{"_id":"moment-duration-format-commonjs","_rev":"18-a6428c47dbfa0460e3f113a9caa30804","name":"moment-duration-format-commonjs","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"moment-duration-format-commonjs","version":"1.0.0","keywords":["moment","duration","format"],"author":{"name":"John Madhavan-Reese","email":"jsmreese@gmail.com"},"license":"MIT","_id":"moment-duration-format-commonjs@1.0.0","maintainers":[{"name":"belym.a.2105","email":"belym.a.2105@gmail.com"}],"contributors":[{"name":"Andrey Belym","email":"belym.a.2105@gmail.com"}],"homepage":"http://github.com/AndreyBelym/moment-duration-format-commonjs","bugs":{"url":"https://github.com/AndreyBelym/moment-duration-format-commonjs/issues"},"dist":{"shasum":"dc5de612e6d6ff41f774d03772a139a363563bc3","tarball":"https://registry.npmjs.org/moment-duration-format-commonjs/-/moment-duration-format-commonjs-1.0.0.tgz","fileCount":10,"integrity":"sha512-MVFR4hIh4jfuwSCPBEE5CCwn3refvTsxK/Yv/DpKJ6YcNnCimlVJ6DQeTJG1KVQPw1o8m3tkbHE9gVjivyv9iA==","signatures":[{"sig":"MEQCICwnl7SLDnqJb1vFgRjx/woG+0cksFxKdEJlDIVX0saGAiBofCyFbIWy8VYpS5s7LUjo8BfksFX5ImuNvs9cnpZN5Q==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":693244,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbkTw9CRA9TVsSAnZWagAAHR4P/Rf+uptmxJwiHs39Y0UZ\nKDZ5aphjNYG1eQvuY90eC0/IREH84qG7hFsKnABl7zX9JXnHjsOrm+4wckvE\nCly0ioO0rRQbDywXmpQsplci0O1rcovDsQ2YjNRRkA9Rb2aEt/ytgAYazuSQ\ngnKfyS4f2H6gF65rbffrFaOtUV4RqP5r17vVB83oEUbxsv2KZLU9z80wWTK9\nLdSjEMNYCFjxPmgP9PRPN3VlR0RzayRKfnU2Pklx6roOdtBJ8OMoJu+W0Cef\nd5BwkAGvAgQ+xACo5rVxTpWUl/GoC6gAYYISCX8GiNaY1D6SXEgJ2gY2LCLI\nrazxu+QWPLzT5/6HSSFeljrWTL9cVvTCXIb+keJ8C8swYNbMQvqjxSkA9mwy\nA3nK3H5oGOD8whnKsLPttUxppOgb5UJSVdba0NqwnoKpUqYyNzG05rp2LaMr\nib/SlRqbvIL7BPpDSuYjUmeLGoFp7MN0FJ7gWdRElxCnQvnXTTwQcB8FV/3s\nOezBwtytyX9sTNopbVZC1iu+Ay4MvXMtBA5u6m+5h8HkA0Pp4YcZA9uAMSxu\nG8fxpIFP536D8nGlHtBuflbTwIzJwi1k8dVxTvCZXHthndLE/vRILaUtN3J8\nZr4yulzv6XgYeHENzUquETUdoMwRarmjES5L5J+8hVWtdsVi643QTvDrngwL\nAgEQ\r\n=Z7Wo\r\n-----END PGP SIGNATURE-----\r\n"},"main":"lib/moment-duration-format.js","gitHead":"6f6e29f0fc221c3949d9cf7fc224af5ecfe5489e","_npmUser":{"name":"belym.a.2105","email":"belym.a.2105@gmail.com"},"repository":{"url":"git://github.com/AndreyBelym/moment-duration-format-commonjs.git","type":"git"},"_npmVersion":"5.6.0","description":"A moment.js plugin for formatting durations.","directories":{},"_nodeVersion":"8.11.3","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/moment-duration-format-commonjs_1.0.0_1536244796925_0.6368129033261041","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"moment-duration-format-commonjs","version":"1.0.1","keywords":["moment","duration","format"],"author":{"name":"John Madhavan-Reese","email":"jsmreese@gmail.com"},"license":"MIT","_id":"moment-duration-format-commonjs@1.0.1","maintainers":[{"name":"belym.a.2105","email":"belym.a.2105@gmail.com"}],"contributors":[{"name":"Andrey Belym","email":"belym.a.2105@gmail.com"}],"homepage":"http://github.com/DevExpress/moment-duration-format-commonjs","bugs":{"url":"https://github.com/DevExpress/moment-duration-format-commonjs/issues"},"dist":{"shasum":"ca8776466dba736a30cb7cda4e07026b5aec8cf1","tarball":"https://registry.npmjs.org/moment-duration-format-commonjs/-/moment-duration-format-commonjs-1.0.1.tgz","fileCount":4,"integrity":"sha512-KhKZRH21/+ihNRWrmdNFOyBptFi7nAWZFeFsRRpXkzgk/Yublb4fxyP0jU6EY1VDxUL/VUPdCmm/wAnpbfXdfw==","signatures":[{"sig":"MEQCIDH+n8SHnmC5eJhRLrfd4l/rivh03HTBjiGAl6Tot25hAiAQ7iQIZjiqyYcIvKnAhC99KmOmCAS0mElABhL7/mlwPA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":93357,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg1eGpCRA9TVsSAnZWagAAM8gP/jIv+mgOSb27EJBbCIeB\n+gZASVHRQTSdgrTZb/JvMuZVbHpJMdbttJb+ou/k8Iz5uN5NzyhiBEZ/Iogn\nyNwGPqPbHgI9O93knnAfj5rmqITCF3SjVr4+DR6LQeBRDNx5Rb21TqMygTiT\nRPcpIBwMbS9PBY76bbRL55Ktig3XzdJWrj44SxUvIWKW9kJV+bsfRYFN8Wxq\nawn2wxO3NoDJpzOjwFA4hqRhvD8EqGdKZ7FLR/Fsf33msMC3Uabk7jp1mBQN\nYuXY5DSKxeeDcbCFKe3Enjb5mOo53wHSqwBl11oF6/xAsxhDMxsgldD6BGfl\nP3xO3BA2lCGE/38S3TY4O03oDOK1gTQi0uJgbRGYfZwKcsl8nfidi3qD054Q\nhE83yyjHqwUJOgKM2Ku2FI5FBgE8tzKv9ogDtKKK4RTIt5D8SRsat26dPlcM\nhXnOzsjZZf48Od2DtNnhAw5LwggUs7SBUjaaxQO5vg1Tg4lJ8qgUO+TpeNw1\n3vHTDUaoouRgNVd0MmCBQVP0uZZc+J904RqTipqO2JpEN9LXRYJajFHoO9TA\nF8aNpDNNWG3vpfnVJKFytzOsv7BbxcD87adgHeG2KfsxPbyVgWkvefzSctrR\nMxfpJtMWpzFJEgv6224hBRfEonxmh4LwjhnHZCj03J7+YeKN9REqOhNe2SIK\nvLCL\r\n=Aojz\r\n-----END PGP SIGNATURE-----\r\n"},"main":"lib/moment-duration-format.js","gitHead":"12250d8ccf5dedbf61e3d5b4f5e856225002c6b0","scripts":{"test":"mocha test"},"_npmUser":{"name":"belym.a.2105","email":"belym.a.2105@gmail.com"},"repository":{"url":"git://github.com/DevExpress/moment-duration-format-commonjs.git","type":"git"},"_npmVersion":"7.18.1","description":"A moment.js plugin for formatting durations.","directories":{},"_nodeVersion":"16.4.0","_hasShrinkwrap":false,"devDependencies":{"mocha":"^9.0.1","moment":"^2.29.1"},"_npmOperationalInternal":{"tmp":"tmp/moment-duration-format-commonjs_1.0.1_1624629672543_0.4720652849095741","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-09-06T14:39:56.924Z","modified":"2025-12-03T13:14:09.343Z","1.0.0":"2018-09-06T14:39:57.158Z","1.0.1":"2021-06-25T14:01:12.725Z"},"bugs":{"url":"https://github.com/DevExpress/moment-duration-format-commonjs/issues"},"author":{"name":"John Madhavan-Reese","email":"jsmreese@gmail.com"},"license":"MIT","homepage":"http://github.com/DevExpress/moment-duration-format-commonjs","keywords":["moment","duration","format"],"repository":{"url":"git://github.com/DevExpress/moment-duration-format-commonjs.git","type":"git"},"description":"A moment.js plugin for formatting durations.","contributors":[{"name":"Andrey Belym","email":"belym.a.2105@gmail.com"}],"maintainers":[{"email":"boris.s.kirov@gmail.com","name":"kirovboris"},{"email":"romanresh@live.com","name":"romanresh"},{"email":"belym.a.2105@gmail.com","name":"belym.a.2105"}],"readme":"# Moment Duration Format CommonJS\n### CommonJS (Node.js) specific version\n\n**Format plugin for the Moment Duration object.**\n\nThis is a plugin to the Moment.js JavaScript date library to add comprehensive formatting to Moment Durations.\n\nFormat template grammar is patterned on the existing Moment Date format template grammar, with a few modifications because durations are fundamentally different from dates.\n\nThis plugin does not have any dependencies beyond Moment.js itself, and may be used in the browser and in Node.js.\n\n---\n\n## Formatting Numbers and Testing\n\nWhere it is available and functional, this plugin uses `Number#toLocaleString` to render formatted numerical output. Unfortunately, many environments do not fully implement the full suite of options in the `toLocaleString` spec, and some provide a buggy implementation.\n\nThis plugin runs a feature test for `toLocaleString`, and will revert to a fallback function to render formatted numerical output if the feature test fails. To force this plugin to always use the fallback number format function, set `useToLocaleString` to `false`. The fallback number format function output can be localized using options detailed at the bottom of this page. You should, in general, specify the fallback number formatting options if the default `\"en\"` locale formatting would be unacceptable on some devices or in some environments.\n\n---\n\n## Installation\n\nThe plugin depends on moment.js, which is not specified as a package dependency in the currently published version.\n\n**Node.js**\n\n`npm install moment-duration-format-commonjs`\n\n---\n\n## Usage\n\nTo use this plugin as a module, use the `require` function.\n\n```javascript\nvar moment = require(\"moment\");\nvar momentDurationFormatSetup = require(\"moment-duration-format\");\n```\n\nThe plugin exports the init function so that duration format can be initialized on other moment instances.\n\nCall the exported setup function to install the plugin into the desired package.\n\n```javascript\nvar moment = require(\"moment-timezone\");\nvar momentDurationFormatSetup = require(\"moment-duration-format\");\n\nmomentDurationFormatSetup(moment);\ntypeof moment.duration.fn.format === \"function\";\n// true\ntypeof moment.duration.format === \"function\";\n// true\n```\n\n### Basics\n\n#### Formatting a Single Duration\n\n```javascript\nmoment.duration.fn.format\n```\n\nThe `duration.fn.format` method can format any moment duration. If no template or other arguments are provided, the default template function will generate a template string based on the duration's value.\n\n```javascript\nmoment.duration(123, \"minutes\").format();\n// \"2:03:00\"\n\nmoment.duration(123, \"months\").format();\n// \"10 years, 3 months\"\n```\n\nThe duration format method may be called with three optional arguments, and returns a formatted string.\n\n```javascript\nmoment.duration(value, units).format([template] [, precision] [, settings])\n// formattedString\n```\n\n#### Formatting Multiple Durations\n\n```javascript\nmoment.duration.format\n```\n\nThe `duration.format` method allows coordinated formatting of multiple moment durations at once. This function accepts an array of durations as its first argument, then the same three optional arguments as the `duration.fn.format` function. This function returns an array of formatted strings.\n\n```javascript\nmoment.duration.format(durationsArray, [template] [, precision] [, settings]);\n// formattedStringsArray\n```\n\nAll of the options that are available to the single duration format function can be used with the multiple duration format function. A single settings object is used to format each of the individual durations.\n\n```javascript\nmoment.duration.format([\n    moment.duration(1, \"second\"),\n    moment.duration(1, \"minute\"),\n    moment.duration(1, \"hour\")\n], \"d [days] hh:mm:ss\");\n// [\"0:00:01\", \"0:01:00\", \"1:00:00\"]\n```\n\n##### Invalid Durations\n\nInvalid durations are treated as having a value of `0` for formatting.\n\n```javascript\nvar invalidDuration = moment.duration(NaN, \"second\");\n\ninvalidDuration.isValid();\n// false\n\ninvalidDuration.format();\n// \"0 seconds\"\n```\n\n### Template\n\n`template` (string|function) is the string used to create the formatted output, or a function that returns the string to be used as the format template.\n\n#### Template String\n\n```javascript\nmoment.duration(123, \"minutes\").format(\"h:mm\");\n// \"2:03\"\n```\n\nThe template string is parsed for moment token characters, which are replaced with the duration's value for each unit type. The moment tokens are:\n\n```\nyears:   Y or y\nmonths:  M\nweeks:   W or w\ndays:    D or d\nhours:   H or h\nminutes: m\nseconds: s\nms:      S\n```\n\nEscape token characters within the template string using square brackets.\n```javascript\nmoment.duration(123, \"minutes\").format(\"h [hrs], m [min]\");\n// \"2 hrs, 3 mins\"\n```\n\n#### Token Length\n\nFor some time duration formats, a zero-padded value is required. Use multiple token  characters together to create the correct amount of padding.\n\n```javascript\nmoment.duration(3661, \"seconds\").format(\"h:mm:ss\");\n// \"1:01:01\"\n\nmoment.duration(15, \"seconds\").format(\"sss [s]\");\n// \"015 s\"\n```\n\nWhen the format template is trimmed, token length on the largest-magnitude rendered token can be trimmed as well. See sections **trim** and **forceLength** below for more details.\n\n```javascript\nmoment.duration(123, \"seconds\").format(\"h:mm:ss\");\n// \"2:03\"\n```\n\n##### Milliseconds Token Length\n\nToken length of `2` for milliseconds is a special case, most likely used to render milliseconds as part of a timer output, such as `mm:ss:SS`. In this case, the milliseconds value is padded to three digits then truncated from the left to render a two digit output.\n\n```javascript\nmoment.duration(9, \"milliseconds\").format(\"mm:ss:SS\", {\n    trim: false\n});\n// \"00:00:00\"\n\nmoment.duration(10, \"milliseconds\").format(\"mm:ss:SS\", {\n    trim: false\n});\n// \"00:00:01\"\n\nmoment.duration(999, \"milliseconds\").format(\"mm:ss:SS\", {\n    trim: false\n});\n// \"00:00:99\"\n\nmoment.duration(1011, \"milliseconds\").format(\"mm:ss:SS\", {\n    trim: false\n});\n// \"00:01:01\"\n```\n\n#### Multiple Token Instances\n\nTokens can appear multiple times in the format template, but all instances must share the same length. If they do not, all instances will be rendered at the length of the first token of that type.\n\n```javascript\nmoment.duration(15, \"seconds\").format(\"ssss sss ss s\");\n// \"0015 0015 0015 0015\"\n\nmoment.duration(15, \"seconds\").format(\"s ss sss ssss\");\n// \"15 15 15 15\"\n```\n\n#### Default Template Function\n\nThe default template function attempts to format a duration based on its magnitude. The larger the duration value, the larger the units of the formatted output will be.\n\nFor some duration values, the default template function will default `trim` to `\"both\"` if that option is not set in the settings object (more on that below).\n\nThe default template function uses auto-localized unit labels (more on that below, also).\n\n```javascript\nmoment.duration(100, \"milliseconds\").format();\n// \"100 milliseconds\"\n\nmoment.duration(100, \"seconds\").format();\n// \"1:40\"\n\nmoment.duration(100, \"days\").format();\n// \"3 months, 9 days\"\n\nmoment.duration(100, \"weeks\").format();\n// \"1 year, 10 months, 30 days\"\n\nmoment.duration(100, \"months\").format();\n// \"8 years, 4 months\"\n```\n\n#### Custom Template Function\n\nUse a custom template function if you need runtime control over the template string. Template functions are executed with a `this` binding of the settings object, and have access to the underlying duration object via `this.duration`. Any of the settings may be accessed or modified by the template function.\n\nThis custom template function uses a different template based on the value of the duration:\n\n```javascript\nfunction customTemplate() {\n    return this.duration.asSeconds() >= 86400 ? \"w [weeks], d [days]\" : \"hh:mm:ss\";\n}\n\nmoment.duration(65, 'seconds').format(customTemplate, {\n    trim: false\n});\n// \"00:01:05\"\n\nmoment.duration(1347840, 'seconds').format(customTemplate, {\n    trim: false\n});\n// \"2 weeks, 2 days\"\n```\n\n#### Punctuation Trimming\n\nTo ensure user-friendly formatted output, punctuation characters are trimmed from the beginning and end of the formatted output. Specifically, leading and trailing period `.`, comma `,`, colon `:`, and space ` ` characters are removed.\n\n### Precision\n\n`precision` (number) defines the number of decimal fraction or integer digits to display for the final value.\n\nThe default precision value is `0`.\n\n```javascript\nmoment.duration(123, \"minutes\").format(\"h [hrs]\");\n// \"2 hrs\"\n```\n\nPositive precision defines the number of decimal fraction digits to display.\n```javascript\nmoment.duration(123, \"minutes\").format(\"h [hrs]\", 2);\n// \"2.05 hrs\"\n```\n\nNegative precision defines the number of integer digits to truncate to zero.\n```javascript\nmoment.duration(223, \"minutes\").format(\"m [min]\", -2);\n// \"200 mins\"\n```\n\n### Settings\n\n`settings` is an object that can override any of the default moment duration format options.\n\nBoth the `template` and `precision` arguments may be specified as properties of a single `settings` object argument, or they may be passed separately along with an optional settings object.\n\n```javascript\nmoment.duration(123, \"minutes\").format({\n    template: \"h [hrs]\",\n    precision: 2\n});\n// \"2.05 hrs\"\n```\n\n#### trim\n\nThe default `trim` behaviour is `\"large\"`.\n\nLargest-magnitude tokens are automatically trimmed when they have no value.\n```javascript\nmoment.duration(123, \"minutes\").format(\"d[d] h:mm:ss\");\n// \"2:03:00\"\n```\n\nTrimming also functions when the format string is oriented with token magnitude increasing from left to right.\n```javascript\nmoment.duration(123, \"minutes\").format(\"s [seconds], m [minutes], h [hours], d [days]\");\n// \"0 seconds, 3 minutes, 2 hours\"\n```\n\nTo stop trimming altogether, set `{ trim: false }`.\n```javascript\nmoment.duration(123, \"minutes\").format(\"d[d] h:mm:ss\", {\n    trim: false\n});\n// \"0d 2:03:00\"\n```\n\nWhen formatting multiple durations using `moment.duration.format`, trimming for all of the durations is coordinated on the union of the set of durations.\n\n```javascript\nmoment.duration.format([\n    moment.duration(1, \"minute\"),\n    moment.duration(1, \"hour\"),\n    moment.duration(1, \"day\")\n], \"y [years], w [weeks], d [days], h [hours], m [minutes]\");\n// [\n//    \"0 days, 0 hours, 1 minute\",\n//    \"0 days, 1 hour, 0 minutes\",\n//    \"1 day, 0 hours, 0 minutes\"\n// ]\n```\n\n`trim` can be a string, a delimited list of strings, an array of strings, or a boolean. Accepted values are as follows:\n\n- ##### `\"large\"`\n\nTrim largest-magnitude zero-value tokens until finding a token with a value, a token identified as `stopTrim`, or the final token of the format string. This is the default `trim` value.\n\n```javascript\nmoment.duration(123, \"minutes\").format(\"d[d] h:mm:ss\");\n// \"2:03:00\"\n\nmoment.duration(123, \"minutes\").format(\"d[d] h:mm:ss\", {\n    trim: \"large\"\n});\n// \"2:03:00\"\n\nmoment.duration(0, \"minutes\").format(\"d[d] h:mm:ss\", {\n    trim: \"large\"\n});\n// \"0\"\n```\n\n- ##### `\"small\"`\n\nTrim smallest-magnitude zero-value tokens until finding a token with a value, a token identified as `stopTrim`, or the final token of the format string.\n\n```javascript\nmoment.duration(123, \"minutes\").format(\"d[d] h:mm:ss\", {\n    trim: \"small\"\n});\n// \"0d 2:03\"\n\nmoment.duration(0, \"minutes\").format(\"d[d] h:mm:ss\", {\n    trim: \"small\"\n});\n// \"0d\"\n```\n\n- ##### `\"both\"`\n\nExecute `\"large\"` trim then `\"small\"` trim.\n\n```javascript\nmoment.duration(123, \"minutes\").format(\"d[d] h[h] m[m] s[s]\", {\n    trim: \"both\"\n});\n// \"2h 3m\"\n\nmoment.duration(0, \"minutes\").format(\"d[d] h[h] m[m] s[s]\", {\n    trim: \"both\"\n});\n// \"0s\"\n```\n\n- ##### `\"mid\"`\n\nTrim any zero-value tokens that are not the first or last tokens. Usually used in conjunction with `\"large\"` or `\"both\"`. e.g. `\"large mid\"` or `\"both mid\"`.\n\n```javascript\nmoment.duration(1441, \"minutes\").format(\"w[w] d[d] h[h] m[m] s[s]\", {\n    trim: \"mid\"\n});\n// \"0w 1d 1m 0s\"\n\nmoment.duration(1441, \"minutes\").format(\"w[w] d[d] h[h] m[m] s[s]\", {\n    trim: \"large mid\"\n});\n// \"1d 1m 0s\"\n\nmoment.duration(1441, \"minutes\").format(\"w[w] d[d] h[h] m[m] s[s]\", {\n    trim: \"small mid\"\n});\n// \"0w 1d 1m\"\n\nmoment.duration(1441, \"minutes\").format(\"w[w] d[d] h[h] m[m] s[s]\", {\n    trim: \"both mid\"\n});\n// \"1d 1m\"\n\nmoment.duration(0, \"minutes\").format(\"w[w] d[d] h[h] m[m] s[s]\", {\n    trim: \"both mid\"\n});\n// \"0s\"\n```\n\n- ##### `\"final\"`\n\nTrim the final token if it is zero-value. Use this option with `\"large\"` or `\"both\"` to output an empty string when formatting a zero-value duration. e.g. `\"large final\"` or `\"both final\"`.\n\n```javascript\nmoment.duration(0, \"minutes\").format(\"d[d] h:mm:ss\", {\n    trim: \"large final\"\n});\n// \"\"\n\nmoment.duration(0, \"minutes\").format(\"d[d] h:mm:ss\", {\n    trim: \"small final\"\n});\n// \"\"\n\nmoment.duration(0, \"minutes\").format(\"d[d] h[h] m[m] s[s]\", {\n    trim: \"both final\"\n});\n// \"\"\n```\n\n- ##### `\"all\"`\n\nTrim all zero-value tokens. Shorthand for `\"both mid final\"`.\n\n```javascript\nmoment.duration(0, \"minutes\").format(\"d[d] h[h] m[m] s[s]\", {\n    trim: \"all\"\n});\n// \"\"\n```\n\n- ##### `\"left\"`\n\nMaps to `\"large\"` to support this plugin's version 1 API.\n\n- ##### `\"right\"`\n\nMaps to `\"large\"` to support this plugin's version 1 API.\n\n- ##### `true`\n\nMaps to `\"large\"`.\n\n- ##### `null`\n\nMaps to `\"large\"`.\n\n- ##### `false`\n\nDisables trimming.\n\n#### largest\n\nSet `largest` to a positive integer to output only the `n` largest-magnitude moment tokens, starting with the largest-magnitude token that has a value.\n\n**Using the `largest` option defaults `trim` to `\"all\"`.**\n\n```javascript\nmoment.duration(7322, \"seconds\").format(\"d [days], h [hours], m [minutes], s [seconds]\", {\n    largest: 2\n});\n// \"2 hours, 2 minutes\"\n\nmoment.duration(1216800, \"seconds\").format(\"y [years], w [weeks], d [days], h [hours], m [minutes], s [seconds]\", {\n    largest: 3\n});\n// \"2 weeks, 2 hours\"\n```\n\nSetting `trim` to a different value, or using `stopTrim` can change the starting token as well as the remaining output.\n\n```javascript\nmoment.duration(1216800, \"seconds\").format(\"y [years], w [weeks], d [days], h [hours], m [minutes], s [seconds]\", {\n    largest: 3,\n    trim: \"both\"\n});\n// \"2 weeks, 0 days, 2 hours\"\n\nmoment.duration(1216800, \"seconds\").format(\"y [years], w [weeks], d [days], h [hours], m [minutes], s [seconds]\", {\n    largest: 3,\n    trim: \"both\",\n    stopTrim: \"m\"\n});\n// \"2 weeks, 0 days, 2 hours\"\n\nmoment.duration(1216800, \"seconds\").format(\"y [years], w [weeks], d [days], h [hours], m [minutes], s [seconds]\", {\n    largest: 4,\n    trim: false\n});\n// \"2 weeks, 0 days, 2 hours, 0 minutes\"\n\nmoment.duration(2, \"hours\").format(\"y [years], d [days], h [hours], m [minutes], s [seconds]\", {\n    trim: \"both\",\n    stopTrim: \"d m\",\n    largest: 2\n});\n// \"0 days 2 hours\"\n```\n\n#### stopTrim\n\nTrimming will stop when a token listed in this option is reached.\n\nOption value may be a moment token string, a delimited set of moment token strings, or an array of moment token strings. Alternatively, set `stopTrim` on tokens in the format template string directly using a `*` character before the moment token.\n\n```javascript\nmoment.duration(23, \"minutes\").format(\"d[d] h:mm:ss\", {\n    stopTrim: \"h\"\n});\n// \"0:23:00\"\n\nmoment.duration(23, \"minutes\").format(\"d[d] *h:mm:ss\");\n// \"0:23:00\"\n```\n\nThis option affects all trimming modes: `\"large\"`, `\"small\"`, `\"mid\"`, and `\"final\"`.\n\n```javascript\nmoment.duration(2, \"hours\").format(\"y [years], d [days], h [hours], m [minutes], s [seconds]\", {\n    trim: \"both\",\n    stopTrim: \"d m\"\n});\n// \"0 days, 2 hours, 0 minutes\"\n\nmoment.duration(2, \"hours\").format(\"y [years], *d [days], h [hours], *m [minutes], s [seconds]\", {\n    trim: \"both\"\n});\n// \"0 days, 2 hours, 0 minutes\"\n```\n\n#### trunc\n\nDefault behavior rounds the final token value.\n\n```javascript\nmoment.duration(179, \"seconds\").format(\"m [minutes]\");\n// \"3 minutes\"\n\nmoment.duration(3780, \"seconds\").format(\"h [hours]\", 1);\n// \"1.1 hours\"\n```\n\nSet `trunc` to `true` to truncate final token value. This was the default behavior in version 1 of this plugin.\n\n```javascript\nmoment.duration(179, \"seconds\").format(\"m [minutes]\", {\n    trunc: true\n});\n// \"2 minutes\"\n\nmoment.duration(3780, \"seconds\").format(\"h [hours]\", 1, {\n    trunc: true\n});\n// \"1.0 hours\"\n```\n\nUsing `trunc` can affect the operation of `trim` and `largest`.\n\n```javascript\nmoment.duration(59, \"seconds\").format(\"d [days], h [hours], m [minutes]\", {\n    trunc: true,\n    trim: \"both\"\n});\n// \"0 minutes\"\n\nmoment.duration(59, \"seconds\").format(\"d [days], h [hours], m [minutes]\", {\n    trunc: true,\n    trim: \"all\"\n});\n// \"\"\n\nmoment.duration(59, \"seconds\").format(\"d [days], h [hours], m [minutes]\", {\n    trunc: true,\n    largest: 1\n});\n// \"\"\n```\n\n#### minValue\n\nUse `minValue` to render generalized output for small duration values, e.g. `\"< 5 minutes\"`. `minValue` must be a positive number and is applied to the least-magnitude moment token in the format template.\n\n```javascript\nmoment.duration(59, \"seconds\").format(\"h [hours], m [minutes]\", {\n    minValue: 1\n});\n// \"< 1 minute\"\n```\n\nThe minimum value will bubble up to larger-magnitude units if they are present in the format template.\n\n```javascript\nmoment.duration(59, \"seconds\").format(\"m:ss\", {\n    minValue: 60\n});\n// \"< 1:00\"\n```\n\nThis option can be used in conjunction with `trim`, and is not affected by `trunc`.\n\n``` javascript\nmoment.duration(59, \"seconds\").format(\"h [hours], m [minutes]\", {\n    minValue: 1,\n    trim: \"both\"\n});\n// \"< 1 minute\"\n\nmoment.duration(59, \"seconds\").format(\"h [hours], m [minutes]\", {\n    minValue: 1,\n    trunc: true,\n    trim: \"both\"\n});\n// \"< 1 minute\"\n\nmoment.duration(59, \"seconds\").format(\"h [hours], m [minutes]\", {\n    minValue: 1,\n    trim: false\n});\n// \"< 0 hours, 1 minute\"\n```\n\n`minValue` can be used with negative durations, where it has the same effect on the least-magnitude moment token's absolute value.\n\n```javascript\nmoment.duration(-59, \"seconds\").format(\"h [hours], m [minutes]\", {\n    minValue: 1\n});\n// \"> -1 minute\"\n```\n\nIf `minValue` is a non-integer number, `precision` should be set as well so that the formatted output makes sense.\n\n```javascript\nmoment.duration(89, \"seconds\").format(\"m\", {\n    minValue: 1.5,\n    precision: 1\n});\n// \"< 1.5\"\n\nmoment.duration(90, \"seconds\").format(\"m\", {\n    minValue: 1.5,\n    precision: 1\n});\n// \"1.5\"\n```\n\n#### maxValue\n\nUse `maxValue` to render generalized output for large duration values, e.g. `\"> 60 days\"`. `maxValue` must be a positive number and is applied to the greatest-magnitude moment token in the format template. As with `minValue`, this option can be used in conjunction with `trim`, is not affected by `trunc`, and can be used with negative durations.\n\n**Using the `maxValue` option defaults `trim` to `\"all\"`.**\n\n```javascript\nmoment.duration(15, \"days\").format(\"w [weeks]\", {\n    maxValue: 2\n});\n// \"> 2 weeks\"\n\nmoment.duration(-15, \"days\").format(\"w [weeks]]\", {\n    maxValue: 2\n});\n// \"< -2 weeks\"\n```\n\n`maxValue` can be used with `trim` and `largest`, but when the maximum value is reached, all lesser-magnitude token values are forced to `0`.\n\n```javascript\nmoment.duration(15.5, \"days\").format(\"w [weeks], d [days], h [hours]\", {\n    maxValue: 2,\n    trim: false,\n    largest: 2\n});\n// \"> 2 weeks, 0 days\"\n```\n\nIf `maxValue` is a non-integer number, `precision` should be set as well so that the formatted output makes sense.\n\n```javascript\nmoment.duration(89, \"seconds\").format(\"m\", {\n    minValue: 1.5,\n    precision: 1\n});\n// \"< 1.5\"\n\nmoment.duration(90, \"seconds\").format(\"m\", {\n    minValue: 1.5,\n    precision: 1\n});\n// \"1.5\"\n```\n\n#### forceLength\n\nForce the first moment token with a value to render at full length, even when the template is trimmed and the first moment token has a length of `1`. Sounds more complicated than it is.\n\n```javascript\nmoment.duration(123, \"seconds\").format(\"h:mm:ss\");\n// \"2:03\"\n```\n\nIf you want minutes to always be rendered with two digits, you can use a first token with a length greater than 1 (this stops the automatic token length trimming for the first token that has a value).\n\n```javascript\nmoment.duration(123, \"seconds\").format(\"hh:mm:ss\");\n// \"02:03\"\n```\n\nOr you can use `{ forceLength: true }`.\n\n```javascript\nmoment.duration(123, \"seconds\").format(\"h:mm:ss\", {\n    forceLength: true\n});\n// \"02:03\"\n```\n\n#### useSignificantDigits\n\nWhen `useSignificantDigits` is set to `true`, the `precision` option determines the maximum significant digits to be rendered. Precision must be a positive integer. Significant digits extend across unit types, e.g. `\"6 hours 37.5 minutes\"` represents `4` significant digits. Enabling this option causes token length to be ignored.\n\n**Using the `useSignificantDigits` option defaults `trim` to `\"all\"`.**\n\nSetting `trunc` affects the operation of `useSignificantDigits`.\n\nSee the documentation for [toLocaleString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) for more information on significant digits.\n\n```javascript\nmoment.duration(99999, \"seconds\").format(\"d [days], h [hours], m [minutes], s [seconds]\", {\n    useSignificantDigits: true,\n    precision: 3\n});\n// \"1 day, 3 hours, 50 minutes\"\n\nmoment.duration(99999, \"seconds\").format(\"d [days], h [hours], m [minutes], s [seconds]\", {\n    useSignificantDigits: true,\n    precision: 3,\n    trunc: true\n});\n// \"1 day, 3 hours, 40 minutes\"\n\nmoment.duration(99999, \"seconds\").format(\"d [days], h [hours], m [minutes], s [seconds]\", {\n    useSignificantDigits: true,\n    precision: 5\n});\n// \"1 day, 3 hours, 46 minutes, 40 seconds\"\n\nmoment.duration(99999, \"seconds\").format(\"d [days], h [hours], m [minutes], s [seconds]\", {\n    useSignificantDigits: true,\n    trunc: true,\n    precision: 5\n});\n// \"1 day, 3 hours, 46 minutes, 30 seconds\"\n\nmoment.duration(99999, \"seconds\").format(\"d [days], h [hours], m [minutes], s [seconds]\", {\n    useSignificantDigits: true,\n    precision: 6\n});\n// \"1 day, 3 hours, 46 minutes, 39 seconds\"\n```\n\n`useSignificantDigits` can be used together with `trim`.\n\n```javascript\nmoment.duration(12.55, \"hours\").format(\"h:mm\", {\n    precision: 2,\n    useSignificantDigits: true,\n    trim: false\n});\n// \"13:00\"\n\nmoment.duration(12.55, \"hours\").format(\"h:mm\", {\n    precision: 2,\n    useSignificantDigits: true,\n    trim: false,\n    trunc: true\n});\n// \"12:00\"\n```\n\n### Localization\n\nFormatted numerical output is rendered using [`toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) if that built-in function is available and passes a feature test on plugin initialization. If the feature test fails, a fallback format function is used. See below for details on localizing output from the fallback format function.\n\nUnit labels are automatically localized and pluralized. Unit labels are detected using the [locale set in moment.js](https://momentjs.com/docs/#/i18n/), which can be different from the locale of user's environment. This plugin uses custom extensions to the moment.js locale object, which can be easily added for any locale (see below).\n\nIt's likely that the options below do not address every i18n requirement for duration formatting (the plugin hasn't been tested on languages that are written from right to left, for instance), but they are a significant step in the right direction and support languages with [multiple forms of plural](https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals)).\n\n#### userLocale\n\nNumerical output is rendered using the locale set in moment.js, retrieved via `moment.locale()`. Set the `userLocale` option to render numerical output using a different locale.\n\n```javascript\nmoment.duration(1234567, \"seconds\").format(\"m [minutes]\", 3);\n// \"20,576.117 minutes\"\n\nmoment.duration(1234567, \"seconds\").format(\"m [minutes]\", 3, {\n    userLocale: \"de-DE\"\n});\n// \"20.576,117 minutes\"\n```\n\n#### Auto-Localized Unit Labels\n\nThe `_` character can be used to generate auto-localized unit labels in the formatted output.\n\nA single underscore `_` will be replaced with the short duration unit label for its associated moment token.\n\nA double underscore `__` will be replaced with the standard duration unit label for its associated moment token.\n\n```javascript\nmoment.duration(2, \"minutes\").format(\"m _\");\n// \"2 mins\"\n\nmoment.duration(2, \"minutes\").format(\"m __\");\n// \"2 minutes\"\n```\n\nThese are the default `\"en\"` locale options for unit labels. Unit label types and even the `\"_\"` character usage can be customized in the locale object extensions (see below).\n\n#### Auto-Localized Time Notation\n\nDurations can also be formatted with a localized time notation.\n\nThe string `_HMS_` is replaced with a localized `hour/minute/second` time notation, e.g. `h:mm:ss`.\n\nThe string `_HM_` is replaced with a localized `hour/minute` time notation, e.g. `h:mm`.\n\nThe string `_MS_` is replaced with a localized `minute/second` time notation, e.g. `m:ss`.\n\n```javascript\nmoment.duration(3661, \"seconds\").format(\"_HMS_\");\n// \"1:01:01\"\n\nmoment.duration(3661, \"seconds\").format(\"_HM_\");\n// \"1:01\"\n\nmoment.duration(61, \"seconds\").format(\"_MS_\");\n// \"1:01\"\n```\n\nThese are the default `\"en\"` locale options for duration time notation templates. Additional templates may be created in the locale object extensions (see below).\n\n#### usePlural\n\nUnit label pluralization is automatically corrected when unit labels appear in the text associated with each moment token. The default `\"en\"` locale extension includes long and short unit labels, and a basic pluralization function. Unit labels, unit label types, and the pluralization function can be customized for a locale (see below).\n\n```javascript\nmoment.duration(1, \"minutes\").format(\"m [minutes]\");\n// \"1 minute\"\n\nmoment.duration(1, \"minutes\").format(\"m [mins]\");\n// \"1 min\"\n\nmoment.duration(2, \"minutes\").format(\"m [minute]\");\n// \"2 minutes\"\n\nmoment.duration(2, \"minutes\").format(\"m [min]\");\n// \"2 mins\"\n```\n\nSet `usePlural` to `false` to disable auto-correction of pluralization.\n\n```javascript\nmoment.duration(1, \"minutes\").format(\"m [minutes]\", {\n    usePlural: false\n});\n// \"1 minutes\"\n\nmoment.duration(1, \"minutes\").format(\"m [mins]\", {\n    usePlural: false\n});\n// \"1 mins\"\n\nmoment.duration(2, \"minutes\").format(\"m [minute]\", {\n    usePlural: false\n});\n// \"2 minute\"\n\nmoment.duration(2, \"minutes\").format(\"m [min]\", {\n    usePlural: false\n});\n// \"2 min\"\n```\n\nThe default pluralization function for the `\"en\"` locale outputs a plural unit name when a value is rendered with decimal precision.\n\n```javascript\nmoment.duration(1, \"minutes\").format(\"m [minutes]\", 2);\n// \"1.00 minutes\"\n```\n\n#### useLeftUnits\n\nThe text to the right of each moment token in a template string is treated as that token's units for the purposes of trimming, pluralizing, and localizing. To properly process a template string where the token/unit association is reversed, set `useLeftUnits` to `true`.\n\n```javascript\nmoment.duration(7322, \"seconds\").format(\"_ h, _ m, _ s\", {\n    useLeftUnits: true\n});\n// \"hrs 2, mins 2, secs 2\"\n```\n\n#### useGrouping\n\nFormatted numerical output is rendered using `toLocaleString` with the option `useGrouping` enabled. Set `useGrouping` to `false` to disable digit grouping.\n\n```javascript\nmoment.duration(1234, \"seconds\").format(\"s [seconds]\");\n// \"1,234 seconds\"\n\nmoment.duration(1234, \"seconds\").format(\"s [seconds]\", {\n    useGrouping: false\n});\n// \"1234 seconds\"\n```\n\n#### Extending Moment's `locale` object\n\nThis plugin now extends the moment.js `locale` object with duration labels, duration label types, duration time-notation templates, and a pluralization function. The `\"en\"` locale is included with this plugin. Other locales may be  defined using the moment.js locale API to provide auto-pluralized and auto-localized unit labels in different languages. If the plugin cannot find the duration locale extensions for the active moment locale, the plugin will fall back to the `\"en\"` locale.\n\nBelow is the default `\"en\"` locale extension.\n\n```javascript\nmoment.updateLocale('en', {\n    durationLabelsStandard: {\n        S: 'millisecond',\n        SS: 'milliseconds',\n        s: 'second',\n        ss: 'seconds',\n        m: 'minute',\n        mm: 'minutes',\n        h: 'hour',\n        hh: 'hours',\n        d: 'day',\n        dd: 'days',\n        w: 'week',\n        ww: 'weeks',\n        M: 'month',\n        MM: 'months',\n        y: 'year',\n        yy: 'years'\n    },\n    durationLabelsShort: {\n        S: 'msec',\n        SS: 'msecs',\n        s: 'sec',\n        ss: 'secs',\n        m: 'min',\n        mm: 'mins',\n        h: 'hr',\n        hh: 'hrs',\n        d: 'dy',\n        dd: 'dys',\n        w: 'wk',\n        ww: 'wks',\n        M: 'mo',\n        MM: 'mos',\n        y: 'yr',\n        yy: 'yrs'\n    },\n    durationTimeTemplates: {\n        HMS: 'h:mm:ss',\n        HM: 'h:mm',\n        MS: 'm:ss'\n    },\n    durationLabelTypes: [\n        { type: \"standard\", string: \"__\" },\n        { type: \"short\", string: \"_\" }\n    ],\n    durationPluralKey: function (token, integerValue, decimalValue) {\n        // Singular for a value of `1`, but not for `1.0`.\n        if (integerValue === 1 && decimalValue === null) {\n            return token;\n        }\n\n        return token + token;\n    }\n});\n```\n\n##### Creating a new Moment `locale` extension\n\nThe duration extensions for a new locale might look something like the following example, which includes an additional unit label type, a custom time-notation template, and an additional form of plural.\n\nThis example provides new values for all of the duration locale extensions. In a new locale, you can include updates for one or more of the duration locale extensions, and any that you do not include will automatically fall back to the `\"en\"` versions in this plugin. e.g. your locale could update only the `durationLabelsShort` object, or only the `durationPluralKey` function, if those were the only differences from the default `\"en\"` locale configuration.\n\nNew types of duration labels must have a key that begins with `durationLabels` and must be enumerated in `durationLabelTypes`.\n\nThis locale uses a single token `\"s\"` for the singular label, a double token `\"ss\"` for the plural label when the value is `2`, and a triple token `\"sss\"` for the plural label for values greater than `3`. For brevity, only labels for the `seconds` type are included.\n\nUnit labels are replaced after the format template string is tokenized, so they need not be escaped. Time-notation templates are replaced before the format template string is tokenized, so they must be escaped.\n\n```javascript\nmoment.updateLocale('sample', {\n    durationLabelsLong: {\n        s: 'singular long second',\n        ss: 'first long plural seconds',\n        sss: 'next long plural seconds'\n        // ...\n    },\n    durationLabelsStandard: {\n        s: 'singular second',\n        ss: 'first plural seconds',\n        sss: 'next plural seconds'\n        // ...\n    },\n    durationLabelsShort: {\n        s: 'singular sec',\n        ss: 'first plural secs',\n        sss: 'next plural secs'\n        // ...\n    },\n    durationTimeTemplates: {\n        HS: 'hh[h].ssss[s]'\n        // ...\n    },\n    durationLabelTypes: [\n        { type: \"long\", string: \"___\" },\n        { type: \"standard\", string: \"__\" },\n        { type: \"short\", string: \"_\" }\n    ],\n    durationPluralKey: function (token, integerValue, decimalValue) {\n        // Decimal value does not affect unit label for this locale.\n\n        // \"xxx\" for > 2.\n        if (integerValue > 2) {\n            return token + token + token;\n        }\n\n        // \"x\" for === 1.\n        if (integerValue === 1) {\n            return token;\n        }\n\n        // \"xx\" for others.\n        return token + token;\n    }\n});\n```\n\n###### `durationPluralKey`\n\nThe function for `durationPluralKey` is passed three arguments:\n\n- `token`\n\nString. A single character representing the unit type.\n\n```\nyears:   y\nmonths:  M\nweeks:   w\ndays:    d\nhours:   h\nminutes: m\nseconds: s\nms:      S\n```\n\n- `integerValue`\n\nNumber. The integer portion of the token's value.\n\n- `decimalValue`\n\nNumber. The decimal fraction portion of the token's value.\n\n### Localization and the Fallback Number Format Function\n\nYou can (and likely should) set the localization options for the fallback number format function if the default `\"en\"` locale formatting is not acceptable on some devices or in some environments.\n\n#### `useToLocaleString`\n\nSet this option to `false` to ignore the `toLocaleString` feature test and force the use of the `formatNumber` fallback function included in this plugin.\n\nThe fallback number format options will have no effect when `toLocaleString` is used. The grouping separator, decimal separator, and integer digit grouping will be determined by the user locale.\n\n```javascript\nmoment.duration(100000.1, \"seconds\").format(\"s\", {\n    userLocale: \"de-DE\",\n    precision: 2,\n    decimalSeparator: \",\",\n    groupingSeparator: \".\"\n});\n// \"100.000,10\" on all devices and in all environemnts.\n```\n\n#### `groupingSeparator`\n\nThe integer digit grouping separator used when using the fallback number format function. Default value is a `,` character.\n\n#### `decimalSeparator`\n\nThe decimal separator used when using the fallback number format function. Default value is a `.` character.\n\n#### `grouping`\n\nThe integer digit grouping used when using the fallback number format function. Must be an array. The default value of `[3]` gives the standard 3-digit thousand/million/billion digit groupings for the \"en\" locale. Setting this option to `[3, 2]` would generate the thousand/lakh/crore digit groupings used in the \"en-IN\" locale.\n\n```javascript\n// Force the use of the fallback number format function. Do not use toLocaleString.\n// We're in some sort of strange hybrid french-indian locale...\nmoment.duration(100000000000, \"seconds\").format(\"m\", {\n    useToLocaleString: false,\n    precision: 2,\n    decimalSeparator: \",\",\n    groupingSeparator: \" \",\n    grouping: [3, 2]\n});\n// \"1 66 66 66 666,67\");\n```\n","readmeFilename":"README.md"}