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

Convert numbers to a specified numbering pattern and vice-versa.

Notifications You must be signed in to change notification settings

LSVH/numbering-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Numbering Patterns

Convert numbers to a specified numbering pattern and vice-versa.

NPM JavaScript Style Guide

Install

npm install --save numbering-patterns

Usage

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

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).

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

About

Convert numbers to a specified numbering pattern and vice-versa.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published