{"id":22702390,"url":"https://github.com/phughesmcr/simplengrams","last_synced_at":"2025-09-07T06:08:05.822Z","repository":{"id":57361358,"uuid":"100054014","full_name":"phughesmcr/SimpleNGrams","owner":"phughesmcr","description":"The easiest way to get n-grams from strings!","archived":false,"fork":false,"pushed_at":"2024-02-29T21:46:32.000Z","size":348,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-20T23:35:42.943Z","etag":null,"topics":["ngram","ngrams","nlp","nlp-parsing","nlp-resources","text-mining"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/phughesmcr.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-08-11T17:05:48.000Z","updated_at":"2024-01-30T20:00:21.000Z","dependencies_parsed_at":"2024-02-29T14:45:53.575Z","dependency_job_id":"91882d59-dbca-4481-b00f-a181d7742db8","html_url":"https://github.com/phughesmcr/SimpleNGrams","commit_stats":null,"previous_names":["phugh/simplengrams"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/phughesmcr/SimpleNGrams","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phughesmcr%2FSimpleNGrams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phughesmcr%2FSimpleNGrams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phughesmcr%2FSimpleNGrams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phughesmcr%2FSimpleNGrams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phughesmcr","download_url":"https://codeload.github.com/phughesmcr/SimpleNGrams/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phughesmcr%2FSimpleNGrams/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274001714,"owners_count":25205318,"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","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"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":["ngram","ngrams","nlp","nlp-parsing","nlp-resources","text-mining"],"created_at":"2024-12-10T07:13:18.162Z","updated_at":"2025-09-07T06:08:05.781Z","avatar_url":"https://github.com/phughesmcr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🗿 SimpleNGrams\n\nThe easiest way to get an array of n-grams from a string or array of tokens!\n\nNo dependencies!\n\n## Install\n\n```bash\nnpm install --production --save simplengrams\n```\n\n## Usage\n\nSimpleNGrams exports one function: `nGram()`.\n\nThe function take the following arguments:\n\n- `input` - a string or array of strings to be split into ngrams.\n- `n` - the ngram size as a number. Defaults to 2 (i.e. bigrams).\n- `pad` - optional padding parameter. Takes a boolean or an array. Defaults to\n  false (i.e. no padding). See [Padding](#padding) below.\n- `splitPattern` - optional pattern as string or RegExp to split input string\n  by. Defaults to spaces. See [Pattern](#pattern) below.\n\n## Example\n\n```javascript\nimport { nGram } from \"simplengrams\";\nconst text = \"In the beginning God created the heavens and the earth.\";\nconst bigrams = nGram(text);\nconsole.log(bigrams);\n```\n\nOutput:\n\n```javascript\n[\n  [\"In\", \"the\"],\n  [\"the\", \"beginning\"],\n  [\"beginning\", \"God\"],\n  [\"God\", \"created\"],\n  [\"created\", \"the\"],\n  [\"the\", \"heavens\"],\n  [\"heavens\", \"and\"],\n  [\"and\", \"the\"],\n  [\"the\", \"earth\"],\n  [\"earth\", \".\"],\n];\n```\n\n## Padding\n\nCustom padding options can be used to add right and left padding to the output\narray.\n\nThe padding argument is the third argument in `nGram()`. It takes a boolean\n(i.e. `true` or `false`) or an array.\n\nThe padding option defaults to `false` if it is not supplied.\n\nSome examples:\n\n- `false` = padding is not applied.\n\n- `true` = `null` is used as padding.\n\n- `['FOO', 'BAR']` = The string `'FOO'` is used as left padding and the string\n  `'BAR'` is used as right padding.\n\n- `['FOOBAR']` = The string `'FOOBAR'` is used as both left and right padding.\n\nYou can disable individual padding by using `undefined` like so:\n\n- `[undefined, 'BAR']` will disable left padding and use `'BAR'` as right\n  padding.\n\nN.B. `null` will cause the padder to use the `null` element literally. Use\n`undefined` instead to disable padding.\n\nN.B. Simply use `false` instead of `[undefined, undefined]` - it results in the\nsame output but is slightly faster.\n\n### Examples\n\n#### pad = true\n\n```javascript\nimport { nGram } from \"simplengrams\";\nconst text = \"In the beginning God created the heavens and the earth.\";\nconst bigrams = nGram(text, 2, true);\nconsole.log(bigrams);\n```\n\n```javascript\n[\n  [null, \"In\"],\n  [\"In\", \"the\"],\n  [\"the\", \"beginning\"],\n  [\"beginning\", \"God\"],\n  [\"God\", \"created\"],\n  [\"created\", \"the\"],\n  [\"the\", \"heavens\"],\n  [\"heavens\", \"and\"],\n  [\"and\", \"the\"],\n  [\"the\", \"earth\"],\n  [\"earth\", \".\"],\n  [\".\", null],\n];\n```\n\n#### pad = [undefined, 'END']\n\n```javascript\nimport { nGram } from \"simplengrams\";\nconst text = \"In the beginning God created the heavens and the earth.\";\nconst bigrams = nGram(text, 2, [undefined, \"END\"]);\nconsole.log(bigrams);\n```\n\n```javascript\n[\n  [\"In\", \"the\"],\n  [\"the\", \"beginning\"],\n  [\"beginning\", \"God\"],\n  [\"God\", \"created\"],\n  [\"created\", \"the\"],\n  [\"the\", \"heavens\"],\n  [\"heavens\", \"and\"],\n  [\"and\", \"the\"],\n  [\"the\", \"earth\"],\n  [\"earth\", \".\"],\n  [\".\", \"END\"],\n];\n```\n\n\u003ca name=\"pattern\"\u003e\n\n## Pattern\n\nThe pattern argument is an optional fourth argument of `nGram()`.\n\nIt defaults to `/\\s+/` and can take a string or a RegExp.\n\nIf your input is an array, the pattern argument is ignored.\n\nFor string inputs, the pattern argument is used to split the string into tokens,\nexactly like `string.split()`.\n\n## Testing\n\nUse `node index.test.js` to check any development changes against expected outputs.\n\n## License\n\n\u0026copy; 2017-24 [P. Hughes](https://www.phugh.es). All rights reserved.\n\nShared under the\n[MIT license](http://creativecommons.org/licenses/by-nc-sa/3.0/) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphughesmcr%2Fsimplengrams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphughesmcr%2Fsimplengrams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphughesmcr%2Fsimplengrams/lists"}