Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

parse-ints

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-ints

Parse integers from comma separated string, including ranges.

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

parse-ints

Parse integers from comma separated string, including ranges.

Usage

var test      = require('tape');
var parseInts = require('parse-ints');

var ints;

test('parses a comma separated strings', function (t) {
  t.plan(2);

  ints = parseInts('1,2,3');
  t.same(ints, [ 1, 2, 3 ]);

  // with radix
  ints = parseInts('101,1010,1111', 2);
  t.same(ints, [ 5, 10, 15 ]);
});

test('parses hyphenated strings into a range', function (t) {
  t.plan(2);

  ints = parseInts('1-3');
  t.same(ints, [ 1, 2, 3 ]);

  // with radix
  ints = parseInts('101-111', 2);
  t.same(ints, [ 5, 6, 7 ]);
});

test('parses mixed strings', function (t) {
  t.plan(2);

  ints = parseInts('1-3, 7, 9-10');
  t.same(ints, [ 1, 2, 3, 7, 9, 10 ]);

  // with radix
  ints = parseInts('101-111, 1010', 2);
  t.same(ints, [ 5, 6, 7, 10 ]);
});

Keywords

parseInt

FAQs

Package last updated on 11 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts