Skip to content
This repository has been archived by the owner on Nov 20, 2022. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Luuk van Houdt committed Jan 4, 2019
0 parents commit 6ae570b
Show file tree
Hide file tree
Showing 10 changed files with 590 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
81 changes: 81 additions & 0 deletions README.md
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)
15 changes: 15 additions & 0 deletions index.js
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};
249 changes: 249 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions package.json
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"
}
}
4 changes: 4 additions & 0 deletions src/flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
PATTERN_ALPHA: 'alpha',
PATTERN_ROMAN: 'roman',
}
8 changes: 8 additions & 0 deletions src/patterns.js
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,
};
Loading

0 comments on commit 6ae570b

Please sign in to comment.