-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6be82e9
commit 07390ac
Showing
6 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ typings/ | |
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
# dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,33 @@ | ||
# pep440conv | ||
Simple stdin/stdout-based utilities for converting to and from PEP-440 semver strings. | ||
|
||
## Requirements | ||
|
||
- Node.js 14 or newer | ||
|
||
## Installation | ||
|
||
The pep440conv utility can be installed using `npm`: | ||
|
||
```sh | ||
npm -g pep440conv | ||
``` | ||
|
||
## Usage | ||
|
||
Usage is very straightforward. Once the packge is installed `frompep440` and `topep440` become available from the | ||
command line: | ||
|
||
```bash | ||
$ # Converting from a regular semver string to to PEP-440. | ||
$ echo '1.0.0-rc.1' | topep440 | ||
1.0.0-rc1 | ||
|
||
$ # Converting from PEP-440 to a regular semver string. | ||
$ echo '1.0.0-rc1' | frompep440 | ||
1.0.0-rc.1 | ||
``` | ||
|
||
## License | ||
|
||
[MIT](LICENSE) © [lambdacasserole](https://github.com/lambdacasserole). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env node | ||
|
||
import getStdin from 'get-stdin'; | ||
|
||
|
||
/** | ||
* Transforms a PEP-440 compatible version string token into a regular semver string token. | ||
* | ||
* @param {string} token the token to transform | ||
* @returns {string} the transformed token | ||
*/ | ||
function fromPep440Token(token) { | ||
const chars = [] | ||
let dotted = false | ||
token.split('').forEach((c)=> { | ||
if (/[0-9]/.test(c) && !dotted) { | ||
chars.push('.'); | ||
dotted = true; | ||
} | ||
chars.push(c); | ||
}) | ||
return chars.join(''); | ||
} | ||
|
||
/** | ||
* Transforms a PEP-440 compatible version string into a regular semver string. | ||
* | ||
* @param {string} pepVersionStr the string to transform | ||
* @returns {string} the transformed string | ||
*/ | ||
function fromPep440(pepVersionStr) { | ||
const tokens = pepVersionStr.split('-'); | ||
return [tokens[0], ...tokens.slice(1).map(fromPep440Token)].join('-'); | ||
} | ||
|
||
|
||
(async () => { | ||
const stdin = await getStdin(); | ||
console.log(fromPep440(stdin)); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "pep440conv", | ||
"version": "1.0.0", | ||
"description": "Simple stdin/stdout-based utilities for converting to and from PEP-440 semver strings.", | ||
"type": "module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/lambdacasserole/incv.git" | ||
}, | ||
"keywords": [ | ||
"version", | ||
"pep", | ||
"440", | ||
"python", | ||
"semver" | ||
], | ||
"author": "Saul Johnson <saul.a.johnson@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/lambdacasserole/pep440conv/issues" | ||
}, | ||
"homepage": "https://github.com/lambdacasserole/pep440conv#readme", | ||
"bin": { | ||
"topep440": "./toPep440.js", | ||
"frompep440": "./fromPep440.js" | ||
}, | ||
"dependencies": { | ||
"get-stdin": "^9.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
|
||
import getStdin from 'get-stdin'; | ||
|
||
|
||
/** | ||
* Transforms a regular semver string to a PEP-440 compatible version string. | ||
* | ||
* @param {string} semverStr the string to transform | ||
* @returns {string} the transformed string | ||
*/ | ||
function toPep440(semverStr) { | ||
const tokens = semverStr.split('-'); | ||
return [tokens[0], ...tokens.slice(1).map((t) => t.replace('.', ''))].join('-'); | ||
} | ||
|
||
|
||
(async () => { | ||
const stdin = await getStdin(); | ||
console.log(toPep440(stdin)); | ||
})(); |