New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

moment-duration-format

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moment-duration-format - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

2

bower.json
{
"name": "moment-duration-format",
"version": "2.2.0",
"version": "2.2.1",
"description": "A moment.js plugin for formatting durations.",

@@ -5,0 +5,0 @@ "main": "lib/moment-duration-format.js",

@@ -1,4 +0,4 @@

/*! Moment Duration Format v2.2.0
/*! Moment Duration Format v2.2.1
* https://github.com/jsmreese/moment-duration-format
* Date: 2018-01-15
* Date: 2018-01-21
*

@@ -40,2 +40,9 @@ * Duration format plugin function for the Moment.js library

// `Number#toLocaleString` rounds incorrectly for select numbers in Microsoft
// environments (Edge, IE11, Windows Phone) and possibly other environments.
// If the rounding test fails and `toLocaleString` will be used for formatting,
// the plugin will "pre-round" number values using the fallback number format
// function before passing them to `toLocaleString` for final formatting.
var toLocaleStringRoundingWorks = false;
// Token type names in order of descending magnitude.

@@ -182,6 +189,15 @@ var types = "escape years months weeks days hours minutes seconds milliseconds general".split(" ");

if (maximumSignificantDigits) {
// toLocaleString output is "0.0" instead of "0" for HTC browsers
// when maximumSignificantDigits is set. See #96.
if (maximumSignificantDigits && number > 0) {
localeStringOptions.maximumSignificantDigits = maximumSignificantDigits;
}
if (!toLocaleStringRoundingWorks) {
var roundingOptions = extend({}, options);
roundingOptions.useGrouping = false;
roundingOptions.decimalSeparator = ".";
number = parseFloat(formatNumber(number, roundingOptions), 10);
}
return number.toLocaleString(userLocale, localeStringOptions);

@@ -603,2 +619,11 @@ }

function featureTestToLocaleStringRounding() {
return (3.55).toLocaleString("en", {
useGrouping: false,
minimumIntegerDigits: 1,
minimumFractionDigits: 1,
maximumFractionDigits: 1
}) === "3.6";
}
function featureTestToLocaleString() {

@@ -1641,4 +1666,5 @@ var passed = true;

// Run feature test for `Number#toLocaleString`.
// Run feature tests for `Number#toLocaleString`.
toLocaleStringWorks = featureTestToLocaleString();
toLocaleStringRoundingWorks = toLocaleStringWorks && featureTestToLocaleStringRounding();

@@ -1645,0 +1671,0 @@ // Initialize duration format on the global moment instance.

{
"name": "moment-duration-format",
"version": "2.2.0",
"version": "2.2.1",
"description": "A moment.js plugin for formatting durations.",

@@ -5,0 +5,0 @@ "main": "lib/moment-duration-format.js",

@@ -13,7 +13,7 @@ # Moment Duration Format

## Important Note
## Formatting Numbers and Testing
Where 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.
This 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 function, set `useToLocaleString` to `false`. The fallback function output can be localized using options detailed below.
This 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.

@@ -24,4 +24,30 @@ This plugin is tested using BrowserStack on a range of Android devices with OS versions from 2.2 to 7, and on a range of iOS devices with OS versions from 4.3 to 11. Also tested on Chrome, Firefox, IE 8-11, and Edge browsers.

Please raise an issue if you notice formatting issues or anomalies in any environment!
---
## Roadmap
### Version 2
A few items remain to finish off Version 2:
- Add type definitions to support TypeScript, publish NuGet package, and support whatever other packaging options are in use these days.
- Testing of the plugin should be modernized, ideally to match the Moment.js testing setup.
### Version 3
Having implemented version 2 of the moment-duration-format plugin, there are some obvious improvements for a version 3.
The ideas below are logged as issues and tagged with the [3.0.0 milestone](https://github.com/jsmreese/moment-duration-format/milestone/6). If you have ideas or comments about what you'd like to see, please log an issue on this project!
- The fallback number formatting localization options should be included with the Moment Locale object extensions this plugin already adds for localizing duration unit labels. This would put all of the localization configuration in one place.
- moment-duration-format and its fallback number formatting function do not follow the same API as `Number#toLocaleString` for significant digits and faction digits. The fallback function should be updated to use the `toLocaleString` API, and the plugin should expose the `toLocaleString` API options directly rather than hiding some of the options and masking them behind `precision` and `useSignificantDigits` options.
- Exposing the fallback number formatting function as well as the `toLocaleString` feature test function would facilitate testing and allow them to be used outside of the context of formatting durations.
---
## Installation

@@ -1108,4 +1134,6 @@

### Localization and the Fallback Format Function
### Localization and the Fallback Number Format Function
You 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.
#### `useToLocaleString`

@@ -1115,18 +1143,29 @@

The following 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.
The 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.
```javascript
moment.duration(100000.1, "seconds").format("s", {
userLocale: "de-DE",
precision: 2,
decimalSeparator: ",",
groupingSeparator: "."
});
// "100.000,10" on all devices and in all environemnts.
```
#### `groupingSeparator`
The integer digit grouping separator used when using the fallback formatNumber function. Default value is a `,` character.
The integer digit grouping separator used when using the fallback number format function. Default value is a `,` character.
#### `decimalSeparator`
The decimal separator used when using the fallback formatNumber function. Default value is a `.` character.
The decimal separator used when using the fallback number format function. Default value is a `.` character.
#### `grouping`
The integer digit grouping used when using the fallback formatNumber 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.
The 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.
```javascript
// Some sort of strange hybrid french-indian locale...
// Force the use of the fallback number format function. Do not use toLocaleString.
// We're in some sort of strange hybrid french-indian locale...
moment.duration(100000000000, "seconds").format("m", {

@@ -1133,0 +1172,0 @@ useToLocaleString: false,

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc