{"id":21493513,"url":"https://github.com/alienkevin/string-unified","last_synced_at":"2026-05-11T16:37:18.612Z","repository":{"id":35077047,"uuid":"203896055","full_name":"AlienKevin/string-unified","owner":"AlienKevin","description":"All you need to handle Unicode strings properly in JS","archived":false,"fork":false,"pushed_at":"2023-01-04T07:58:44.000Z","size":909,"stargazers_count":1,"open_issues_count":14,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T04:17:46.153Z","etag":null,"topics":["nodejs","string-manipulation","ts","unicode"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlienKevin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-23T00:47:12.000Z","updated_at":"2019-10-09T01:19:08.000Z","dependencies_parsed_at":"2023-01-15T13:20:58.345Z","dependency_job_id":null,"html_url":"https://github.com/AlienKevin/string-unified","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienKevin%2Fstring-unified","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienKevin%2Fstring-unified/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienKevin%2Fstring-unified/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienKevin%2Fstring-unified/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlienKevin","download_url":"https://codeload.github.com/AlienKevin/string-unified/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244029504,"owners_count":20386420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["nodejs","string-manipulation","ts","unicode"],"created_at":"2024-11-23T15:43:10.785Z","updated_at":"2026-05-11T16:37:18.569Z","avatar_url":"https://github.com/AlienKevin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# string-unified\nAll you need to **handle Unicode strings properly** in JS.\n\nThis library builds on the power of [grapheme-splitter](https://github.com/orling/grapheme-splitter) to provide all essential functions for accurate Unicode string manipulations.\n\n# Installation\n## Node.js\n```\nnpm i string-unified\n```\n## Browsers\njsDelivr\n```\nhttps://cdn.jsdelivr.net/npm/string-unified@latest\n```\nUnpkg\n```\nhttps://unpkg.com/string-unified@latest/dist/index.js\n```\nAnd import string-unified like this\n```js\n// ES2015+\nimport * as unified from \"string-unified\";\nimport { length, charAt, substring } from \"string-unified\";\n\n// CommonJS\nconst unified = require(\"string-unified\")\nconst { length, charAt, substring } = require(\"string-unified\");\n```\n# Usage\n* [length()](#length)\n* [charAt()](#charAt)\n* [substring()](#substring)\n* [indexOf()](#indexOf)\n* [lastIndexOf()](#lastIndexOf)\n* [includes()](#includes)\n* [split()](#split)\n* [startsWith()](#startsWith)\n* [endsWith()](#endsWith)\n* [match()](#match)\n\n\u003e All functions except match() are transpiled to ES5.\n\u003e [See below](#match) for why match() requires ES2015+.\n\n## length\nGet the length of a string.\n```js\nfunction length(str)\n```\n|Param|Type|Default|Description|\n|-----|----|-------|-----------|\n|str  |string|*none*|string to find length for|\n### Examples\n```js\nlength('abc') // 3\n\nlength('谢谢') // 2\n\nlength('अनुच्छेद') // 5\n\nlength('뎌쉐') // 2\n\nlength('Ĺo͂řȩm̅') // 5\n\nlength('Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘') // 5\n\nlength('🎅🔥🌘☀🛴👚') // 6\n\nlength('🏳️‍🌈') // 1\n```\n## charAt\nGet the character at an index.\n```\nfunction charAt(str, index)\n```\n|Param|Type|Default|Description|\n|-----|----|-------|-----------|\n|str  |string|*none*|string to get char from|\n|index|number|*none*|index to get char|\n### Examples\n```js\ncharAt('helloあ', 5) // 'あ'\n\ncharAt('谢谢你😊', 10) // undefined\n\n// negative indices also work!\n// same as charAt('谢谢你😊', 3)\ncharAt('谢谢你😊', -1) // '😊'\n```\n## substring\nGet a substring of a string.\n```\nfunction substring(str, start?, end?)\n```\n|Param|Type|Default|Description|\n|-----|----|-------|-----------|\n|str  |string|*none*|string to retrieve substring from|\n|start|number|0|start index of substring|\n|end|number|end of string|end index of substring|\n### Examples\n```js\nsubstring('🥪🥗🍤🍜🍚', 3) // '🍜🍚'\n\nsubstring('🥪🥗🍤🍜🍚', 2, 5) // '🍤🍜🍚'\n\n// negative indices also work!\n// same as substring('🥪🥗🍤🍜🍚', 2, 3)\nsubstring('🥪🥗🍤🍜🍚', -3, -2) // '🍤'\n```\n## indexOf\nGet the index of the first occurence of a search string.\n```js\nfunction indexOf(str, searchStr, start?, end?)\n```\n|Param|Type|Default|Description|\n|-----|----|-------|-----------|\n|str  |string|*none*|string to search in|\n|searchStr|string|*none*|string to search for|\n|start|number|0|start index of the search|\n|end|number|end of string|end index of the search|\n### Examples\n```js\n// get index of the *first* occurence\nindexOf('🚗🚌🚑🚜🚒🚜', '🚜') // 3\n\n// return undefined if not found\nindexOf('🚗🚌🚑🚜🚒🚜', '🛴🛴🛴') // undefined\n```\n## lastIndexOf\nGet the index of the last occurence of a search string.\n```js\nfunction lastIndexOf(str, searchStr, start?, end?)\n```\n|Param|Type|Default|Description|\n|-----|----|-------|-----------|\n|str  |string|*none*|string to search in|\n|searchStr|string|*none*|string to search for|\n|start|number|0|start index of the search|\n|end|number|end of string|end index of the search|\n### Examples\n```js\n// get index of the *last* occurence\nlastIndexOf('🚗🚌🚑🚜🚒🚜', '🚜') // 5\n\n// return undefined if not found\nlastIndexOf('🚗🚌🚑🚜🚒🚜', '🛴🛴🛴') // undefined\n```\n## includes\nTest if a search string appears in a string.\n```js\nfunction includes(str, searchStr, start?, end?)\n```\n|Param|Type|Default|Description|\n|-----|----|-------|-----------|\n|str  |string|*none*|string to search in|\n|searchStr|string|*none*|string to search for|\n|start|number|0|start index of the search|\n|end|number|end of string|end index of the search|\n### Examples\n```js\nincludes('🎁🎄🎃🎉🧧', '🎃') // true\n\n// same as includes('🎃🎉🧧', '🎁')\nincludes('🎁🎄🎃🎉🧧', '🎁', 2) // false\n\n// same as includes('🎉', '🎉')\nincludes('🎁🎄🎃🎉🧧', '🎉', 3, 4) // true\n\n// negative indices also work!\n// same as includes('🎃🎉🧧', '🎁')\nincludes('🎁🎄🎃🎉🧧', '🎁', -3) // false\n```\n## split\nSplit a string by a separator (can be a string or regex).\n```js\nfunction split(str, separator?, limit?)\n```\n|Param|Type|Default|Description|\n|-----|----|-------|-----------|\n|str  |string|*none*|string to split|\n|separator|string or RegExp|*none*|separator to split string|\n|limit|number|+Infinity|limit of the number of splits returned\n### Examples\n```js\nsplit('👩🔹👨🔹🧑🔹👧🔹👦🔹🧒', '🔹') //  ['👩','👨','🧑','👧','👦','🧒'])\nsplit('👩🔹👨🔹🧑🔹👧🔹👦🔹🧒', '🔹', 3) // ['👩','👨','🧑']\n\n// limit can be larger than array size\nsplit('👩🔹👨🔹🧑', '🔹', 6) // ['👩','👨','🧑']\n\n// no separator returns a copy of the string inside an array\nsplit('👩🔹👨🔹🧑🔹👧🔹👦🔹🧒') // ['👩🔹👨🔹🧑🔹👧🔹👦🔹🧒']\n\n// if separator is an empty string '', split whole string into a character array\nsplit('👩🔹👨🔹🧑🔹👧🔹👦🔹🧒', '') //  ['👩','🔹','👨','🔹','🧑','🔹','👧','🔹','👦','🔹','🧒'])\n\n// If separator is a regular expression containing capturing parentheses (), matched results are included\nsplit('Hello👋 1 word. Sentence #️⃣ 2.', /(\\d)/)) // [\"Hello👋 \", \"1\", \" word. Sentence #️⃣ \", \"2\", \".\"]\n```\n## startsWith\nTest is a string starts with a search string.\n```js\nfunction startsWith(str, searchStr, start?, end?)\n```\n|Param|Type|Default|Description|\n|-----|----|-------|-----------|\n|str  |string|*none*|string to search in|\n|searchStr|string|*none*|string to search for|\n|start|number|0|start index of the search|\n|end|number|end of string|end index of the search|\n### Examples\n```js\nstartsWith('🎢🎪🎭🎡🎠', '🎢🎪') // true\n\n// same as startsWith('🎪🎭🎡🎠', '🎢')\nstartsWith('🎢🎪🎭🎡🎠', '🎢', 1) // false\n\n// same as startsWith('🎪🎭', '🎪')\nstartsWith('🎢🎪🎭🎡🎠', '🎪', 1, 3) // true\n\n// negative indices also work!\n// same as startsWith('🎡🎠', '🎡')\nstartsWith('🎢🎪🎭🎡🎠', '🎡', -2) // true\n```\n## endsWith\nTest is a string ends with a search string.\n```js\nfunction endsWith(str, searchStr, start?, end?)\n```\n|Param|Type|Default|Description|\n|-----|----|-------|-----------|\n|str  |string|*none*|string to search in|\n|searchStr|string|*none*|string to search for|\n|start|number|0|start index of the search\n|end|number|end of string|end index of the search|\n### Examples\n```js\nendsWith('🎢🎪🎭🎡🎠', '🎠') // true\n\n// same as endsWith('🎭🎡🎠', '🎠')\nendsWith('🎢🎪🎭🎡🎠', '🎠', 2) // true\n\n// negative indices also work!\n// same as endsWith('🎪🎭', '🎭')\nendsWith('🎢🎪🎭🎡🎠', '🎭', -4, 3) // true\n```\n## match\n\u003e Note that match() requires ES2015+ because of limited support of unicode regexp\n\u003e in lower versions and limitations of current source code transpilers like [regexpu](https://github.com/mathiasbynens/regexpu#known-limitations).\n\nTest if a string matches a regular expression or another string.\n```js\nfunction match(str, regexp)\n```\n|Param|Type|Default|Description|\n|-----|----|-------|-----------|\n|str  |string|*none*|string to search in|\n|regexp|RegExp or string|*none*|Regular expression or string to search for|\n### Examples\n```js\n// Test if a string matches a RegExp\n// Without global flag\nmatch('🐵🐶🐺🐱', /🐺/) // ['🐺', index: 2, input: '🐵🐶🐺🐱', groups: undefined]\n\nmatch('🏳️‍🌈', /🌈/) // null\n\n// Must add 'u' flag otherwise throw \"Range out of order in character class\"\nmatch('💩', /[💩-💫]/u) // ['💩', index: 0, input: '💩', groups: undefined]\n\n// all operators like '.' includes unicode characters\nmatch('foo👋bar', /foo(.)bar/) // ['foo👋bar', '👋', index: 0, input: 'foo👋bar', groups: undefined)\n\n// With global flag\nmatch('🐵🐺🐶🐺🐱', /🐺/g) // ['🐺', '🐺']\n\nmatch('🏁🏳️‍🌈🏴🏳️‍🌈⛳🚩🏳️‍🌈🎌', /🏳️‍🌈[⛳🎌]/g) // ['🏳️‍🌈⛳', '🏳️‍🌈🎌']\n\n// Test if a string matches another string\nmatch('🏁🏳️‍🌈🏴🏳️‍🌈⛳🚩', '🏳️‍🌈') // ['🏳️‍🌈', index: 1, input: '🏁🏳️‍🌈🏴🏳️‍🌈⛳🚩', groups: undefined];\n\n// Special case when regexp is undefined\nmatch('Nothing will not match anything.', undefined) // null\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falienkevin%2Fstring-unified","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falienkevin%2Fstring-unified","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falienkevin%2Fstring-unified/lists"}