srange
install
npm install @hehehai/srange
or you can use yarn
pnpm
some package manager
usage
import
import { rangeArr, rangeChar, rangeFloat, rangeInt } from '@hehehai/srange'
- rangeInt: int range generator
- rangeFloat: float range generator
- rangeChar: char range generator
- rangeArr: slice arr by range
rules
start
:(options) start of range [default: 0, a]..
:(required) range separator=
:(options) range include end [default: false]end
:(required) end of range
int
start
default 0
import { rangeInt } from '@hehehai/srange'
rangeInt('0..10')
rangeInt('0..=10')
rangeInt('20..30')
rangeInt('20..=30')
rangeInt('20..20')
rangeInt('20..21')
rangeInt('20..=21')
rangeInt('-3..10')
rangeInt('-3..=10')
rangeInt('..10')
rangeInt('..=10')
rangeInt('10..0')
rangeInt('10..=0')
rangeInt('-3..0')
rangeInt('..-3')
rangeInt('..=-3')
char
start
default a
import { rangeChar } from '@hehehai/srange'
rangeChar('a..f')
rangeChar('a..=f')
rangeChar('A..F')
rangeChar('A..=F')
rangeChar('..f')
rangeChar('..=f')
rangeChar('f..k')
rangeChar('f..=k')
rangeChar('k..=f')
float
start
default 0
import { rangeFloat } from '@hehehai/srange'
rangeFloat('0.0..1.0')
rangeFloat('0.0..=1.0')
rangeFloat('..1.0')
rangeFloat('1.7..1.80')
rangeFloat('1.7..1.2')
rangeFloat('-0.7..1')
array
start
default 0
import { rangeArr } from '@hehehai/srange'
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant']
rangeArr(animals, '0..2')
rangeArr(animals, '0..=2')
rangeArr(animals, '..2')
rangeArr(animals, '1..8')
rangeArr(animals, '1..-2')
rangeArr(animals, '-2..-1')
rangeArr(animals, '-1..-3')
rangeArr(animals, '6..8')
feat
thx
License
MIT License © 2022 hehehai