1.0.1 • Published 4 years ago

calimari v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Calimari

Version 1.0.1 Do you want users to be able to input ANY set of numbers easily, no matter how complex? No problem! Calimari has you covered (and it's tasty too).

Installing

npm install calimari@1.0.1

Usage

const calimari = require("calimari");
console.log(calimari("5-7, 9 || -5-20"));

The above example uses all of calimari's input features simeltaneously, and will output

[
    [5, 6, 7, 9],
    [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
]

Confusing? See this simpler example, or check the Features section.

const calimari = require("calimari");
console.log(calimari("1, 4, 6-8"));
// [[1, 4, 6, 7, 8]]

Features

Joining Comma

When Calimari is fed an input with a comma, such as 1, 3, 5it will join the results of each term (term in this stance meaning 1 for example, but it could mean 5-8, etc.)

calimari("1, 3, 5");
// [[1, 3, 5]]

Safe Parsing

If a string in the set cannot be turned into a number, it's simply ignored.

calimari("todd");
// [[]]

calimari("1, 2, oatmeal");
// [[1, 2]]

Ranges

You can specify a range of numbers, and even comma them together. You can also use them in reverse order (larger number first).

calimari("10-12");
// [[10, 11, 12]]

calimari("15-13");
// [[13, 14, 15]]

calimari("1-2, 4-5");
// [[1, 2, 4, 5]]

Numerical Sorting

Calimari will always sort numbers from least to greatest.

Negative Numbers

Just a reminder that calimari still supports negative numbers, even if the range indicator is also a minus symbol.

Logical OR

Dictated by two upward dashes (||), you can give your users a choice to use either one set of numbers or another. The exact use case depends on your implementation, but it could be for the user to say "if you can't use these numbers, use these instead". Every number option list is a new array within the returned array, which is why results without an OR are in a double array.

calimari("2-8 || 1, 5, 7-9");
// [[2, 3, 4, 5, 6, 7, 8], [1, 5, 7, 8, 9]]