{"id":24065983,"url":"https://github.com/yumetodo/es-string-algorithm","last_synced_at":"2026-05-01T20:33:00.711Z","repository":{"id":40793313,"uuid":"170115364","full_name":"yumetodo/es-string-algorithm","owner":"yumetodo","description":"port from C++STL std::basic_string","archived":false,"fork":false,"pushed_at":"2025-08-13T04:40:10.000Z","size":1496,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-13T20:09:16.487Z","etag":null,"topics":["cpp","npm-package","string-algorithms"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yumetodo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-11T11:10:34.000Z","updated_at":"2025-08-13T04:40:07.000Z","dependencies_parsed_at":"2024-09-09T09:23:15.377Z","dependency_job_id":"cbf3695b-9160-4fbc-af92-f269ae97562f","html_url":"https://github.com/yumetodo/es-string-algorithm","commit_stats":{"total_commits":114,"total_committers":3,"mean_commits":38.0,"dds":0.3070175438596491,"last_synced_commit":"e6c2d8a0def3c1496deb2173e9d5f501e3c49d6a"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/yumetodo/es-string-algorithm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yumetodo%2Fes-string-algorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yumetodo%2Fes-string-algorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yumetodo%2Fes-string-algorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yumetodo%2Fes-string-algorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yumetodo","download_url":"https://codeload.github.com/yumetodo/es-string-algorithm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yumetodo%2Fes-string-algorithm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32512665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","npm-package","string-algorithms"],"created_at":"2025-01-09T11:16:21.779Z","updated_at":"2026-05-01T20:33:00.693Z","avatar_url":"https://github.com/yumetodo.png","language":"TypeScript","readme":"# es-string-algorithm\n\n[![CircleCI](https://circleci.com/gh/yumetodo/es-string-algorithm.svg?style=svg)](https://circleci.com/gh/yumetodo/es-string-algorithm) [![Known Vulnerabilities](https://snyk.io/test/github/yumetodo/es-string-algorithm/badge.svg?targetFile=package.json)](https://snyk.io/test/github/yumetodo/es-string-algorithm?targetFile=package.json)\n\n[![NPM](https://nodei.co/npm/es-string-algorithm.png)](https://nodei.co/npm/es-string-algorithm/)\n\n## Introduction\n\nC++ STL provide `find_first_of` / `find_first_not_of` / `find_last_of` / `find_last_not_of` / `find` / `rfind` member function.\n\nHowever, JavaScript `String` class does not provide such method. So, this package provide these functions.\n\n## Reference\n\n**Every function manipulate a string as if that is UTF-32 encoded.**\n\nTo describe simply, we use two function like below:\n\n- `at(s: string, n: number) =\u003e string`: Returns `n`th charactor.\n\n### findFirstOf\n\n```ts\nexport declare const findFirstOf: (target: string, key: string, pos?: number, n?: number | undefined) =\u003e number;\n```\n\nDetermines the lowest position `xpos`, if possible, such that both of the following conditions hold:\n\n1. `pos \u003c= xpos` and `xpos \u003c std.size(target)`\n2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`)\n\n#### Parameters\n\n- `target`: search target string\n- `key`: string identifying characters to search for\n- `pos = 0`: position at which to begin searching\n- `n`(opt): length of character string identifying characters to search for\n\n#### Return value\n\n`xpos` if the function can determine such a value for `xpos`. Otherwise, returns `-1`.\n\n#### Example\n\n```js\nconst std = require('es-string-algorithm');\nconst s = 'Hello, world. Welcome to C++ world.';\nconst str = 'world';\nconsole.log(std.findFirstOf(s, str, 14));// =\u003e 16\nconsole.log(std.findFirstOf(s, ',.+', 14));// =\u003e 26\nconsole.log(std.findFirstOf('arikitari na sekai', 'a', 1));// =\u003e 6\nconsole.log(std.findFirstOf('🍣🍺', '🍺'));// =\u003e 1\n```\n\n### findLastof\n\n```ts\nexport declare const findLastof: (target: string, key: string, pos?: number, n?: number | undefined) =\u003e number;\n```\n\nDetermines the highest position `xpos`, if possible, such that both of the following conditions hold:\n\n1. `pos \u003c= xpos` and `xpos \u003c std.size(target)`\n2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`)\n\n#### Parameters\n\n- `target`: search target string\n- `key`: string identifying characters to search for\n- `pos = -1`: position at which the search is to finish. `-1` is equal to the length of search target string\n- `n`(opt): length of character string identifying characters to search for\n\n#### Return value\n\n`xpos` if the function can determine such a value for `xpos`. Otherwise, returns `-1`.\n\n#### Example\n\n```js\nconst std = require('es-string-algorithm');\nconst s = 'Hello, world. Welcome to C++ world.';\nconst str = 'world';\nconsole.log(std.findLastof(s, str, 25));// =\u003e 23\nconsole.log(std.findLastof(s, ',.+', 5));// =\u003e 5\nconsole.log(std.findLastof('arikitari na sekai', 'a', 1));// =\u003e 0\nconsole.log(std.findLastof('🍣🍺', '🍺'));// =\u003e 1\n```\n\n### findFirstNotOf\n\n```ts\nexport declare const findFirstNotOf: (target: string, key: string, pos?: number, n?: number | undefined) =\u003e number;\n```\n\nDetermines the lowest position `xpos`, if possible, such that both of the following conditions hold:\n\n1. `pos \u003c= xpos` and `xpos \u003c std.size(target)`\n2. [`!k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`)\n\n#### Parameters\n\n- `target`: search target string\n- `key`: string identifying characters to search for\n- `pos = 0`: position at which to begin searching\n- `n`(opt): length of character string identifying characters to search for\n\n#### Return value\n\n`xpos` if the function can determine such a value for `xpos`. Otherwise, returns `-1`.\n\n#### Example\n\n```js\nconst std = require('es-string-algorithm');\nconst s = 'Hello, world. Welcome to C++ world.';\nconst str = 'world';\nconsole.log(std.findFirstNotOf(s, str, 2));// =\u003e 5\nconsole.log(std.findFirstNotOf(s, 'worlde,. ', 1));// =\u003e 14\nconsole.log(std.findFirstNotOf('arikitari na sekai datta', 't', 21));// =\u003e 23\nconsole.log(std.findFirstNotOf('🍣🍺', '🍣'));// =\u003e 1\n```\n\n### findLastNotof\n\n```ts\nexport declare const findLastNotof: (target: string, key: string, pos?: number, n?: number | undefined) =\u003e number;\n```\n\nDetermines the highest position `xpos`, if possible, such that both of the following conditions hold:\n\n1. `pos \u003c= xpos` and `xpos \u003c std.size(target)`\n2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`)\n\n#### Parameters\n\n- `target`: search target string\n- `key`: string identifying characters to search for\n- `pos = -1`: position at which the search is to finish. `-1` is equal to the length of search target string\n- `n`(opt): length of character string identifying characters to search for\n\n#### Return value\n\n`xpos` if the function can determine such a value for `xpos`. Otherwise, returns `-1`.\n\n#### Example\n\n```js\nconst std = require('es-string-algorithm');\nconst s = 'Hello, world. Welcome to C++ world.';\nconst str = 'world';\nconsole.log(std.findLastNotof(s, str, 11));// =\u003e 6\nconsole.log(std.findLastNotof(s, 'Welcome to C++ world.', 1));// =\u003e 5\nconsole.log(std.findLastNotof('arikitari na sekai', 'a', 0));// =\u003e -1\nconsole.log(std.findLastNotof('🍣🍺', '🍺'));// =\u003e 0\n```\n\n### find\n\n```ts\nexport declare const find: (target: string, key: string, pos = 0, n?: number) =\u003e number;\n```\n\nDetermines the lowest position `xpos`, if possible, such that both of the following conditions hold:\n\n1. `xpos \u003c= pos` and `xpos + n \u003c= std.size(target)`\n2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`)\n\n#### Parameters\n\n- `target`: search target string\n- `key`: string identifying characters to search for\n- `pos = 0`: position at which to begin searching\n- `n`(opt): length of character string identifying characters to search for\n\n#### Return value\n\n`xpos` if the function can determine such a value for `xpos`. Otherwise, returns `-1`.\n\n#### Example\n\n```js\nconst std = require('es-string-algorithm');\nconst s = 'Hello, world. Welcome to C++ world.';\nconst str = 'world';\nconsole.log(std.find(s, findWord));// =\u003e 7\nconsole.log(std.find(s, findWord, 12));// =\u003e 29\nconsole.log(std.find(s, findWord, 33));// =\u003e -1\nconsole.log(std.find('🍣🍺📧💾', '🍺📧'));// =\u003e 1\n```\n\n### rfind\n\n```ts\nexport declare const rfind: (target: string, key: string, pos = -1, n?: number) =\u003e number;\n```\n\nDetermines the highest position `xpos`, if possible, such that both of the following conditions hold:\n\n1. `xpos \u003c= pos` and `xpos + n \u003c= std.size(target)`\n2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`)\n\n#### Parameters\n\n- `target`: search target string\n- `key`: string identifying characters to search for\n- `pos = -1`: position at which to begin searching\n- `n`(opt): length of character string identifying characters to search for\n\n#### Return value\n\n`xpos` if the function can determine such a value for `xpos`. Otherwise, returns `-1`.\n\n#### Example\n\n```js\nconst std = require('es-string-algorithm');\nconst s = 'Hello, world. Welcome to C++ world.';\nconst str = 'world';\nconsole.log(std.rfind(s, findWord, 29));// =\u003e 29\nconsole.log(std.rfind(s, findWord, 28));// =\u003e 7\nconsole.log(std.rfind(s, 'W', 29));// =\u003e 14\nconsole.log(std.rfind('🍣🍺📧💾', '🍺📧'));// =\u003e 1\n```\n\n### substr\n\n```ts\nexport declare const substr: (s: string, pos?: number, n?: number | undefined) =\u003e string;\n```\n\nCreate part of the `s`\n\n#### Parameters\n\n- `s`: string\n- `pos = 0`: copy start position\n- `n`(opt): copy length\n\n#### Return value\n\npart of the `s` in range of `[pos...rlast]` (`rlast` is the smaller of `pos + n` and `std.size(s)`)\n\n#### Exception\n\nThrows `RangeError` when `pos` or `n` is negative or `pos` \u003e `std.size(s)`\n\n### size\n\n```ts\nexport declare const size: (s: string) =\u003e number;\n```\n\nA count of the number of codepoint currently in the string.\n\n#### Parameters\n\n- `s`: string\n\n#### Complexity\n\n`O(n)`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyumetodo%2Fes-string-algorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyumetodo%2Fes-string-algorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyumetodo%2Fes-string-algorithm/lists"}