JSPM

parse-int-array

1.0.2
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 15
    • Score
      100M100P100Q33012F
    • License MIT

    Parse a string to an integer array

    Package Exports

    • parse-int-array
    • parse-int-array/parse-int-array.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parse-int-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    parseIntArray

    Parse a string and returns an integer array.

    Prototype

    parseIntArray(str, base = 0]);

    Parameter

    • str:string
    • base:number/function=0:number

    Returns

    an array of integer.

    Example

    var parseIntArray = require("parse-int-array");
    
    // The comma separates the numbers.
    parseIntArray("0,1,2"); // returns [0,1,2]
    parseIntArray("2,0,1"); // returns [2,0,1]
    
    // The delimitor '..' represents a range 
    parseIntArray("0..2");  // returns [0,1,2]
    parseIntArray("10..10000");  // ...
    
    // Combination
    parseIntArray(
        "1,5..3,6");        // returns [1,5,4,3,6]
    
    // Usage of user parser
    var animals = ["bird","cat","dog"];
    function animal2index(animal, base) {
        return animals.indexOf(animal);
    }
    parseIntArray(
        "cat, bird, dog",
        animal2index);      // returns [1,0,2]

    LICENSE

    This software is released under the MIT License, see LICENSE