
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
es-string-algorithm
Advanced tools
C++ STL provide find_first_of
/ find_first_not_of
/ find_last_of
/ find_last_not_of
/ find
/ rfind
member function.
However, JavaScript String
class does not provide such method. So, this package provide these functions.
Every function manipulate a string as if that is UTF-32 encoded.
To describe simply, we use two function like below:
at(s: string, n: number) => string
: Returns n
th charactor.export declare const findFirstOf: (target: string, key: string, pos?: number, n?: number | undefined) => number;
Determines the lowest position xpos
, if possible, such that both of the following conditions hold:
pos <= xpos
and xpos < std.size(target)
k.includes(at(target, xpos))
(When n
is undefined
(omitted), k
is equal to key
. Otherwise, k
is equal to std.substr(key, 0, n)
)target
: search target stringkey
: string identifying characters to search forpos = 0
: position at which to begin searchingn
(opt): length of character string identifying characters to search forxpos
if the function can determine such a value for xpos
. Otherwise, returns -1
.
const std = require('es-string-algorithm');
const s = 'Hello, world. Welcome to C++ world.';
const str = 'world';
console.log(std.findFirstOf(s, str, 14));// => 16
console.log(std.findFirstOf(s, ',.+', 14));// => 26
console.log(std.findFirstOf('arikitari na sekai', 'a', 1));// => 6
console.log(std.findFirstOf('π£πΊ', 'πΊ'));// => 1
export declare const findLastof: (target: string, key: string, pos?: number, n?: number | undefined) => number;
Determines the highest position xpos
, if possible, such that both of the following conditions hold:
pos <= xpos
and xpos < std.size(target)
k.includes(at(target, xpos))
(When n
is undefined
(omitted), k
is equal to key
. Otherwise, k
is equal to std.substr(key, 0, n)
)target
: search target stringkey
: string identifying characters to search forpos = -1
: position at which the search is to finish. -1
is equal to the length of search target stringn
(opt): length of character string identifying characters to search forxpos
if the function can determine such a value for xpos
. Otherwise, returns -1
.
const std = require('es-string-algorithm');
const s = 'Hello, world. Welcome to C++ world.';
const str = 'world';
console.log(std.findLastof(s, str, 25));// => 23
console.log(std.findLastof(s, ',.+', 5));// => 5
console.log(std.findLastof('arikitari na sekai', 'a', 1));// => 0
console.log(std.findLastof('π£πΊ', 'πΊ'));// => 1
export declare const findFirstNotOf: (target: string, key: string, pos?: number, n?: number | undefined) => number;
Determines the lowest position xpos
, if possible, such that both of the following conditions hold:
pos <= xpos
and xpos < std.size(target)
!k.includes(at(target, xpos))
(When n
is undefined
(omitted), k
is equal to key
. Otherwise, k
is equal to std.substr(key, 0, n)
)target
: search target stringkey
: string identifying characters to search forpos = 0
: position at which to begin searchingn
(opt): length of character string identifying characters to search forxpos
if the function can determine such a value for xpos
. Otherwise, returns -1
.
const std = require('es-string-algorithm');
const s = 'Hello, world. Welcome to C++ world.';
const str = 'world';
console.log(std.findFirstNotOf(s, str, 2));// => 5
console.log(std.findFirstNotOf(s, 'worlde,. ', 1));// => 14
console.log(std.findFirstNotOf('arikitari na sekai datta', 't', 21));// => 23
console.log(std.findFirstNotOf('π£πΊ', 'π£'));// => 1
export declare const findLastNotof: (target: string, key: string, pos?: number, n?: number | undefined) => number;
Determines the highest position xpos
, if possible, such that both of the following conditions hold:
pos <= xpos
and xpos < std.size(target)
k.includes(at(target, xpos))
(When n
is undefined
(omitted), k
is equal to key
. Otherwise, k
is equal to std.substr(key, 0, n)
)target
: search target stringkey
: string identifying characters to search forpos = -1
: position at which the search is to finish. -1
is equal to the length of search target stringn
(opt): length of character string identifying characters to search forxpos
if the function can determine such a value for xpos
. Otherwise, returns -1
.
const std = require('es-string-algorithm');
const s = 'Hello, world. Welcome to C++ world.';
const str = 'world';
console.log(std.findLastNotof(s, str, 11));// => 6
console.log(std.findLastNotof(s, 'Welcome to C++ world.', 1));// => 5
console.log(std.findLastNotof('arikitari na sekai', 'a', 0));// => -1
console.log(std.findLastNotof('π£πΊ', 'πΊ'));// => 0
export declare const find: (target: string, key: string, pos = 0, n?: number) => number;
Determines the lowest position xpos
, if possible, such that both of the following conditions hold:
xpos <= pos
and xpos + n <= std.size(target)
k.includes(at(target, xpos))
(When n
is undefined
(omitted), k
is equal to key
. Otherwise, k
is equal to std.substr(key, 0, n)
)target
: search target stringkey
: string identifying characters to search forpos = 0
: position at which to begin searchingn
(opt): length of character string identifying characters to search forxpos
if the function can determine such a value for xpos
. Otherwise, returns -1
.
const std = require('es-string-algorithm');
const s = 'Hello, world. Welcome to C++ world.';
const str = 'world';
console.log(std.find(s, findWord));// => 7
console.log(std.find(s, findWord, 12));// => 29
console.log(std.find(s, findWord, 33));// => -1
console.log(std.find('π£πΊπ§πΎ', 'πΊπ§'));// => 1
export declare const rfind: (target: string, key: string, pos = -1, n?: number) => number;
Determines the highest position xpos
, if possible, such that both of the following conditions hold:
xpos <= pos
and xpos + n <= std.size(target)
k.includes(at(target, xpos))
(When n
is undefined
(omitted), k
is equal to key
. Otherwise, k
is equal to std.substr(key, 0, n)
)target
: search target stringkey
: string identifying characters to search forpos = -1
: position at which to begin searchingn
(opt): length of character string identifying characters to search forxpos
if the function can determine such a value for xpos
. Otherwise, returns -1
.
const std = require('es-string-algorithm');
const s = 'Hello, world. Welcome to C++ world.';
const str = 'world';
console.log(std.rfind(s, findWord, 29));// => 29
console.log(std.rfind(s, findWord, 28));// => 7
console.log(std.rfind(s, 'W', 29));// => 14
console.log(std.rfind('π£πΊπ§πΎ', 'πΊπ§'));// => 1
export declare const substr: (s: string, pos?: number, n?: number | undefined) => string;
Create part of the s
s
: stringpos = 0
: copy start positionn
(opt): copy lengthpart of the s
in range of [pos...rlast]
(rlast
is the smaller of pos + n
and std.size(s)
)
Throws RangeError
when pos
or n
is negative or pos
> std.size(s)
export declare const size: (s: string) => number;
A count of the number of codepoint currently in the string.
s
: stringO(n)
FAQs
port from C++STL std::basic_string
The npm package es-string-algorithm receives a total of 10 weekly downloads. As such, es-string-algorithm popularity was classified as not popular.
We found that es-string-algorithm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Γ faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.