{"id":16552151,"url":"https://github.com/pandasekh/better-substring","last_synced_at":"2026-05-11T15:03:41.386Z","repository":{"id":124296838,"uuid":"381318786","full_name":"PandaSekh/Better-Substring","owner":"PandaSekh","description":"✂ Improved substring method to avoid splitting mid word","archived":false,"fork":false,"pushed_at":"2021-06-29T14:59:41.000Z","size":109,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-15T00:32:33.405Z","etag":null,"topics":["split","string-manipulation","substring","trim"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/better-substring","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/PandaSekh.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":"2021-06-29T10:01:51.000Z","updated_at":"2021-06-29T15:26:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"cc1a3ecf-61c5-4c14-b44c-97b99bf70338","html_url":"https://github.com/PandaSekh/Better-Substring","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandaSekh%2FBetter-Substring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandaSekh%2FBetter-Substring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandaSekh%2FBetter-Substring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandaSekh%2FBetter-Substring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PandaSekh","download_url":"https://codeload.github.com/PandaSekh/Better-Substring/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241885688,"owners_count":20036955,"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":["split","string-manipulation","substring","trim"],"created_at":"2024-10-11T19:44:06.063Z","updated_at":"2026-05-11T15:03:36.356Z","avatar_url":"https://github.com/PandaSekh.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  Better Substring\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/PandaSekh/better-substring/actions/workflows/test.yml/badge.svg\" alt=\"Build Status\"\u003e\n  \u003cimg src=\"https://img.badgesize.io/https:/unpkg.com/better-substring@latest/dist/index.js?compression=brotli\u0026label=size\" alt=\"Size\"\u003e\n  \u003cimg alt=\"Dependencies\" src=\"https://img.shields.io/badge/dependencies-none-brightgreene\"\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e✂ Improved substring method to avoid splitting mid word\u003c/p\u003e\n\nbetter-substring is a *lightweight* (**~180 bytes**) tool that enhances the default substring method. No more words split in half!\n\n* * *\n\n## Install\n\nnpm: \n```bash\nnpm install --save better-substring\n```\n\nYarn:\n```bash\nyarn add better-substring\n```\n\n## Examples\nBasic example, will try to split at index 3.\n```js\nimport betterSubstring from \"better-substring\";\n\nconst sentence = \"Hello World :D\";\n\nconst subs = betterSubstring(sentence, 0, false, 3, true);\n\nconsole.log(subs); // \"Hello\"\n```\n\nInstead of going forward until the word is finished, with `false` we go back.\n```js\nimport betterSubstring from \"better-substring\";\n\nconst sentence = \"Hello World :D\";\n\nconst subs = betterSubstring(sentence, 0, false, 8, false);\n\nconsole.log(subs); // \"Hello\"\n```\n\nWe can also define a starting point\n```js\nimport betterSubstring from \"better-substring\";\n\nconst sentence = \"Hello World :D\";\n\nconst subs = betterSubstring(sentence, 6, true, 8, true);\n\nconsole.log(subs); // \"World\"\n```\n\n## API\n### `substring(sentence: string, init: number, initForward = false, end?: number, endForward = true) =\u003e string`\n\nReturns a substring without splitting words.\n\n- `sentence: string` the sentence/string to work with. \n- `init: string` index where to start the substring. 0 to start from the beginning. \n- `initForward = false` (optional) in case the split will occur mid-word, shall we go forward (true) or back (false)?. \n- `end: number` (optional) index where you want the split to occur. \n- `endForward = true` (optional) in case the split will occur mid-word, shall we go forward (true) or back (false)?. \n\n## License\n\nMIT © [PandaSekh](https://github.com/PandaSekh)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandasekh%2Fbetter-substring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpandasekh%2Fbetter-substring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandasekh%2Fbetter-substring/lists"}