{"id":13583288,"url":"https://github.com/HubSpot/humanize","last_synced_at":"2025-04-06T18:32:09.676Z","repository":{"id":6524981,"uuid":"7765964","full_name":"HubSpot/humanize","owner":"HubSpot","description":"A simple utility library for making the web more humane. #hubspot-open-source","archived":false,"fork":false,"pushed_at":"2023-11-01T17:35:31.000Z","size":655,"stargazers_count":910,"open_issues_count":23,"forks_count":75,"subscribers_count":164,"default_branch":"master","last_synced_at":"2024-04-14T05:25:18.408Z","etag":null,"topics":[],"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/HubSpot.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}},"created_at":"2013-01-23T02:09:45.000Z","updated_at":"2024-04-04T10:22:00.000Z","dependencies_parsed_at":"2024-01-19T01:11:08.470Z","dependency_job_id":"79cd78dd-fc13-4119-9f13-883bb4296c14","html_url":"https://github.com/HubSpot/humanize","commit_stats":{"total_commits":135,"total_committers":15,"mean_commits":9.0,"dds":0.6370370370370371,"last_synced_commit":"ee0e597f7bf73c42f6841b2f60647b7f1f787cac"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fhumanize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fhumanize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fhumanize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fhumanize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HubSpot","download_url":"https://codeload.github.com/HubSpot/humanize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247531134,"owners_count":20953899,"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-01T15:03:22.942Z","updated_at":"2025-04-06T18:32:07.711Z","avatar_url":"https://github.com/HubSpot.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Humanize Plus\n\n[![npm version](https://img.shields.io/npm/v/humanize-plus.svg?style=flat-square)](https://www.npmjs.com/package/humanize-plus)\n[![build status](https://img.shields.io/travis/HubSpot/humanize/master.svg?style=flat-square)](https://travis-ci.org/HubSpot/humanize)\n[![npm downloads](https://img.shields.io/npm/dm/humanize-plus.svg?style=flat-square)](https://www.npmjs.com/package/humanize-plus)\n\n\nA simple utility library for making the web more humane.\n\n## Getting Started\n\nHumanize Plus is available via node package manager.\n\n`npm install humanize-plus`\n\nOr download the [minified version][min] or the [full version][max].\n\n[min]: https://raw.github.com/HubSpot/humanize/master/dist/humanize.min.js\n[max]: https://raw.github.com/HubSpot/humanize/master/src/humanize.js\n\nIn your web page:\n\n```html\n\u003cscript src=\"public/humanize.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\nvar capitalized = Humanize.capitalize(\"ten tiny ducklings.\")\n// \"Ten tiny ducklings.\"\n\u003c/script\u003e\n```\n\nIn your node package.json:\n```javascript\n\"dependencies\": {\n  \"humanize-plus\": \"^1.7.0\"\n}\n```\n\nFor recent changes, see the [changelog](https://github.com/HubSpot/humanize/blob/master/CHANGELOG.md).\n\n## API Methods\n\n### Numbers\n\n##### formatNumber\nFormats a number to a human-readable string. Localize by overriding the precision, thousand and decimal arguments.\n\n```javascript\nHumanize.formatNumber(123456789, 2)\n// \"123,456,789.00\"\n```\n\n##### intComma\nConverts an integer to a string containing commas every three digits.\n\n```javascript\nHumanize.intComma(123456789)\n// \"123,456,789\"\n```\n##### intcomma - DEPRECATED - This method will not be present in the next major version.\nAlias for `intComma`\n\n\n##### intword - DEPRECATED - This method will not be present in the next major version.\nConverts a large integer to a friendly text representation.\nThis method is now a thin wrapper around compactInteger\n\n`Humanize.intword(num, ch, de) === Humanize.compactInteger(num, de)`\n\n```javascript\nHumanize.intword(123456789, 'nopnopnopnop', 1)\n// \"123.5M\"\n\nHumanize.intword(123456789, 'this is a nop', 3)\n// \"123.457M\"\n\nHumanize.intword(10, 'still a nop', 1)\n// \"10\"\n```\n\n##### compactInteger\nConverts an integer into its most compact representation. Decimal precision is ignored for all integers, n, such that abs(n) \u003c 1000.\n\n```javascript\nHumanize.compactInteger(123456789, 1)\n// \"123.5M\"\n\n// Switch to scientific notation for trillons, because no one knows those abbreviations.\nHumanize.compactInteger(-7832186132456328967, 4)\n// \"-7.8322x10^18\"\n\nHumanize.compactInteger(-100, 2)\n// \"-100\"\n```\n\n##### boundedNumber\nBounds a value from above. Modified values have customizable ending strings ('+' by default)\n\n```javascript\nHumanize.boundedNumber(110, 100)\n// \"100+\"\n\nHumanize.boundedNumber(50, 100)\n// \"50\"\n```\n\n##### truncatenumber - DEPRECATED - This method will not be present in the next major version.\nAlias for `boundedNumber`\n\n##### ordinal\nConverts an integer to its ordinal as a string.\n\n```javascript\nHumanize.ordinal(22)\n// \"22nd\"\n```\n\n##### times\nInterprets numbers as occurences. Also accepts an optional array/map of overrides.\n\n```javascript\nfor (i=0; i\u003c5; i++) {\n  Humanize.times(i, {\"4\": \"too many\"});\n  // Bonus!\n  if (i === 1) {\n    Humanize.times(1.1);\n  }\n}\n// never\n// once\n// 1.1 times\n// twice\n// 3 times\n// too many times\n```\n\n##### pace\nMatches a pace (value and interval) with a logical time frame. Very useful for slow paces.\n\n```javascript\nsecond = 1000\nweek = 6.048e8\ndecade = 3.156e11\n\nHumanize.pace(1.5, second, \"heartbeat\")\n// Approximately 2 heartbeats per second\n\nHumanize.pace(4, week)\n// Approximately 4 times per week\n\nHumanize.pace(1, decade, \"life crisis\")\n// Less than 1 life crisis per week\n```\n\n##### fileSize\nFormats the value like a 'human-readable' file size (i.e. '13 KB', '4.1 MB', '102 bytes', etc).\n\n```javascript\nHumanize.fileSize(1024 * 20)\n// \"20 Kb\"\n\nHumanize.fileSize(1024 * 2000)\n// \"1.95 Mb\"\n\nHumanize.fileSize(Math.pow(1000, 4))\n// \"931.32 Gb\"\n```\n##### filesize - DEPRECATED - This method will not be present in the next major version.\nAlias for `fileSize`\n\n\n##### pluralize\nReturns the plural version of a given word if the value is not 1. The default suffix is 's'.\n\n```javascript\nHumanize.pluralize(1, \"duck\")\n// \"duck\"\n\nHumanize.pluralize(3, \"duck\")\n// \"ducks\"\n\nHumanize.pluralize(3, \"duck\", \"duckies\")\n// \"duckies\"\n```\n\n### Strings\n\n##### truncate\nTruncates a string if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis sequence (\"…\").\n\n```javascript\nHumanize.truncate('long text is good for you')\n// \"long text is good for you\"\n\nHumanize.truncate('long text is good for you', 19)\n// \"long text is goo...\"\n\nHumanize.truncate('long text is good for you', 19, '... etc')\n// \"long text is... etc\"\n```\n\n##### truncateWords\nTruncates a string after a certain number of words.\n\n```javascript\nHumanize.truncateWords('long text is good for you', 5)\n// \"long text is good for ...\"\n```\n\n##### truncatewords - DEPRECATED - This method will not be present in the next major version.\nAlias for `truncateWords`\n\n##### nl2br and br2nl\nFlexible conversion of `\u003cbr/\u003e` tags to newlines and vice versa.\n\n```javascript\n// Use your imagination\n```\n\n##### capitalize\nCapitalizes the first letter in a string, optionally downcasing the tail.\n\n```javascript\nHumanize.capitalize(\"some boring string\")\n// \"Some boring string\"\n\nHumanize.capitalize(\"wHoOaA!\")\n// \"WHoOaA!\"\n\nHumanize.capitalize(\"wHoOaA!\", true)\n// \"Whooaa!\"\n```\n\n##### capitalizeAll\nCaptializes the first letter of every word in a string.\n\n```javascript\nHumanize.capitalizeAll(\"some boring string\")\n// \"Some Boring String\"\n```\n\n##### titleCase\nIntelligently capitalizes eligible words in a string and normalizes internal whitespace.\n\n```javascript\nHumanize.titleCase(\"some of a boring string\")\n// \"Some of a Boring String\"\n\nHumanize.titleCase(\"cool the          iTunes cake, O'Malley!\")\n// \"Cool the iTunes Cake, O'Malley!\"\n```\n\n##### titlecase - DEPRECATED - This method will not be present in the next major version.\nAlias for `titleCase`\n\n\n### Arrays\n\n##### oxford\nConverts a list of items to a human readable string with an optional limit.\n\n```javascript\nitems = ['apple', 'orange', 'banana', 'pear', 'pineapple']\n\nHumanize.oxford(items)\n// \"apple, orange, banana, pear, and pineapple\"\n\nHumanize.oxford(items, 3)\n// \"apple, orange, banana, and 2 others\"\n\n// Pluralizes properly too!\nHumanize.oxford(items, 4)\n// \"apple, orange, banana, pear, and 1 other\"\n\nHumanize.oxford(items, 3, \"and some other fruits\")\n// \"apple, orange, banana, and some other fruits\"\n```\n\n##### frequency\nDescribes how many times an item appears in a list\n\n```javascript\ncatPics = [\n  'https://media2.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif',\n  'https://media3.giphy.com/media/uzglgIsyY1Cgg/giphy.gif'\n]\ndogPics = []\n\n\"Cats \" + Humanize.frequency(catPics, \"typed on keyboards\")\n// \"Cats typed on keyboards 3 times\"\n\n\"Dogs \" + Humanize.frequency(docPics, \"typed on keyboards\")\n// \"Dogs never typed on keyboards\"\n```\n\n\n### Utility methods\n\n##### toFixed\nFixes binary rounding issues (eg. (0.615).toFixed(2) === \"0.61\").\n\n```javascript\nHumanize.toFixed(0.615, 2)\n// \"0.62\"\n```\n\n##### normalizePrecision\nEnsures precision value is a positive integer.\n\n```javascript\nHumanize.normalizePrecision(-232.231)\n// 232\n```\n\n## Important notes\nPlease don't edit files in the `dist` subdirectory as they are generated through compilation. You'll find source code in the `src` subdirectory!\n\n## Compiling\n\n`npm run install \u0026\u0026 npm run build`\n\nAnd that's it!\n\nThe project will compile the CoffeeScript files into the `dist` subdirectory.\n\n## Testing\n\n`npm run test`\n\n\n## License\nCopyright (c) 2013-2016 HubSpotDev\nLicensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHubSpot%2Fhumanize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHubSpot%2Fhumanize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHubSpot%2Fhumanize/lists"}