string-between

1.0.1 • Public • Published

string-between

Get a string between (when compared) two other strings

Install

$ yarn add string-between

Usage

It can, for example, be usefull to represent an ordered list in a database: You keep indexes as string and order the list with them. This way you can add new element at the end or insert between elements as much as you want without editing other indexes.

const stringBefore = "A";
const stringAfter = "B";
const stringBetween = getStringBetween(stringBefore, stringAfter);
console.log(stringBetween);
//=> "AW"
// "AW" > "A" && "AW" < "B"
 
// This works indefinitely:
 
const stringBefore = "A";
const stringAfter = "AW";
const stringBetween = getStringBetween(stringBefore, stringAfter);
console.log(stringBetween);
//=> "AC"
// "AC" > "A" && "AC" < "AW"
 
// You can also add after:
 
const stringBefore = "A";
const stringAfter = getStringBetween(stringBefore);
console.log(stringAfter);
//=> "B"
// "B" > "A"
 
// or before:
 
const stringAfter = "A";
const stringBefore = getStringBetween(null, stringAfter);
console.log(stringBefore);
//=> "8"
// "8" < "A"
 
// or even to start with
 
const string = getStringBetween();
console.log(string);
//=> "W"

Parameters

string before (Optional)

string after (Optional)

minimum char code (Optional: default to 48)

maximum char code (Optional: default to 126)

Readme

Keywords

none

Package Sidebar

Install

npm i string-between

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

12 kB

Total Files

5

Last publish

Collaborators

  • httpete