{"id":16382890,"url":"https://github.com/dresende/node-ziffer","last_synced_at":"2025-03-23T03:33:25.025Z","repository":{"id":21336459,"uuid":"92392856","full_name":"dresende/node-ziffer","owner":"dresende","description":"NodeJS simple number formatter","archived":false,"fork":false,"pushed_at":"2024-03-27T08:03:47.000Z","size":89,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T17:24:46.407Z","etag":null,"topics":["currency","nodejs","numberformat"],"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/dresende.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-25T10:33:44.000Z","updated_at":"2023-01-30T09:47:11.000Z","dependencies_parsed_at":"2024-10-28T15:24:18.508Z","dependency_job_id":"744212de-bc99-4716-904e-fccd4ec86748","html_url":"https://github.com/dresende/node-ziffer","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dresende%2Fnode-ziffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dresende%2Fnode-ziffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dresende%2Fnode-ziffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dresende%2Fnode-ziffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dresende","download_url":"https://codeload.github.com/dresende/node-ziffer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245052647,"owners_count":20553162,"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":["currency","nodejs","numberformat"],"created_at":"2024-10-11T04:06:46.757Z","updated_at":"2025-03-23T03:33:24.693Z","avatar_url":"https://github.com/dresende.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Ziffer\n\n[![Build](https://github.com/dresende/node-ziffer/workflows/Node.js%20CI/badge.svg)](https://github.com/dresende/node-ziffer/actions)\n[![Code Climate](https://codeclimate.com/github/dresende/node-ziffer/badges/gpa.svg)](https://codeclimate.com/github/dresende/node-ziffer)\n[![](https://badge.fury.io/js/ziffer.svg)](https://npmjs.org/package/ziffer)\n\nNodeJS simple number formatter.\n\n### Install\n\n```sh\nnpm i ziffer\n```\n\n### Usage\n\n```js\nconst ziffer = require(\"ziffer\");\nconst euro   = ziffer({ inprefix: \"€ \", decimals: 2 });\n\n// prints \"€ 12 345,68\"\nconsole.log(euro.format(12345.678));\n\n// prints \"-€ 12_345::7\"\nconsole.log(euro.format(-12345.678, { decimals: 1, thousands: \"_\", decimal: \"::\" }));\n\n// prints \"(€ 12 345,68)\"\nconsole.log(euro.format(-12345.678, { negative: \"paren\" }));\n\n// prints -12345.678\nconsole.log(euro.unformat(\"(€ 12 345,68)\", { negative: \"paren\" }));\n```\n\n### Options\n\nWhen creating a ziffer formatter you can pass any of these options in an optional object. These will be the defaults to subsequent `.format()` calls. You can also set an individual option in a specific call by passing a second options argument as seen above.\n\n**List of Options**\n\n- `decimal`: separator between integer and fraction (default: comma)\n- `thousands`: separator between integer groups (default: space)\n- `outprefix`: string prefix (default: none)\n- `inprefix`: string prefix (default: none)\n- `insuffix`: string suffix (default: none)\n- `outsuffix`: string suffix (default: none)\n- `negative`: how negative values are expressed - \"left\", \"right\" or parenthesis (default: left)\n- `group`: size of digit groups separated by `thousands` (default: 3)\n- `group_except`: exception for digit grouping (default: 4)\n- `decimals`: number of decimals in fraction to round to (default: no rounding)\n- `digits`: a string with 10 digits from 0 to 9 (default: empty, which means 0-9)\n\nThe reason there's an `in` and `out` prefix and suffix is because of how negative values are formatted. The negative characters (minus or parenthesis) are placed in between, which leaves you the opportunity to format any way you like.\n\nHere's a weird example:\n\n```js\nconst ziffer = require(\"ziffer\");\nconst euro   = ziffer({\n    outprefix : \"\u003c\",\n    inprefix  : \"[\",\n    insuffix  : \"]\",\n    outsuffix : \"\u003e\",\n    negative  : \"paren\"\n});\n\n// prints \u003c([123])\u003e\nconsole.log(euro.format(-123));\n// notice how parenthesis are place in between\n```\n\n### Advanced\n\n#### Group\n\nInteger digit grouping can also be configured using a list of group sizes instead of a single number. This allows, for example, to group digits the way Hindi do.\n\n```js\nconst ziffer = require(\"ziffer\");\nconst hindi  = ziffer({\n    decimal   : \".\",\n    thousands : \",\",\n    group     : [ 3, 2 ],\n    decimals  : 2\n});\n\n// prints 12,34,56,789.00\nconsole.log(hindi.format(123456789));\n```\n\n#### Digits\n\nFor example, converting numbers to Arabic numeral can be done like the following:\n\n```js\nconst ziffer = require(\"ziffer\");\nconst arab   = ziffer({\n    digits : \"٠١٢٣٤٥٦٧٨٩\"\n});\n\n// prints ١٥٩\nconsole.log(arab.format(159));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdresende%2Fnode-ziffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdresende%2Fnode-ziffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdresende%2Fnode-ziffer/lists"}