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

es-string-algorithm

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

es-string-algorithm

port from C++STL std::basic_string

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

es-string-algorithm

Build Status

Greenkeeper badge

Introduction

C++ STL provide find_first_of / find_first_not_of / find_last_of / find_last_not_of member function.

However, JavaScript String class does not provide such method. So, this package provide these functions.

(When you want find / rfind that C++ STL provide, please use indexOf / lastIndexOf)

Reference

Every function manipulate a string as if that is UTF-32 encoded.

To describe simply, we use two function like below:

  • size(s: string) => number: Returns the length of s.
  • at(s: string, n: number) => string: Returns nth charactor.

findFirstOf

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:

  1. pos <= xpos and xpos < size(target)
  2. k.includes(at(target, xpos)) (When n is undefined (omitted), k is equal to key. Otherwise, k is equal to key.substring(0, n))
Parameters
  • target: search target string
  • key: string identifying characters to search for
  • pos = 0: position at which to begin searching
  • n(opt): length of character string identifying characters to search for
Return value

xpos if the function can determine such a value for xpos. Otherwise, returns -1.

Example
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

findLastof

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:

  1. pos <= xpos and xpos < size(target)
  2. k.includes(at(target, xpos)) (When n is undefined (omitted), k is equal to key. Otherwise, k is equal to key.substring(0, n))
Parameters
  • target: search target string
  • key: string identifying characters to search for
  • pos = -1: position at which the search is to finish. -1 is equal to the length of search target string
  • n(opt): length of character string identifying characters to search for
Return value

xpos if the function can determine such a value for xpos. Otherwise, returns -1.

Example
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

findFirstNotOf

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:

  1. pos <= xpos and xpos < size(target)
  2. !k.includes(at(target, xpos)) (When n is undefined (omitted), k is equal to key. Otherwise, k is equal to key.substring(0, n))
Parameters
  • target: search target string
  • key: string identifying characters to search for
  • pos = 0: position at which to begin searching
  • n(opt): length of character string identifying characters to search for
Return value

xpos if the function can determine such a value for xpos. Otherwise, returns -1.

Example
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

findLastNotof

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:

  1. pos <= xpos and xpos < size(target)
  2. k.includes(at(target, xpos)) (When n is undefined (omitted), k is equal to key. Otherwise, k is equal to key.substring(0, n))
Parameters
  • target: search target string
  • key: string identifying characters to search for
  • pos = -1: position at which the search is to finish. -1 is equal to the length of search target string
  • n(opt): length of character string identifying characters to search for
Return value

xpos if the function can determine such a value for xpos. Otherwise, returns -1.

Example
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

Keywords

FAQs

Package last updated on 31 May 2019

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