@guanghechen/parse-lineno
TypeScript icon, indicating that this package has built-in type declarations

2.3.10 • Public • Published

@guanghechen/parse-lineno


Parse something like '1,3-10' to numbers or intervals.

Install

  • npm

    npm install --save-dev @guanghechen/parse-lineno
  • yarn

    yarn add --dev @guanghechen/parse-lineno

Usage

  • Parse lineno string into numbers.

    import { collectNumbers } from '@guanghechen/parse-lineno'
    
    collectNumbers('')              // => []
    collectNumbers('1')             // => [1]
    collectNumbers('1-3')           // => [1, 2, 3]
    collectNumbers('3,1-2,2,2')     // => [1, 2, 3]
    collectNumbers('3,7-5,2,2')     // => [2, 3, 5, 6, 7]
    collectNumbers('2,1-3')         // => [1, 2, 3]
    collectNumbers('4,1-3')         // => [1, 2, 3, 4]
    collectNumbers('2-4,1-3,5-9')   // => [1, 2, 3, 4, 5, 6, 7, 8, 9]
    collectNumbers('2-4,1-3,6-9')   // => [1, 2, 3, 4, 6, 7, 8, 9]
  • Parse lineno string into intervals.

    import { collectIntervals } from '@guanghechen/parse-lineno'
    
    collectIntervals('')              // => []
    collectIntervals('1')             // => [[1, 1]]
    collectIntervals('1-3')           // => [[1, 3]]
    collectIntervals('3,1-2,2,2')     // => [[1, 3]]
    collectIntervals('3,7-5,2,2')     // => [[2, 3], [5, 7]]
    collectIntervals('2,1-3')         // => [[1, 3]]
    collectIntervals('4,1-3')         // => [[1, 4]]
    collectIntervals('2-4,1-3,5-9')   // => [[1, 9]]
    collectIntervals('2-4,1-3,6-9')   // => [[1, 4], [6, 9]]
  • Custom Separator (default is /[,\s]+/)

    collectNumbers('2#4-5#5-8', /#/)    // => [2, 4, 5, 6, 7, 8]
    
    collectIntervals('2#4-5#5-8', /#/)  // => [[2, 2], [4, 8]]

Package Sidebar

Install

npm i @guanghechen/parse-lineno

Weekly Downloads

7

Version

2.3.10

License

MIT

Unpacked Size

17.9 kB

Total Files

8

Last publish

Collaborators

  • lemonclown