Skip to content

pierregoutheraud/string-between

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published