Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hehehai/srange

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hehehai/srange

like rust range but with string

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

srange

logo

NPM version

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

rule
  • 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') // [0, ..., 9]
rangeInt('0..=10') // [0, ..., 10]
rangeInt('20..30') // [20, ..., 29]
rangeInt('20..=30') // [20, ..., 30]
rangeInt('20..20') // [20]
rangeInt('20..21') // [20]
rangeInt('20..=21') // [20, 21]
rangeInt('-3..10') // [-3, ..., 9]
rangeInt('-3..=10') // [-3, ..., 10]
rangeInt('..10') // [0, ..., 9]
rangeInt('..=10') // [0, ..., 10]
rangeInt('10..0') // [10, ..., 1]
rangeInt('10..=0') // [10, ..., 0]
rangeInt('-3..0') // [-3, -2, -1]
rangeInt('..-3') // [0, -1, -2]
rangeInt('..=-3') // [0, -1, -2, -3]

char

start default a

import { rangeChar } from '@hehehai/srange'

rangeChar('a..f') // ['a', ..., 'e']
rangeChar('a..=f') // ['a', ..., 'f']
rangeChar('A..F') // ['A', ..., 'E']
rangeChar('A..=F') // ['A', ..., 'F']
rangeChar('..f') // ['a', ..., 'e']
rangeChar('..=f') // ['a', ..., 'f']
rangeChar('f..k') // ['f', ..., 'j']
rangeChar('f..=k') // ['f', ..., 'k']
rangeChar('k..=f') // ['k', ..., 'f']

float

start default 0

import { rangeFloat } from '@hehehai/srange'

rangeFloat('0.0..1.0') // [0, ..., 0.9]
rangeFloat('0.0..=1.0') // [0, ..., 0.9, 1]
rangeFloat('..1.0') // [0, ..., 0.9]
rangeFloat('1.7..1.80') // [1.7, ..., 1.79]
rangeFloat('1.7..1.2') // [1.7, ..., 1.3]
rangeFloat('-0.7..1') // [-0.7, ..., 0.9]

array

start default 0

import { rangeArr } from '@hehehai/srange'

const animals = ['ant', 'bison', 'camel', 'duck', 'elephant']

rangeArr(animals, '0..2') // ['ant', 'bison']
rangeArr(animals, '0..=2') // ['ant', 'bison', 'camel']
rangeArr(animals, '..2') // ['ant', 'bison']
rangeArr(animals, '1..8') // ['bison', ..., 'elephant']
rangeArr(animals, '1..-2') // ['bison', 'camel']
rangeArr(animals, '-2..-1') // ['duck']
rangeArr(animals, '-1..-3') // []
rangeArr(animals, '6..8') // []

feat

  • typescript format string type

  • generator array sequence

  • reverse order

  • float number range

  • a-z and A-Z array sequence

  • custom preset items then generator range array sequence

  • tests

thx

License

MIT License © 2022 hehehai

FAQs

Package last updated on 24 Jun 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc