@automattic/number-formatters 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
 
7
+ ## [1.1.4] - 2026-04-06
8
+ ### Changed
9
+ - Update package dependencies. [#47887]
10
+
11
+ ### Fixed
12
+ - Access wp.date settings directly. [#47812]
13
+
14
+ ## [1.1.3] - 2026-03-30
15
+ ### Changed
16
+ - Update package dependencies. [#47799]
17
+
7
18
  ## [1.1.2] - 2026-03-16
8
19
  ### Changed
9
20
  - Tests: Disable test incompatible with newer Node versions (22.22.1+). [#47588]
@@ -117,6 +128,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
117
128
  - Initial release
118
129
  - Basic number formatting functionality
119
130
 
131
+ [1.1.4]: https://github.com/Automattic/number-formatters/compare/1.1.3...1.1.4
132
+ [1.1.3]: https://github.com/Automattic/number-formatters/compare/1.1.2...1.1.3
120
133
  [1.1.2]: https://github.com/Automattic/number-formatters/compare/1.1.1...1.1.2
121
134
  [1.1.1]: https://github.com/Automattic/number-formatters/compare/1.1.0...1.1.1
122
135
  [1.1.0]: https://github.com/Automattic/number-formatters/compare/1.0.18...1.1.0
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FALLBACK_CURRENCY = exports.FALLBACK_LOCALE = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  exports.FALLBACK_LOCALE = 'en';
5
6
  exports.FALLBACK_CURRENCY = 'USD';
7
+ // This is just to hint to the dependency extraction tool that this package depends on @wordpress/date
8
+ // See: https://github.com/Automattic/jetpack/pull/47812#issuecomment-4142452829
9
+ tslib_1.__exportStar(require("@wordpress/date"), exports);
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const date_1 = require("@wordpress/date");
4
3
  const constants_ts_1 = require("./constants.cjs");
5
4
  const index_ts_1 = require("./number-format-currency/index.cjs");
6
5
  const number_format_ts_1 = require("./number-format.cjs");
@@ -31,9 +30,13 @@ function createNumberFormatters() {
31
30
  * @return {string} The locale to use for formatting.
32
31
  */
33
32
  const getBrowserSafeLocale = () => {
34
- const { l10n: { locale: localeFromUserSettings }, } = (0, date_1.getSettings)();
33
+ // Accessing the user's locale from `@wordpress/date` package.
34
+ // This is a bit hacky but it's better than importing `@wordpress/date` and using its `getSettings` function,
35
+ // because it drags moment.js with it even though we don't need it here.
36
+ const localeFromUserSettings = typeof window !== 'undefined' ? window.wp?.date?.getSettings?.()?.l10n?.locale : undefined;
37
+ const localeFromNavigator = typeof window !== 'undefined' ? window?.navigator?.language : undefined;
35
38
  return (localeState ??
36
- (localeFromUserSettings || global?.window?.navigator?.language) ??
39
+ (localeFromUserSettings || localeFromNavigator) ??
37
40
  constants_ts_1.FALLBACK_LOCALE).split('_')[0];
38
41
  };
39
42
  const setGeoLocation = (geoLocation) => {
@@ -1,2 +1,5 @@
1
1
  export const FALLBACK_LOCALE = 'en';
2
2
  export const FALLBACK_CURRENCY = 'USD';
3
+ // This is just to hint to the dependency extraction tool that this package depends on @wordpress/date
4
+ // See: https://github.com/Automattic/jetpack/pull/47812#issuecomment-4142452829
5
+ export * from '@wordpress/date';
@@ -1,4 +1,3 @@
1
- import { getSettings } from '@wordpress/date';
2
1
  import { FALLBACK_LOCALE } from "./constants.js";
3
2
  import { numberFormatCurrency, getCurrencyObject as getCurrencyObjectFromCurrencyFormatter, } from "./number-format-currency/index.js";
4
3
  import { numberFormat, numberFormatCompact } from "./number-format.js";
@@ -29,9 +28,13 @@ function createNumberFormatters() {
29
28
  * @return {string} The locale to use for formatting.
30
29
  */
31
30
  const getBrowserSafeLocale = () => {
32
- const { l10n: { locale: localeFromUserSettings }, } = getSettings();
31
+ // Accessing the user's locale from `@wordpress/date` package.
32
+ // This is a bit hacky but it's better than importing `@wordpress/date` and using its `getSettings` function,
33
+ // because it drags moment.js with it even though we don't need it here.
34
+ const localeFromUserSettings = typeof window !== 'undefined' ? window.wp?.date?.getSettings?.()?.l10n?.locale : undefined;
35
+ const localeFromNavigator = typeof window !== 'undefined' ? window?.navigator?.language : undefined;
33
36
  return (localeState ??
34
- (localeFromUserSettings || global?.window?.navigator?.language) ??
37
+ (localeFromUserSettings || localeFromNavigator) ??
35
38
  FALLBACK_LOCALE).split('_')[0];
36
39
  };
37
40
  const setGeoLocation = (geoLocation) => {
@@ -1,2 +1,3 @@
1
1
  export declare const FALLBACK_LOCALE = "en";
2
2
  export declare const FALLBACK_CURRENCY = "USD";
3
+ export * from '@wordpress/date';
@@ -1,4 +1,17 @@
1
1
  import type { FormatCurrency, FormatNumber, GetCurrencyObject } from './types.ts';
2
+ declare global {
3
+ interface Window {
4
+ wp?: {
5
+ date?: {
6
+ getSettings?: () => {
7
+ l10n?: {
8
+ locale?: string;
9
+ };
10
+ };
11
+ };
12
+ };
13
+ }
14
+ }
2
15
  export interface NumberFormatters {
3
16
  /**
4
17
  * Sets the locale for number formatting
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/number-formatters",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Number formatting utilities",
5
5
  "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/number-formatters/#readme",
6
6
  "bugs": {
@@ -39,11 +39,11 @@
39
39
  "devDependencies": {
40
40
  "@babel/core": "7.29.0",
41
41
  "@babel/preset-react": "7.28.5",
42
- "@jest/globals": "30.2.0",
43
- "@knighted/duel": "2.1.5",
42
+ "@jest/globals": "30.3.0",
43
+ "@knighted/duel": "4.0.2",
44
44
  "@types/jest": "30.0.0",
45
45
  "@typescript/native-preview": "7.0.0-dev.20260225.1",
46
- "jest": "30.2.0",
46
+ "jest": "30.3.0",
47
47
  "typescript": "5.9.3"
48
48
  }
49
49
  }
package/src/constants.ts CHANGED
@@ -1,2 +1,6 @@
1
1
  export const FALLBACK_LOCALE = 'en';
2
2
  export const FALLBACK_CURRENCY = 'USD';
3
+
4
+ // This is just to hint to the dependency extraction tool that this package depends on @wordpress/date
5
+ // See: https://github.com/Automattic/jetpack/pull/47812#issuecomment-4142452829
6
+ export * from '@wordpress/date';
@@ -1,4 +1,3 @@
1
- import { getSettings } from '@wordpress/date';
2
1
  import { FALLBACK_LOCALE } from './constants.ts';
3
2
  import {
4
3
  numberFormatCurrency,
@@ -7,8 +6,19 @@ import {
7
6
  import { numberFormat, numberFormatCompact } from './number-format.ts';
8
7
  import type { CurrencyObject, FormatCurrency, FormatNumber, GetCurrencyObject } from './types.ts';
9
8
 
10
- // Since global is used inside createNumberFormatters, we need to declare it for TS
11
- declare const global: typeof globalThis;
9
+ declare global {
10
+ interface Window {
11
+ wp?: {
12
+ date?: {
13
+ getSettings?: () => {
14
+ l10n?: {
15
+ locale?: string;
16
+ };
17
+ };
18
+ };
19
+ };
20
+ }
21
+ }
12
22
 
13
23
  export interface NumberFormatters {
14
24
  /**
@@ -162,13 +172,18 @@ function createNumberFormatters(): NumberFormatters {
162
172
  * @return {string} The locale to use for formatting.
163
173
  */
164
174
  const getBrowserSafeLocale = (): string => {
165
- const {
166
- l10n: { locale: localeFromUserSettings },
167
- } = getSettings();
175
+ // Accessing the user's locale from `@wordpress/date` package.
176
+ // This is a bit hacky but it's better than importing `@wordpress/date` and using its `getSettings` function,
177
+ // because it drags moment.js with it even though we don't need it here.
178
+ const localeFromUserSettings =
179
+ typeof window !== 'undefined' ? window.wp?.date?.getSettings?.()?.l10n?.locale : undefined;
180
+
181
+ const localeFromNavigator =
182
+ typeof window !== 'undefined' ? window?.navigator?.language : undefined;
168
183
 
169
184
  return (
170
185
  localeState ??
171
- ( localeFromUserSettings || global?.window?.navigator?.language ) ??
186
+ ( localeFromUserSettings || localeFromNavigator ) ??
172
187
  FALLBACK_LOCALE
173
188
  ).split( '_' )[ 0 ];
174
189
  };