{"id":13528337,"url":"https://github.com/sallar/stringz","last_synced_at":"2025-05-15T22:06:54.511Z","repository":{"id":10056186,"uuid":"64241254","full_name":"sallar/stringz","owner":"sallar","description":":100: Super fast unicode-aware string manipulation Javascript library","archived":false,"fork":false,"pushed_at":"2024-09-11T14:30:25.000Z","size":1075,"stargazers_count":237,"open_issues_count":17,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-14T10:11:55.137Z","etag":null,"topics":["javascript","nodejs","string-manipulation","strings","substr","unicode","utf-8"],"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/sallar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2016-07-26T17:32:03.000Z","updated_at":"2025-03-15T20:58:25.000Z","dependencies_parsed_at":"2024-06-18T12:39:18.869Z","dependency_job_id":"27859955-e99c-4176-8547-8986fef7eb00","html_url":"https://github.com/sallar/stringz","commit_stats":{"total_commits":107,"total_committers":14,"mean_commits":7.642857142857143,"dds":0.383177570093458,"last_synced_commit":"80c3be398e7ba9be4fd763b74ec33f3a3f790912"},"previous_names":["sallar/limit-string-length"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sallar%2Fstringz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sallar%2Fstringz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sallar%2Fstringz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sallar%2Fstringz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sallar","download_url":"https://codeload.github.com/sallar/stringz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254430330,"owners_count":22069909,"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":["javascript","nodejs","string-manipulation","strings","substr","unicode","utf-8"],"created_at":"2024-08-01T06:02:26.307Z","updated_at":"2025-05-15T22:06:54.456Z","avatar_url":"https://github.com/sallar.png","language":"TypeScript","readme":"# Stringz [![Build Status](https://travis-ci.org/sallar/stringz.svg?branch=master)](https://travis-ci.org/sallar/stringz) [![codecov](https://codecov.io/gh/sallar/stringz/branch/master/graph/badge.svg)](https://codecov.io/gh/sallar/stringz) [![npm](https://img.shields.io/npm/dm/stringz.svg)](https://www.npmjs.com/package/stringz)\n\nA really small, performant, unicode-aware library for working\nwith Strings in Node.js.\n\nJavascript has a serious problem with unicode. Even ES6 can’t solve the problem\nentirely since some characters like the new colored emojis are three bytes\ninstead of two bytes. Sometimes even more! `\"👍🏽\".length` returns `4` which is\ntotally wrong (hint: it should be 1!). ES6's `Array.from` tried to solve this,\nbut that even fails: `Array.from(\"👍🏽\")` returns `[\"👍\", \"🏽\"]` which is\nincorrect. This library tries to tackle all these problems with a mega RegExp.\n[Read More Here](https://mathiasbynens.be/notes/javascript-unicode).\n\n## Features\n\n* Unicode-aware string manipulation tools\n* High performance\n\n## Install\n\n```bash\n$ npm install stringz --save\n```\n\nAnd import it in your awesome node app:\n\n```javascript\n// ES2015+\nimport * as stringz from 'stringz'; // OR:\nimport { limit, substring, length, substr } from 'stringz';\n```\n\n```javascript\n// CommonJS\nconst stringz = require('stringz'); // OR:\nconst { limit, substr } = require('stringz');\n```\n\n## Usage\n\n* [`limit()`](#limit-string-to-width)\n* [`length()`](#string-length)\n* [`substring()`](#substring)\n* [`substr()`](#substr)\n* [`indexOf()`](#indexof)\n* [`toArray()`](#toarray)\n\n### Limit String to Width\n\n    function limit(str[, limit[, padStr[, padPosition]]])\n\n| Param       | Type                | Default              | Description                                               |\n| ----------- | ------------------- | -------------------- | --------------------------------------------------------- |\n| str         | \u003ccode\u003eString\u003c/code\u003e | _none_               | The string to be limited                                  |\n| limit       | \u003ccode\u003eNumber\u003c/code\u003e | \u003ccode\u003e16\u003c/code\u003e      | Desired string length                                     |\n| padStr      | \u003ccode\u003eString\u003c/code\u003e | \u003ccode\u003e\"#\"\u003c/code\u003e     | Character to pad the output with                          |\n| padPosition | \u003ccode\u003eString\u003c/code\u003e | \u003ccode\u003e\"right\"\u003c/code\u003e | Pad position: \u003ccode\u003e\"right\"\u003c/code\u003e or \u003ccode\u003e\"left\"\u003c/code\u003e |\n\n#### Examples\n\n```javascript\n// Truncate:\nlimit('Life’s like a box of chocolates.', 20); // \"Life's like a box of\"\n\n// Pad:\nlimit('Everybody loves emojis!', 26, '💩'); // \"Everybody loves emojis!💩💩💩\"\nlimit('What are you looking at?', 30, '+', 'left'); // \"++++++What are you looking at?\"\n\n// Unicode Aware:\nlimit('🤔🤔🤔', 2); // \"🤔🤔\"\nlimit('👍🏽👍🏽', 4, '👍🏽'); // \"👍🏽👍🏽👍🏽👍🏽\"\n```\n\n### String Length\n\n    function length(str)\n\n| Param | Type                | Default | Description                     |\n| ----- | ------------------- | ------- | ------------------------------- |\n| str   | \u003ccode\u003eString\u003c/code\u003e | _none_  | String to return the length for |\n\n#### Examples\n\n```javascript\nlength('Iñtërnâtiônàlizætiøn☃💩'); // 22\n```\n\n### Substring\n\n    function substring(str, start[, end])\n\n| Param | Type                | Default       | Description          |\n| ----- | ------------------- | ------------- | -------------------- |\n| str   | \u003ccode\u003eString\u003c/code\u003e | _none_        | String to be devided |\n| start | \u003ccode\u003eNumber\u003c/code\u003e | _none_        | Start position       |\n| end   | \u003ccode\u003eNumber\u003c/code\u003e | End of string | End position         |\n\n#### Examples\n\n```javascript\nsubstring('Emojis 👍🏽 are 🍆 poison. 🌮s are bad.', 7, 14); // \"👍🏽 are 🍆\"\n```\n\n### Substr\n\n    function substr(str[, start[, length]])\n\n| Param  | Type                | Default                               | Description          |\n| ------ | ------------------- | ------------------------------------- | -------------------- |\n| str    | \u003ccode\u003eString\u003c/code\u003e | _none_                                | String to be devided |\n| start  | \u003ccode\u003eNumber\u003c/code\u003e | Start of string                       | Start position       |\n| length | \u003ccode\u003eNumber\u003c/code\u003e | String length minus `start` parameter | Length of result     |\n\n#### Examples\n\n```javascript\nsubstr('A.C. Milan 🇮🇹⚽️', 5, 7); // \"Milan 🇮🇹\"\n```\n\n### IndexOf\n\n    function indexOf(str[, searchStr[, position]])\n\n| Param     | Type                | Default | Description           |\n| --------- | ------------------- | ------- | --------------------- |\n| str       | \u003ccode\u003eString\u003c/code\u003e | _none_  | String to get index   |\n| searchStr | \u003ccode\u003eString\u003c/code\u003e | _none_  | String to be searched |\n| position  | \u003ccode\u003eNumber\u003c/code\u003e | 0       | Start of searching    |\n\n#### Examples\n\n```javascript\nindexOf('Emojis 👍🏽 are 🍆 poison. 🌮s are bad.', 'are'); // 9\nindexOf('Emojis 👍🏽 are 🍆 poison. 🌮s are bad.', 'are', 10); // 26\n```\n\n### ToArray\n\n    function toArray(str)\n\n| Param | Type                | Default | Description                |\n| ----- | ------------------- | ------- | -------------------------- |\n| str   | \u003ccode\u003eString\u003c/code\u003e | _none_  | String to convert to array |\n\n#### Examples\n\n```javascript\ntoArray('👍🏽🍆🌮'); // ['👍🏽', '🍆', '🌮']\n```\n\n## Test\n\n```bash\n$ npm test\n```\n\n## Benchmark\n\nThis library scores high in a length benchmark (it's intended usage) and should\nbe fast for most use case.\n\n```\nStringz .length (accurate) x 861,039 ops/sec ±1.57% (84 runs sampled)\nLodash .toArray (accurate) x 795,108 ops/sec ±2.13% (82 runs sampled)\nEmoji Aware .split (inaccurate) x 2,269 ops/sec ±1.38% (85 runs sampled)\nSpliddit .length (inaccurate) x 487,718 ops/sec ±2.21% (83 runs sampled)\nUTF8 Length (inaccurate) x 232,918 ops/sec ±1.02% (87 runs sampled)\nFastest is Stringz .length\n```\n\nTo run benchmarks yourself:\n\n```bash\n$ cd ./benchmark\n$ npm install\n$ node run.js\n```\n\n## Changelog\n\n[Moved to CHANGELOG.md](CHANGELOG.md)\n\n## License\n\nThis software is released under the\n[MIT License](http://sallar.mit-license.org/).\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsallar%2Fstringz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsallar%2Fstringz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsallar%2Fstringz/lists"}