{"id":13801054,"url":"https://github.com/vixalien/written","last_synced_at":"2025-05-13T10:31:03.094Z","repository":{"id":62422684,"uuid":"484198387","full_name":"vixalien/written","owner":"vixalien","description":"A set of utilities for manipulating text, with a focus on providing typographic tools rather than pure string manipulation.","archived":false,"fork":true,"pushed_at":"2024-09-04T17:24:59.000Z","size":120,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-06T00:36:27.494Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"stephenhutchings/written","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vixalien.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}},"created_at":"2022-04-21T20:40:10.000Z","updated_at":"2024-09-04T17:25:02.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/vixalien/written","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/vixalien%2Fwritten","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vixalien%2Fwritten/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vixalien%2Fwritten/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vixalien%2Fwritten/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vixalien","download_url":"https://codeload.github.com/vixalien/written/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225198966,"owners_count":17437008,"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":[],"created_at":"2024-08-04T00:01:19.076Z","updated_at":"2024-11-18T15:31:28.996Z","avatar_url":"https://github.com/vixalien.png","language":"TypeScript","funding_links":[],"categories":["Modules"],"sub_categories":["String utils"],"readme":"### written\n\n[![Build Status](https://travis-ci.org/stephenhutchings/written.svg)](https://travis-ci.org/stephenhutchings/written)\n\n_written_ provides a set of utilities for manipulating text, with a focus on\nproviding typographic tools rather than pure string manipulation. It can be\nadded as a set of mixins to Underscore or used in it's own right, both in front\nand back end contexts.\n\n- [Capitalization](#capitalization)\n- [Utilities](#utilities)\n- [Collapse](#collapse)\n- [Cases](#cases)\n- [Tags](#tags)\n- [Lists](#lists)\n- [Hyphenation](#hyphenation)\n- [Quantify](#quantify)\n- [Written Numbers](#written-numbers)\n- [Quotes](#quotes)\n- [Ordinals](#ordinals)\n- [Numbers](#numbers)\n- [Glyphs](#glyphs)\n- [Language Support](#language-support)\n\n##### Deno or ESM\n\n```js\nimport * as written from \"https://deno.land/x/written/written.ts\";\n\n// or import singular functions\nimport { writtenNumber } from \"https://deno.land/x/written/written.ts\";\n```\n\n##### Browser\n\n```html\n\u003cscript type=\"module\" src=\u003e\u003c/script\u003e\n```\n\n##### NPM\n\nAs this is a Deno fork, the original NPM version is published by\n@stephenhutchings from the repo\n[stephenhutchings/written](https://www.github.com/stephenhutchings/written).\nNote that the Node version doesn't have types.\n\n```bash\nnpm install written\n```\n\n---\n\n#### Setup\n\n_written_ can be used in any environment that supports both ES Modules and\nTypeScript.\n\nSome style guides prefer the numbers 12 and under to be written, so we'll\ninclude those in here. If more or fewer numbers need to be added, or those from\nanother language, see [Language Support](#language-support).\n\nFollowing the APA style guide (for ease and practicality) conjunctions,\narticles, and short prepositions of less than four letters will be left in\nlowercase when calling `capitalizeAll()`.\n\nA rule is needed to determine the correct ordinal for any number. For English,\nwe use match in such a way that the first value in the matching array is\nreturned, unless it is 11, 12 or 13. We use this number to determine the correct\nordinal form.\n\n---\n\n#### Capitalization\n\nCapitalize the first letter of a string.\n\nExamples:\n\n```ts\nw.capitalize(\"obviously\");                       // Obviously\n```\n\nCapitalize all words in a string apart from some common lower case words. This\ncan be tested with the internal noncaps regular expression, which are stored by\nlanguage code, or by passing a regular expression of your own.\n\nExamples:\n\n```ts\nw.capitalizeAll(\"this and that\");                // This and That\nw.capitalizeAll(\"the cat in the hat\");           // The Cat in the Hat\n```\n\n#### Utilities\n\n`enclose` wraps a string within two other strings, repeating the first if needs\nbe. `cleanJoin` joins an array of words with falsy, non-string values removed\nwith some glue. Both are used internally but are offered in case of their\nexternal value.\n\nExamples:\n\n```ts\nw.enclose(\"'\", \"string\");                        // 'string'\nw.cleanJoin([\"this\", null, \"that\"], \" and \");    // this and that\n```\n\n#### Collapse\n\nReplace all white-space in a string with a single space character\n\nExamples:\n\n```ts\nw.collapse(\"this   \\t\\t and \\n    that\");        // this and that\n```\n\n#### Cases\n\nTransform strings between common code cases.\n\nExamples:\n\n```ts\nw.camelCase(\"some-thing\");                       // someThing\nw.hyphenCase(\"some_thing\");                      // some-thing\nw.snakeCase(\"someThing\");                        // some_thing\nw.humanCase(\"fromA_to-Z\");                       // from A to Z\n```\n\nThis helps to split \"cased\" words into their constituent parts...\n\n#### Tags\n\nEnclose a string inside an HTML tag.\n\nExamples:\n\n```ts\nw.wrapInTag(\"Hello world!\");                     // \u003cspan\u003eHello world!\u003c/span\u003e\nw.wrapInTag(\"Hello world!\", \"em\");               // \u003cem\u003eHello world!\u003c/em\u003e\nw.wrapInTag(                                     // \u003ca href=\"/url\" class=\"b\" disabled=\"disabled\"\u003eLink\u003c/a\u003e\n  \"Link\",\n  \"a\",\n  {\n    href: \"/url\",\n    class: [\"b\"],\n    disabled: true,\n  },\n);\n```\n\n#### Lists\n\nGroup strings into a grammatically correct list with an arbitrary limit. The\nfinal example shows all the possible options available.\n\nExamples:\n\n```ts\nw.prettyList([\"Ben\", \"Bob\"])                     // Ben and Bob\nw.prettyList([\"Ben\", \"Bob\", \"Bill\"])             // Ben, Bob and Bill\nw.prettyList([\"Ben\", \"Bob\", \"Bill\", \"Max\"], 2)   // Ben, Bob and 2 more\nw.prettyList([\"Ben\", \"Bob\"], 1, {more: \"other\"}) // Ben and 1 other\nw.prettyList([                                   // Document 1 \u0026 two other files\n  {file: \"Document 1\"},\n  {file: \"Document 2\"},\n  {file: \"Document 3\"}\n], 1, {\n  amp: \"\u0026\"\n  written: true,\n  more: \"other file\",\n  quantify: true,\n  key: \"file\"\n})\n```\n\n#### Hyphenation\n\nAdd soft hyphens every `n` characters so that the CSS attribute\n`hyphens: manual` will allow for nice breaks in long strings of text. This is\nespecially useful on mobile devices, where long strings can break the layout.\n\nExamples:\n\n```ts\nw.hyphenate(\"antidisestablishmentarianism\"); // antidisest%C2%ADablishm...\n```\n\n#### Quantify\n\nAdd an \"s\" to a string when an amount is non-singular, disregarding the order of\nthe arguments passsed. If an array or collection is passed, it’s length will be\nused as the numerical input.\n\nExamples:\n\n```ts\nw.quantify(\"monkey\", 1);                         // 1 monkey\nw.quantify(1, \"monkey\");                         // 1 monkey\nw.quantify(\"monkey\", 9, { written: true });      // nine monkeys\nw.quantify(\"person\", 9, { plural: \"people\" });   // 9 people\nw.quantify([1, 2, 3], \"number\");                 // 3 numbers\n```\n\n#### Written Numbers\n\nConvert numbers between one and twelve into their written counter-parts.\n\nExamples:\n\n```ts\nw.writtenNumber(1);                              // one\nw.writtenNumber(2, \"DE\");                        // zwei\n```\n\n#### Quotes\n\nWrap a string in single or double quotes or guillemets (angle quotes).\n\nExamples:\n\n```ts\nw.quote(\"pastry chef\", \"s\");                     // ‘pastry chef’\nw.quote(\"cats cradle\");                          // “cats cradle”\nw.quote(\"tres chic\", \"a\");                       // «tres chic»\nw.quote(\"Gol\", \"!\");                             // ¡Gol!\nw.quote(\"Cómo estás\", \"?\");                      // ¿Cómo estás?\n```\n\n#### Ordinals\n\nConvert a number from it's cardinal to ordinal equivalent.\n\nExamples:\n\n```ts\nw.ordinal(1);                                    // 1st\nw.ordinal(2, { written: true });                 // second\nw.ordinal(3, { wrap: true });                    // 3\u003csup\u003erd\u003c/sup\u003e\nw.ordinal(4, { wrap: \"em\" });                    // 4\u003cem\u003eth\u003c/em\u003e\n```\n\n#### Numbers\n\nFormat a number in various ways and parse one from a string.\n\nExamples:\n\n```ts\nw.prettyNumber(1000);                            // 1,000\nw.prettyNumber(10.5, 2);                         // 10.50\nw.prettyNumber(9999, \" \", 2, \",\");               // 9 999,00\n\nw.prettyPrice(4);                                // $4.00\nw.prettyPrice(1200, \"£\");                        // £1,200.00\nw.prettyPrice(                                   // €4\u003csup\u003e00\u003c/sup\u003e\n  4,\n  {\n    currency: \"€\",\n    wrap: \"sup\",\n  },\n);\n\nw.prettyPercent(0.5);                            // 50%\nw.prettyPercent(1, 4);                           // 25%\nw.prettyPercent(1, 3, 2);                        // 33.33%\n\nw.parseNumber(1000);                             // 1000\nw.parseNumber(\"1,000.00\");                       // 1000\nw.parseNumber(\"99%\");                            // 0.99\nw.parseNumber(\"some 44,000 participants\");       // 44000\n```\n\n#### Glyphs\n\nProvide quick access to different typographic glyphs without the need commit\nthem to memory or look at a reference table.\n\nExamples:\n\n```ts\nw.glyphs();                                      // Create map of ASCII glyphs\nw.glyph(\"!\");                                    // \u0026#33;\n```\n\n#### Language Support\n\nSet cardinal and ordinal numbers and non-caps words for different languages as\nappropriate. Please note that only partial support for French, German, Italian,\nSpanish and Swedish is currently implemented. If using in the browser, ensure\nthat the document's charset is set to UTF-8. _Pull requests which extend\nlanguage support are encouraged._\n\nTo load and install a locale, do:\n\n```ts\nimport * as written from \"https://deno.land/x/written/written.ts\";\nimport * as DE from \"https://deno.land/x/written/lang/written.de.ts\";\n// there is also es,fs,it and se.\n\nwritten.setLanguage(DE.dico, DE.code);\n\n// now all your operations will be based on the DE locale.\nw.writtenNumber(1);                              // eins\n\n// you can also override the set locale:\nw.writtenNumber(2, \"EN\");                        // two\n```\n\n#### Aliases\n\nPack up the `written` object (with some aliases...)\n\n* `dasherize` -\u003e `hyphenCase`\n* `dashify` -\u003e `hyphenCase`\n* `slugify` -\u003e `snakeCase`\n* `underscore` -\u003e `snakeCase`\n* `numerate` -\u003e `quantify`\n* `count` -\u003e `quantify`\n* `titleCase` -\u003e `capitalizeAll`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvixalien%2Fwritten","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvixalien%2Fwritten","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvixalien%2Fwritten/lists"}