{"id":15413514,"url":"https://github.com/wooorm/trigram-utils","last_synced_at":"2025-04-19T11:53:21.756Z","repository":{"id":20937745,"uuid":"24226054","full_name":"wooorm/trigram-utils","owner":"wooorm","description":"A few language trigram utilities","archived":false,"fork":false,"pushed_at":"2022-11-20T10:50:54.000Z","size":75,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-17T17:18:26.041Z","etag":null,"topics":["clean","trigram","tuple"],"latest_commit_sha":null,"homepage":"","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/wooorm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":"funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"wooorm"}},"created_at":"2014-09-19T10:32:34.000Z","updated_at":"2024-04-13T09:04:24.000Z","dependencies_parsed_at":"2022-08-28T05:40:15.935Z","dependency_job_id":null,"html_url":"https://github.com/wooorm/trigram-utils","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Ftrigram-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Ftrigram-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Ftrigram-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Ftrigram-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/trigram-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249445277,"owners_count":21273573,"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":["clean","trigram","tuple"],"created_at":"2024-10-01T16:57:30.704Z","updated_at":"2025-04-19T11:53:21.740Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/wooorm"],"categories":[],"sub_categories":[],"readme":"# trigram-utils\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n\nA few language trigram utilities.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`clean(value)`](#cleanvalue)\n    *   [`trigrams(value)`](#trigramsvalue)\n    *   [`asDictionary(value)`](#asdictionaryvalue)\n    *   [`asTuples(value)`](#astuplesvalue)\n    *   [`tuplesAsDictionary(tuples)`](#tuplesasdictionarytuples)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package contains a few utilities that can help when working with trigram\n(an n-gram where each slice is 3 characters) based natural language detection.\n\n## When should I use this?\n\nProbably not often, except when you want to create something like [franc][],\nbut build it in something other than UDHR.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 14.14+, 16.0+), install with [npm][]:\n\n```sh\nnpm install trigram-utils\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport * as trigramUtils from 'https://esm.sh/trigram-utils@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import * as trigramUtils from 'https://esm.sh/trigram-utils@2?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {clean, trigrams, asDictionary, asTuples, tuplesAsDictionary} from 'trigram-utils'\n\nclean(' t@rololol ') // =\u003e 't rololol'\n\ntrigrams(' t@rololol ')\n// =\u003e [' t ', 't r', ' ro', 'rol', 'olo', 'lol', 'olo', 'lol', 'ol ']\n\nasDictionary(' t@rololol ')\n// =\u003e {'ol ': 1, lol: 2, olo: 2, rol: 1, ' ro': 1, 't r': 1, ' t ': 1}\n\nconst tuples = asTuples(' t@rololol ')\n// =\u003e [\n//   ['ol ', 1],\n//   ['rol', 1],\n//   [' ro', 1],\n//   ['t r', 1],\n//   [' t ', 1],\n//   ['lol', 2],\n//   ['olo', 2]\n// ]\n\ntuplesAsDictionary(tuples)\n// =\u003e {olo: 2, lol: 2, ' t ': 1, 't r': 1, ' ro': 1, rol: 1, 'ol ': 1}\n```\n\n## API\n\nThis package exports the identifiers `clean`, `trigrams`,\n`asDictionary`, `asTuples`, and `tuplesAsDictionary`.\nThere is no default export.\n\n### `clean(value)`\n\nClean a value (`string`).\nStrips some (for language detection) useless punctuation, symbols, and numbers.\nCollapses white space, trims, and lowercases.\n\n### `trigrams(value)`\n\nFrom a value (`string`), make clean, padded trigrams (see [`n-gram`][n-gram])\n(`Array\u003cstring\u003e`).\n\n### `asDictionary(value)`\n\nFrom a value (`string`), get clean trigrams as a dictionary\n(`Record\u003cstring, number\u003e`): keys are trigrams, values are occurrence counts.\n\n### `asTuples(value)`\n\nFrom a value (`string`), get clean trigrams with occurrence counts as a tuple\n(`Array\u003c[string, number]\u003e`): first index (`0`) the trigram, second (`1`) the\noccurrence count.\n\n### `tuplesAsDictionary(tuples)`\n\nTurn trigram tuples (`Array\u003c[string, number]\u003e`) into a dictionary\n(`Record\u003cstring, number\u003e`).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types `TrigramTuple`, `TrigramTuples`, and\n`TrigramDictionary`.\n\n## Compatibility\n\nThis package is at least compatible with all maintained versions of Node.js.\nAs of now, that is Node.js 14.14+ and 16.0+.\nIt also works in Deno and modern browsers.\n\n## Security\n\nThis package is safe.\n\n## Related\n\n*   [`words/trigrams`](https://github.com/wooorm/trigrams)\n    — trigrams for 400+ languages based on UDHR\n*   [`words/n-gram`](https://github.com/words/n-gram)\n    — get n-grams from text\n*   [`wooorm/franc`][franc]\n    — natural language detection\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][contribute].\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/wooorm/trigram-utils/workflows/main/badge.svg\n\n[build]: https://github.com/wooorm/trigram-utils/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/trigram-utils.svg\n\n[coverage]: https://codecov.io/github/wooorm/trigram-utils\n\n[downloads-badge]: https://img.shields.io/npm/dm/trigram-utils.svg\n\n[downloads]: https://www.npmjs.com/package/trigram-utils\n\n[size-badge]: https://img.shields.io/bundlephobia/minzip/trigram-utils.svg\n\n[size]: https://bundlephobia.com/result?p=trigram-utils\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[typescript]: https://www.typescriptlang.org\n\n[contribute]: https://opensource.guide/how-to-contribute/\n\n[n-gram]: https://github.com/words/n-gram\n\n[franc]: https://github.com/wooorm/franc\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Ftrigram-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Ftrigram-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Ftrigram-utils/lists"}