This repository has been archived by the owner on Nov 20, 2022. It is now read-only.
-
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
Luuk van Houdt
committed
Jan 4, 2019
0 parents
commit 6ae570b
Showing
10 changed files
with
590 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,81 @@ | ||
# Numbering Patterns | ||
|
||
> Convert numbers to a specified numbering pattern and vice-versa. | ||
[![NPM](https://img.shields.io/npm/v/numbering-patterns.svg)](https://www.npmjs.com/package/numbering-patterns) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
|
||
## Install | ||
|
||
```bash | ||
npm install --save numbering-patterns | ||
``` | ||
|
||
## Usage | ||
|
||
```jsx | ||
import {convert, parse, flags} from 'numbering-patterns' | ||
|
||
convert(3); // output: 'C' | ||
convert(3, flags.PATTERN_ROMAN); // output: 'III' | ||
convert('B'); // output: 2 | ||
convert('V', flags.PATTERN_ROMAN); // output: 5 | ||
|
||
parse('A?B'); // output: 'AB' | ||
parse('IIII'); // output: 'III' | ||
``` | ||
|
||
## Syntax | ||
|
||
```jsx | ||
convert(value, pattern = flags.PATTERN_ALPHA); | ||
``` | ||
|
||
Returns a string or an integer depending on what __value__ is passed to it. | ||
|
||
* **value**: The string convert to an integer or the integer to convert to a numbering pattern string. | ||
* **pattern**: The name of the numbering pattern to use for the conversion *(default = flags.PATTERN_ALPHA)*. | ||
|
||
--- | ||
|
||
```jsx | ||
parse(value, pattern = flags.PATTERN_ALPHA); | ||
``` | ||
|
||
Returns a string in the correct format of the specified numbering pattern. | ||
|
||
* **value**: The string to parse to a correctly formatted numbering pattern string. | ||
* **pattern**: The name of the numbering pattern to parse the string to *(default = flags.PATTERN_ALPHA)*. | ||
|
||
## Supported patterns | ||
|
||
The following numbering patterns are supported. | ||
|
||
### Alphabetic numeral | ||
|
||
__Flag name:__ | ||
``` | ||
flags.PATTERN_ALPHA | ||
``` | ||
|
||
__Example:__ | ||
``` | ||
1, 2, 3, ..., 53, 54, 55, ... | ||
A, B, C, ..., AA, AB, AC, ... | ||
``` | ||
|
||
### Roman numeral | ||
|
||
__Flag name:__ | ||
``` | ||
flags.PATTERN_ROMAN | ||
``` | ||
|
||
__Example:__ | ||
``` | ||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ..., 50, ..., 100, ..., 500, ... | ||
I, II, III, IV, V, VI, VII, VIII, IX, X, ..., L, ..., C, ..., D, ... | ||
``` | ||
|
||
## License | ||
|
||
MIT © [LSVH](https://github.com/LSVH) |
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,15 @@ | ||
const flags = require('./src/flags'); | ||
const patterns = require('./src/patterns'); | ||
|
||
const convert = (value, pattern = flags.PATTERN_ALPHA) => { | ||
if (patterns.hasOwnProperty(pattern)) { | ||
return patterns[pattern](value); | ||
} else { | ||
return value; | ||
} | ||
}; | ||
|
||
const parse = (value, pattern = flags.PATTERN_ALPHA) => | ||
typeof value === 'string' ? convert(convert(value, pattern), pattern) : value; | ||
|
||
module.exports = {flags, patterns, convert, parse}; |
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,28 @@ | ||
{ | ||
"name": "numbering-patterns", | ||
"version": "1.0.0", | ||
"description": "Convert numbers to a specified numbering pattern and vice-versa.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha src/tests/**/*.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/LSVH/numbering-patterns.git" | ||
}, | ||
"keywords": [ | ||
"library", | ||
"numbers", | ||
"patterns" | ||
], | ||
"author": "LSVH", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/LSVH/numbering-patterns/issues" | ||
}, | ||
"homepage": "https://github.com/LSVH/numbering-patterns#readme", | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"mocha": "^5.2.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,4 @@ | ||
module.exports = { | ||
PATTERN_ALPHA: 'alpha', | ||
PATTERN_ROMAN: 'roman', | ||
} |
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,8 @@ | ||
const flags = require('./flags'); | ||
const alpha = require('./patterns/alpha'); | ||
const roman = require('./patterns/roman'); | ||
|
||
module.exports = { | ||
[flags.PATTERN_ALPHA]: alpha, | ||
[flags.PATTERN_ROMAN]: roman, | ||
}; |
Oops, something went wrong.