chapter-numbering
v1.1.3
Published
accepts a number and a format and returns a string in the specified format.
Downloads
269
Readme
chapter-numbering
A package for chapter and section numbering. Handles roman numerals (Chapter IV) or consecutive lettering (Exhibit A).
Install
Available as npm package
$ npm install chapter-numbering
const numbering = require("chapter-numbering")
Usage
Convert Number to String
The main function accepts a number or array of numbers, and a string describing the output format.
This string can include ruby style interpolation keys #{} with I, i, A, a, #, 1.
You can also pass in a string without keys, and it will simply replace the above characters with the converted number (but watch out with that since it will catch the 'a' in chapter and the 'i' in section.)
numbering([4, 5, 6], "Book #{I} - Section #{A}: page #{#}")
// 'Book IV - Section E: page 6'
numbering([4, 5, 6], "i - a - #")
// 'iv - e - 6'
You can also use the roman or alpha methods by directly passing them a number:
numbering.roman(28)
// 'XXVIII'
numbering.alpha(28)
// 'AB'
Convert String to number
Use the parse object's roman or alpha methods to convert Roman or Alpha to numerals:
> numbering.parse.roman('III')
// 3
> numbering.parse.alpha('A')
// 1```