@driveflux/format-money 5.2.1-next.0 → 5.2.1
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/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +3 -0
- package/dist/config.js.map +1 -0
- package/dist/index.js.map +7 -0
- package/package.json +6 -6
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts", "../../../singleton/dist/index.js", "../../src/config.ts"],
|
|
4
|
+
"sourcesContent": ["import { config } from './config.js'\n\ntype FormatMoneyOptions = {\n locales?: string | string[]\n currencyDisplay?: 'symbol' | 'code' | 'name' | 'narrowSymbol'\n} & Omit<Intl.NumberFormatOptions, 'style' | 'currencyDisplay'>\n\n/**\n * Formats the money object into a string\n * @param money\n * @param locales\n */\nexport function formatMoney(money: number, providedOptions?: FormatMoneyOptions | string) {\n const options = { ...config.defaultFormat } as Intl.NumberFormatOptions\n let locale = config.defaultLocale\n if(typeof providedOptions === 'string') {\n options.currency = providedOptions\n }\n\n if(typeof providedOptions === 'object' && providedOptions) {\n for(const k in providedOptions) {\n const key = k as keyof FormatMoneyOptions\n if(key === 'locales') {\n locale = providedOptions[key] as string\n continue\n }\n \n // TODO\n // @ts-expect-error\n options[key] = providedOptions[key]\n }\n }\n \n return new Intl.NumberFormat(locale, {\n ...options,\n style: 'currency',\n }).format(money)\n}\n \n\n/** // TODO check if there are any instances using this function, update them then remove this\n * @deprecated use formatMoney instead\n * @returns \n */\nexport const formatMoneyWithFraction = formatMoney\n\n/**\n *\n * @param money\n * @param fraction cannot be less than 1\n * @returns\n */\nexport const decimals = (money: number | string, fraction = 2) => {\n if (fraction < 1) {\n throw new Error('Fraction cannot be less than 1')\n }\n\n const m = +money\n const safe = isNaN(m) ? 0 : m\n return Math.round(safe * 10 ** fraction) / 10 ** fraction\n}\n", "// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- First init will be empty\nif (!globalThis.__globalSingletonProvider) {\n globalThis.__globalSingletonProvider = new Map();\n}\nexport var singletonMap = globalThis.__globalSingletonProvider;\nexport function singleton(name, object) {\n var force = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;\n if (singletonMap.has(name) && !force) {\n return singletonMap.get(name);\n }\n return singletonMap.set(name, object).get(name);\n}\nif (process.env.SINGLETON_DEBUG === 'true') {\n setInterval(function() {\n var _globalThis___globalSingletonProvider;\n console.log('Singletons', (_globalThis___globalSingletonProvider = globalThis.__globalSingletonProvider) === null || _globalThis___globalSingletonProvider === void 0 ? void 0 : _globalThis___globalSingletonProvider.size, globalThis.__globalSingletonProvider.keys());\n }, 1000);\n}\n", "import { singleton } from '@driveflux/singleton'\n\nexport type Config = {\n defaultFormat: {\n currency: string\n currencyDisplay: string\n maximumFractionDigits: number\n minimumFractionDigits: number\n }\n defaultLocale: string | string[]\n}\n\nconst getConfig = (): Config => ({\n defaultFormat: {\n currency: 'MYR',\n currencyDisplay: 'narrowSymbol',\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n },\n defaultLocale: 'en-MY',\n})\n\nexport let config: Config = singleton('formatMoneyConfig', getConfig())\n\nexport const resetConfig = () => {\n config = singleton('formatMoneyConfig', getConfig(), true)\n\n return config\n}\n\nexport const setConfig = <Key extends keyof Config>(key: Key, value: Config[Key]) => {\n config[key] = value\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAI,CAAC,WAAW,2BAA2B;AACvC,aAAW,4BAA4B,oBAAI,IAAI;AACnD;AACO,IAAI,eAAe,WAAW;AAC9B,SAAS,UAAU,MAAM,QAAQ;AACpC,MAAI,QAAQ,UAAU,SAAS,KAAK,UAAU,CAAC,MAAM,SAAS,UAAU,CAAC,IAAI;AAC7E,MAAI,aAAa,IAAI,IAAI,KAAK,CAAC,OAAO;AAClC,WAAO,aAAa,IAA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AAM,QAAQ,IAAI,MAAM;AACnD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAYhD,MAAM,SAAS,GAAG,GAAW,EAAE,CAAC,CAAC;IAC/B,aAAa,EAAE;QACb,QAAQ,EAAE,KAAK;QACf,eAAe,EAAE,cAAc;QAC/B,qBAAqB,EAAE,CAAC;QACxB,qBAAqB,EAAE,CAAC;KACzB;IACD,aAAa,EAAE,OAAO;CACvB,CAAC,CAAA;AAEF,MAAM,CAAC,IAAI,MAAM,GAAW,SAAS,CAAC,mBAAmB,EAAE,SAAS,EAAE,CAAC,CAAA;AAEvE,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,MAAM,GAAG,SAAS,CAAC,mBAAmB,EAAE,SAAS,EAAE,EAAE,IAAI,CAAC,CAAA;IAE1D,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAA2B,GAAQ,EAAE,KAAkB,EAAE,EAAE;IAClF,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AACrB,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../singleton/dist/index.js", "../src/config.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- First init will be empty\nif (!globalThis.__globalSingletonProvider) {\n globalThis.__globalSingletonProvider = new Map();\n}\nexport var singletonMap = globalThis.__globalSingletonProvider;\nexport function singleton(name, object) {\n var force = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;\n if (singletonMap.has(name) && !force) {\n return singletonMap.get(name);\n }\n return singletonMap.set(name, object).get(name);\n}\nif (process.env.SINGLETON_DEBUG === 'true') {\n setInterval(function() {\n var _globalThis___globalSingletonProvider;\n console.log('Singletons', (_globalThis___globalSingletonProvider = globalThis.__globalSingletonProvider) === null || _globalThis___globalSingletonProvider === void 0 ? void 0 : _globalThis___globalSingletonProvider.size, globalThis.__globalSingletonProvider.keys());\n }, 1000);\n}\n", "import { singleton } from '@driveflux/singleton'\n\nexport type Config = {\n defaultFormat: {\n currency: string\n currencyDisplay: string\n maximumFractionDigits: number\n minimumFractionDigits: number\n }\n defaultLocale: string | string[]\n}\n\nconst getConfig = (): Config => ({\n defaultFormat: {\n currency: 'MYR',\n currencyDisplay: 'narrowSymbol',\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n },\n defaultLocale: 'en-MY',\n})\n\nexport let config: Config = singleton('formatMoneyConfig', getConfig())\n\nexport const resetConfig = () => {\n config = singleton('formatMoneyConfig', getConfig(), true)\n\n return config\n}\n\nexport const setConfig = <Key extends keyof Config>(key: Key, value: Config[Key]) => {\n config[key] = value\n}\n", "import { config } from './config.js'\n\ntype FormatMoneyOptions = {\n locales?: string | string[]\n currencyDisplay?: 'symbol' | 'code' | 'name' | 'narrowSymbol'\n} & Omit<Intl.NumberFormatOptions, 'style' | 'currencyDisplay'>\n\n/**\n * Formats the money object into a string\n * @param money\n * @param locales\n */\nexport function formatMoney(money: number, providedOptions?: FormatMoneyOptions | string) {\n const options = { ...config.defaultFormat } as Intl.NumberFormatOptions\n let locale = config.defaultLocale\n if(typeof providedOptions === 'string') {\n options.currency = providedOptions\n }\n\n if(typeof providedOptions === 'object' && providedOptions) {\n for(const k in providedOptions) {\n const key = k as keyof FormatMoneyOptions\n if(key === 'locales') {\n locale = providedOptions[key] as string\n continue\n }\n \n // TODO\n // @ts-expect-error\n options[key] = providedOptions[key]\n }\n }\n \n return new Intl.NumberFormat(locale, {\n ...options,\n style: 'currency',\n }).format(money)\n}\n \n\n/** // TODO check if there are any instances using this function, update them then remove this\n * @deprecated use formatMoney instead\n * @returns \n */\nexport const formatMoneyWithFraction = formatMoney\n\n/**\n *\n * @param money\n * @param fraction cannot be less than 1\n * @returns\n */\nexport const decimals = (money: number | string, fraction = 2) => {\n if (fraction < 1) {\n throw new Error('Fraction cannot be less than 1')\n }\n\n const m = +money\n const safe = isNaN(m) ? 0 : m\n return Math.round(safe * 10 ** fraction) / 10 ** fraction\n}\n"],
|
|
5
|
+
"mappings": ";AACA,IAAI,CAAC,WAAW,2BAA2B;AACvC,aAAW,4BAA4B,oBAAI,IAAI;AACnD;AACO,IAAI,eAAe,WAAW;AAC9B,SAAS,UAAU,MAAM,QAAQ;AACpC,MAAI,QAAQ,UAAU,SAAS,KAAK,UAAU,CAAC,MAAM,SAAS,UAAU,CAAC,IAAI;AAC7E,MAAI,aAAa,IAAI,IAAI,KAAK,CAAC,OAAO;AAClC,WAAO,aAAa,IAAI,IAAI;AAAA,EAChC;AACA,SAAO,aAAa,IAAI,MAAM,MAAM,EAAE,IAAI,IAAI;AAClD;AACA,IAAI,QAAQ,IAAI,oBAAoB,QAAQ;AACxC,cAAY,WAAW;AACnB,QAAI;AACJ,YAAQ,IAAI,eAAe,wCAAwC,WAAW,+BAA+B,QAAQ,0CAA0C,SAAS,SAAS,sCAAsC,MAAM,WAAW,0BAA0B,KAAK,CAAC;AAAA,EAC5Q,GAAG,GAAI;AACX;;;ACLA,IAAM,YAAY,OAAe;AAAA,EAC/B,eAAe;AAAA,IACb,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,EACzB;AAAA,EACA,eAAe;AACjB;AAEO,IAAI,SAAiB,UAAU,qBAAqB,UAAU,CAAC;;;ACV/D,SAAS,YAAY,OAAe,iBAA+C;AACxF,QAAM,UAAU,EAAE,GAAG,OAAO,cAAc;AAC1C,MAAI,SAAS,OAAO;AACpB,MAAG,OAAO,oBAAoB,UAAU;AACtC,YAAQ,WAAW;AAAA,EACrB;AAEA,MAAG,OAAO,oBAAoB,YAAY,iBAAiB;AACzD,eAAU,KAAK,iBAAiB;AAC9B,YAAM,MAAM;AACZ,UAAG,QAAQ,WAAW;AACpB,iBAAS,gBAAgB,GAAG;AAC5B;AAAA,MACF;AAIA,cAAQ,GAAG,IAAI,gBAAgB,GAAG;AAAA,IACpC;AAAA,EACF;AAEA,SAAO,IAAI,KAAK,aAAa,QAAQ;AAAA,IACnC,GAAG;AAAA,IACH,OAAO;AAAA,EACT,CAAC,EAAE,OAAO,KAAK;AACjB;AAOO,IAAM,0BAA0B;AAQhC,IAAM,WAAW,CAAC,OAAwB,WAAW,MAAM;AAChE,MAAI,WAAW,GAAG;AAChB,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAEA,QAAM,IAAI,CAAC;AACX,QAAM,OAAO,MAAM,CAAC,IAAI,IAAI;AAC5B,SAAO,KAAK,MAAM,OAAO,MAAM,QAAQ,IAAI,MAAM;AACnD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/format-money",
|
|
3
|
-
"version": "5.2.1
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package.json": "./package.json",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@driveflux/singleton": "1.2.1
|
|
16
|
+
"@driveflux/singleton": "1.2.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@driveflux/fab": "2.2.1
|
|
20
|
-
"@driveflux/tsconfig": "1.2.1
|
|
21
|
-
"@types/node": "^
|
|
19
|
+
"@driveflux/fab": "2.2.1",
|
|
20
|
+
"@driveflux/tsconfig": "1.2.1",
|
|
21
|
+
"@types/node": "^22.5.5",
|
|
22
22
|
"del-cli": "^5.1.0",
|
|
23
|
-
"typescript": "^5.
|
|
23
|
+
"typescript": "^5.6.2"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "fab",
|