yummies 7.19.4 → 7.20.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/assert.cjs +1 -1
- package/assert.cjs.map +1 -1
- package/assert.js +1 -1
- package/assert.js.map +1 -1
- package/async.cjs +147 -137
- package/async.cjs.map +1 -1
- package/async.d.ts +98 -131
- package/async.js +147 -137
- package/async.js.map +1 -1
- package/common.cjs +3 -1
- package/common.cjs.map +1 -1
- package/common.d.ts +18 -24
- package/common.js +3 -1
- package/common.js.map +1 -1
- package/complex.cjs +1 -0
- package/complex.cjs.map +1 -1
- package/complex.js +1 -0
- package/complex.js.map +1 -1
- package/cookie.cjs +1 -1
- package/cookie.cjs.map +1 -1
- package/cookie.d.ts +0 -18
- package/cookie.js +1 -1
- package/cookie.js.map +1 -1
- package/css-cx.cjs +78 -0
- package/css-cx.cjs.map +1 -0
- package/css-cx.d.ts +69 -0
- package/css-cx.js +74 -0
- package/css-cx.js.map +1 -0
- package/css.cjs +32 -111
- package/css.cjs.map +1 -1
- package/css.d.ts +32 -42
- package/css.js +30 -107
- package/css.js.map +1 -1
- package/data.cjs +60 -50
- package/data.cjs.map +1 -1
- package/data.d.ts +21 -34
- package/data.js +60 -50
- package/data.js.map +1 -1
- package/date-time.cjs +104 -98
- package/date-time.cjs.map +1 -1
- package/date-time.d.ts +51 -57
- package/date-time.js +104 -97
- package/date-time.js.map +1 -1
- package/device.cjs +14 -19
- package/device.cjs.map +1 -1
- package/device.d.ts +15 -26
- package/device.js +14 -19
- package/device.js.map +1 -1
- package/encodings.cjs +1 -1
- package/encodings.cjs.map +1 -1
- package/encodings.d.ts +0 -17
- package/encodings.js +1 -1
- package/encodings.js.map +1 -1
- package/errors.cjs +1 -18
- package/errors.cjs.map +1 -1
- package/errors.d.ts +0 -17
- package/errors.js +1 -17
- package/errors.js.map +1 -1
- package/file.cjs +3 -17
- package/file.cjs.map +1 -1
- package/file.d.ts +1 -16
- package/file.js +3 -17
- package/file.js.map +1 -1
- package/format.cjs +1 -1
- package/format.cjs.map +1 -1
- package/format.js +1 -1
- package/format.js.map +1 -1
- package/html.cjs +112 -175
- package/html.cjs.map +1 -1
- package/html.d.ts +58 -57
- package/html.js +111 -172
- package/html.js.map +1 -1
- package/id-nanoid.cjs +36 -0
- package/id-nanoid.cjs.map +1 -0
- package/id-nanoid.d.ts +26 -0
- package/id-nanoid.js +32 -0
- package/id-nanoid.js.map +1 -0
- package/id.cjs +10 -45
- package/id.cjs.map +1 -1
- package/id.d.ts +27 -36
- package/id.js +6 -40
- package/id.js.map +1 -1
- package/imports.cjs +3 -18
- package/imports.cjs.map +1 -1
- package/imports.d.ts +1 -16
- package/imports.js +3 -17
- package/imports.js.map +1 -1
- package/math.cjs +16 -12
- package/math.cjs.map +1 -1
- package/math.d.ts +9 -24
- package/math.js +16 -12
- package/math.js.map +1 -1
- package/media.cjs +88 -89
- package/media.cjs.map +1 -1
- package/media.d.ts +72 -80
- package/media.js +88 -88
- package/media.js.map +1 -1
- package/mobx.cjs +0 -1
- package/mobx.cjs.map +1 -1
- package/mobx.js.map +1 -1
- package/ms.cjs +3 -17
- package/ms.cjs.map +1 -1
- package/ms.d.ts +1 -16
- package/ms.js +3 -17
- package/ms.js.map +1 -1
- package/number.cjs +1 -17
- package/number.cjs.map +1 -1
- package/number.d.ts +0 -16
- package/number.js +1 -17
- package/number.js.map +1 -1
- package/package.json +6 -6
- package/parser.cjs +1 -1
- package/parser.cjs.map +1 -1
- package/parser.js +1 -1
- package/parser.js.map +1 -1
- package/price.cjs +1 -1
- package/price.cjs.map +1 -1
- package/price.d.ts +0 -16
- package/price.js +1 -1
- package/price.js.map +1 -1
- package/random.cjs +37 -39
- package/random.cjs.map +1 -1
- package/random.d.ts +31 -40
- package/random.js +37 -39
- package/random.js.map +1 -1
- package/react.cjs +0 -1
- package/react.cjs.map +1 -1
- package/react.js.map +1 -1
- package/sanitize-html.cjs +82 -0
- package/sanitize-html.cjs.map +1 -0
- package/sanitize-html.d.ts +28 -0
- package/sanitize-html.js +79 -0
- package/sanitize-html.js.map +1 -0
- package/sound.cjs +1 -17
- package/sound.cjs.map +1 -1
- package/sound.d.ts +0 -16
- package/sound.js +1 -17
- package/sound.js.map +1 -1
- package/storage.cjs +7 -5
- package/storage.cjs.map +1 -1
- package/storage.d.ts +3 -17
- package/storage.js +7 -5
- package/storage.js.map +1 -1
- package/text.cjs +3 -17
- package/text.cjs.map +1 -1
- package/text.d.ts +1 -16
- package/text.js +3 -17
- package/text.js.map +1 -1
- package/type-guard.cjs +38 -1
- package/type-guard.cjs.map +1 -1
- package/type-guard.d.ts +38 -0
- package/type-guard.js +38 -1
- package/type-guard.js.map +1 -1
- package/types.d.ts +20 -1
- package/types.global.d.ts +19 -0
- package/vibrate.cjs +1 -17
- package/vibrate.cjs.map +1 -1
- package/vibrate.d.ts +0 -16
- package/vibrate.js +1 -17
- package/vibrate.js.map +1 -1
- /package/{chunk-pbuEa-1d.js → chunk-D7D4PA-g.js} +0 -0
- /package/{chunk-CZWwpsFl.cjs → chunk-DakpK96I.cjs} +0 -0
package/ms.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ms.cjs","names":[],"sources":["../src/ms.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"ms.cjs","names":[],"sources":["../src/ms/units-to-ms.ts","../src/ms/ms.ts"],"sourcesContent":["export const unitsToMs = {\n ms: 1,\n sec: 1000,\n min: 1000 * 60,\n hour: 1000 * 60 * 60,\n day: 1000 * 60 * 60 * 24,\n week: 1000 * 60 * 60 * 24 * 7,\n} as const;\n","import { unitsToMs } from './units-to-ms.js';\n\n/**\n * Converts a value in the specified unit to milliseconds.\n *\n * @example\n * ```ts\n * ms(1, 'min') // 60_000\n * ms(30, 'sec') // 30_000\n * ```\n */\nexport const ms = (value: number, unit: keyof typeof unitsToMs = 'ms') =>\n value * unitsToMs[unit];\n"],"mappings":";;AAAA,IAAa,YAAY;CACvB,IAAI;CACJ,KAAK;CACL,KAAK,MAAO;CACZ,MAAM,MAAO,KAAK;CAClB,KAAK,MAAO,KAAK,KAAK;CACtB,MAAM,MAAO,KAAK,KAAK,KAAK;AAC9B;;;;;;;;;;;;ACIA,IAAa,MAAM,OAAe,OAA+B,SAC/D,QAAQ,UAAU"}
|
package/ms.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ---header-docs-section---
|
|
3
|
-
* # yummies/ms
|
|
4
|
-
*
|
|
5
|
-
* ## Description
|
|
6
|
-
*
|
|
7
|
-
* Converts human-friendly time units (seconds, minutes, hours, days, weeks) to **milliseconds** for
|
|
8
|
-
* timers, animations, and `dayjs`-style math. The `unitsToMs` map is shared across the library so
|
|
9
|
-
* delays and durations stay consistent instead of scattering `* 1000` literals through the code.
|
|
10
|
-
*
|
|
11
|
-
* ## Usage
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { ms } from "yummies/ms";
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
1
|
declare const unitsToMs: {
|
|
18
2
|
readonly ms: 1;
|
|
19
3
|
readonly sec: 1000;
|
|
@@ -22,6 +6,7 @@ declare const unitsToMs: {
|
|
|
22
6
|
readonly day: number;
|
|
23
7
|
readonly week: number;
|
|
24
8
|
};
|
|
9
|
+
|
|
25
10
|
/**
|
|
26
11
|
* Converts a value in the specified unit to milliseconds.
|
|
27
12
|
*
|
package/ms.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
//#region src/ms.ts
|
|
2
|
-
/**
|
|
3
|
-
* ---header-docs-section---
|
|
4
|
-
* # yummies/ms
|
|
5
|
-
*
|
|
6
|
-
* ## Description
|
|
7
|
-
*
|
|
8
|
-
* Converts human-friendly time units (seconds, minutes, hours, days, weeks) to **milliseconds** for
|
|
9
|
-
* timers, animations, and `dayjs`-style math. The `unitsToMs` map is shared across the library so
|
|
10
|
-
* delays and durations stay consistent instead of scattering `* 1000` literals through the code.
|
|
11
|
-
*
|
|
12
|
-
* ## Usage
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { ms } from "yummies/ms";
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
1
|
+
//#region src/ms/units-to-ms.ts
|
|
18
2
|
var unitsToMs = {
|
|
19
3
|
ms: 1,
|
|
20
4
|
sec: 1e3,
|
|
@@ -23,6 +7,8 @@ var unitsToMs = {
|
|
|
23
7
|
day: 1e3 * 60 * 60 * 24,
|
|
24
8
|
week: 1e3 * 60 * 60 * 24 * 7
|
|
25
9
|
};
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/ms/ms.ts
|
|
26
12
|
/**
|
|
27
13
|
* Converts a value in the specified unit to milliseconds.
|
|
28
14
|
*
|
package/ms.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ms.js","names":[],"sources":["../src/ms.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"ms.js","names":[],"sources":["../src/ms/units-to-ms.ts","../src/ms/ms.ts"],"sourcesContent":["export const unitsToMs = {\n ms: 1,\n sec: 1000,\n min: 1000 * 60,\n hour: 1000 * 60 * 60,\n day: 1000 * 60 * 60 * 24,\n week: 1000 * 60 * 60 * 24 * 7,\n} as const;\n","import { unitsToMs } from './units-to-ms.js';\n\n/**\n * Converts a value in the specified unit to milliseconds.\n *\n * @example\n * ```ts\n * ms(1, 'min') // 60_000\n * ms(30, 'sec') // 30_000\n * ```\n */\nexport const ms = (value: number, unit: keyof typeof unitsToMs = 'ms') =>\n value * unitsToMs[unit];\n"],"mappings":";AAAA,IAAa,YAAY;CACvB,IAAI;CACJ,KAAK;CACL,KAAK,MAAO;CACZ,MAAM,MAAO,KAAK;CAClB,KAAK,MAAO,KAAK,KAAK;CACtB,MAAM,MAAO,KAAK,KAAK,KAAK;AAC9B;;;;;;;;;;;;ACIA,IAAa,MAAM,OAAe,OAA+B,SAC/D,QAAQ,UAAU"}
|
package/number.cjs
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/number.ts
|
|
3
|
-
/**
|
|
4
|
-
* ---header-docs-section---
|
|
5
|
-
* # yummies/number
|
|
6
|
-
*
|
|
7
|
-
* ## Description
|
|
8
|
-
*
|
|
9
|
-
* Numeric rounding that avoids classic floating-point artifacts (`191.212999…`) without paying for
|
|
10
|
-
* string round-trips in hot paths. Use when formatting prices, charts, or sliders where a fixed
|
|
11
|
-
* decimal count must be stable for display and comparisons.
|
|
12
|
-
*
|
|
13
|
-
* ## Usage
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { round } from "yummies/number";
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
2
|
+
//#region src/number/round.ts
|
|
19
3
|
/**
|
|
20
4
|
* Works like `parseFloat(number.toFixed(4))` but performance better
|
|
21
5
|
*
|
package/number.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.cjs","names":[],"sources":["../src/number.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"number.cjs","names":[],"sources":["../src/number/round.ts"],"sourcesContent":["/**\n * Works like `parseFloat(number.toFixed(4))` but performance better\n *\n * @example\n * round(191.212999999999999999999999, 4) // 191.213\n */\nexport function round(value: number, decimalPlaces: number = 0): number {\n if (!decimalPlaces) {\n return Math.round(value);\n }\n\n const factor = 10 ** decimalPlaces;\n return Math.round(value * factor) / factor;\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,MAAM,OAAe,gBAAwB,GAAW;CACtE,IAAI,CAAC,eACH,OAAO,KAAK,MAAM,KAAK;CAGzB,MAAM,SAAS,MAAM;CACrB,OAAO,KAAK,MAAM,QAAQ,MAAM,IAAI;AACtC"}
|
package/number.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ---header-docs-section---
|
|
3
|
-
* # yummies/number
|
|
4
|
-
*
|
|
5
|
-
* ## Description
|
|
6
|
-
*
|
|
7
|
-
* Numeric rounding that avoids classic floating-point artifacts (`191.212999…`) without paying for
|
|
8
|
-
* string round-trips in hot paths. Use when formatting prices, charts, or sliders where a fixed
|
|
9
|
-
* decimal count must be stable for display and comparisons.
|
|
10
|
-
*
|
|
11
|
-
* ## Usage
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { round } from "yummies/number";
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
1
|
/**
|
|
18
2
|
* Works like `parseFloat(number.toFixed(4))` but performance better
|
|
19
3
|
*
|
package/number.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
//#region src/number.ts
|
|
2
|
-
/**
|
|
3
|
-
* ---header-docs-section---
|
|
4
|
-
* # yummies/number
|
|
5
|
-
*
|
|
6
|
-
* ## Description
|
|
7
|
-
*
|
|
8
|
-
* Numeric rounding that avoids classic floating-point artifacts (`191.212999…`) without paying for
|
|
9
|
-
* string round-trips in hot paths. Use when formatting prices, charts, or sliders where a fixed
|
|
10
|
-
* decimal count must be stable for display and comparisons.
|
|
11
|
-
*
|
|
12
|
-
* ## Usage
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { round } from "yummies/number";
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
1
|
+
//#region src/number/round.ts
|
|
18
2
|
/**
|
|
19
3
|
* Works like `parseFloat(number.toFixed(4))` but performance better
|
|
20
4
|
*
|
package/number.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","names":[],"sources":["../src/number.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"number.js","names":[],"sources":["../src/number/round.ts"],"sourcesContent":["/**\n * Works like `parseFloat(number.toFixed(4))` but performance better\n *\n * @example\n * round(191.212999999999999999999999, 4) // 191.213\n */\nexport function round(value: number, decimalPlaces: number = 0): number {\n if (!decimalPlaces) {\n return Math.round(value);\n }\n\n const factor = 10 ** decimalPlaces;\n return Math.round(value * factor) / factor;\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,MAAM,OAAe,gBAAwB,GAAW;CACtE,IAAI,CAAC,eACH,OAAO,KAAK,MAAM,KAAK;CAGzB,MAAM,SAAS,MAAM;CACrB,OAAO,KAAK,MAAM,QAAQ,MAAM,IAAI;AACtC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yummies",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.20.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"javascript",
|
|
6
6
|
"typescript",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"homepage": "https://js2me.github.io/yummies/api/async/",
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "
|
|
18
|
+
"url": "https://github.com/js2me/yummies"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"mobx": "^6.12.4",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"class-variance-authority": "^0.7.1",
|
|
35
35
|
"clsx": "^2.1.1",
|
|
36
|
-
"dayjs": "^1.11.
|
|
37
|
-
"dompurify": "^3.4.
|
|
38
|
-
"nanoid": "^5.1.
|
|
39
|
-
"tailwind-merge": "^3.
|
|
36
|
+
"dayjs": "^1.11.21",
|
|
37
|
+
"dompurify": "^3.4.11",
|
|
38
|
+
"nanoid": "^5.1.15",
|
|
39
|
+
"tailwind-merge": "^3.6.0"
|
|
40
40
|
},
|
|
41
41
|
"type": "module",
|
|
42
42
|
"exports": {
|
package/parser.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_chunk = require("./chunk-
|
|
2
|
+
const require_chunk = require("./chunk-DakpK96I.cjs");
|
|
3
3
|
let yummies_type_guard = require("yummies/type-guard");
|
|
4
4
|
let yummies_format = require("yummies/format");
|
|
5
5
|
//#region src/parser/number.ts
|
package/parser.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.cjs","names":[],"sources":["../src/parser/number.ts","../src/parser/percent.ts","../src/parser/string.ts","../src/parser/_exports.ts"],"sourcesContent":["import { format } from 'yummies/format';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface NumberParserSettings<TFallback = number> {\n digits?: number;\n fallback?: TFallback;\n /**\n * Round to upper boundary\n * 5.1 -> 6\n */\n ceil?: boolean;\n /**\n * Round to bottom boundary\n * 5.9 -> 5\n */\n floor?: boolean;\n clamped?: [min?: Maybe<number>, max?: Maybe<number>];\n}\n\n/**\n * Parses a number from raw input and optionally clamps, rounds or limits\n * fractional digits.\n *\n * Strings are normalized by removing spaces and replacing `,` with `.` before\n * parsing. Invalid inputs return the configured fallback.\n *\n * @template TFallback Fallback value type returned when parsing fails.\n * @param input Raw value to parse.\n * @param userSettings Parser settings merged with `number.defaultSettings`.\n * @returns Parsed number or fallback value.\n *\n * @example\n * ```ts\n * number('1 234,5'); // 1234.5\n * ```\n *\n * @example\n * ```ts\n * number('bad', { fallback: 0 }); // 0\n * ```\n */\nexport const number = <TFallback = number>(\n input: Maybe<unknown>,\n userSettings?: Maybe<NumberParserSettings<TFallback>>,\n): number | TFallback => {\n const settings = {\n ...number.defaultSettings,\n ...userSettings,\n };\n\n const fallback = (\n 'fallback' in settings ? settings.fallback : 0\n ) as TFallback;\n\n let result: number;\n\n if (typeGuard.isNumber(input)) {\n result = input;\n } else if (typeGuard.isString(input)) {\n const formattedInput = format.skipSpaces(input).replace(',', '.');\n if (formattedInput === '') {\n result = fallback as any;\n } else {\n result = Number(formattedInput);\n }\n } else {\n result = fallback as any;\n }\n\n if (typeGuard.isNumber(result)) {\n if (settings?.clamped != null) {\n result = Math.max(\n settings.clamped[0] ?? -Infinity,\n Math.min(result, settings.clamped[1] ?? Infinity),\n );\n }\n\n if (settings?.ceil != null) {\n result = Math.ceil(result);\n }\n\n if (settings?.floor != null) {\n result = Math.floor(result);\n }\n\n if (settings?.digits != null) {\n result = +result.toFixed(settings.digits);\n }\n\n return result;\n } else {\n return fallback;\n }\n};\n\nnumber.defaultSettings = {} as NumberParserSettings;\n","import type { Maybe } from 'yummies/types';\n\nimport { type NumberParserSettings, number } from './number.js';\n\n/**\n * Converts a value into a percentage of `maxValue` and parses the result with\n * the shared numeric parser.\n *\n * @template TFallback Fallback value type returned when parsing fails.\n * @param value Current value.\n * @param maxValue Maximum value representing `100%`.\n * @param settings Numeric parser settings for the computed percentage.\n * @returns Parsed percentage or fallback value.\n *\n * @example\n * ```ts\n * percent(25, 200); // 12.5\n * ```\n *\n * @example\n * ```ts\n * percent('bad', 100, { fallback: 0 }); // 0\n * ```\n */\nexport const percent = <TFallback = number>(\n value: Maybe<string | number>,\n maxValue?: Maybe<string | number>,\n settings?: Maybe<NumberParserSettings<TFallback>>,\n) => {\n return number<TFallback>((Number(value) / Number(maxValue)) * 100, settings);\n};\n","import { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface StringParserSettings<TFallback = string> {\n fallback?: TFallback;\n prettyJson?: boolean;\n}\n\n/**\n * Converts arbitrary input into a string representation.\n *\n * Objects are serialized with `JSON.stringify`, optionally pretty-printed, and\n * nullish values resolve to the configured fallback.\n *\n * @template TFallback Fallback value type returned for nullish input.\n * @param input Raw value to stringify.\n * @param settings String conversion settings.\n * @returns Stringified input or fallback value.\n *\n * @example\n * ```ts\n * string(123); // '123'\n * ```\n *\n * @example\n * ```ts\n * string({ id: 1 }, { prettyJson: true });\n * ```\n */\nexport const string = <TFallback = string>(\n input: Maybe<unknown>,\n settings?: Maybe<StringParserSettings<TFallback>>,\n): string | TFallback => {\n const fallback =\n settings && 'fallback' in settings ? (settings.fallback as TFallback) : '';\n\n if (input == null) {\n return fallback;\n }\n\n if (typeGuard.isObject(input)) {\n if (settings?.prettyJson) {\n return JSON.stringify(input, null, 2);\n }\n\n return JSON.stringify(input);\n }\n\n return String(input);\n};\n","/**\n * ---header-docs-section---\n * # yummies/parser\n *\n * ## Description\n *\n * Parsers for user-entered **numbers, percents, and strings** with tolerant input and typed\n * results. Use when normalizing form values, query params, or CSV-like text before validation\n * schemas run, without duplicating regex and `parseFloat` edge cases in every feature module.\n *\n * ## Usage\n *\n * ```ts\n * import { parser } from \"yummies/parser\";\n * ```\n */\n\nexport * from './number.js';\nexport * from './percent.js';\nexport * from './string.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,UACX,OACA,iBACuB;CACvB,MAAM,WAAW;EACf,GAAG,OAAO;EACV,GAAG;
|
|
1
|
+
{"version":3,"file":"parser.cjs","names":[],"sources":["../src/parser/number.ts","../src/parser/percent.ts","../src/parser/string.ts","../src/parser/_exports.ts"],"sourcesContent":["import { format } from 'yummies/format';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface NumberParserSettings<TFallback = number> {\n digits?: number;\n fallback?: TFallback;\n /**\n * Round to upper boundary\n * 5.1 -> 6\n */\n ceil?: boolean;\n /**\n * Round to bottom boundary\n * 5.9 -> 5\n */\n floor?: boolean;\n clamped?: [min?: Maybe<number>, max?: Maybe<number>];\n}\n\n/**\n * Parses a number from raw input and optionally clamps, rounds or limits\n * fractional digits.\n *\n * Strings are normalized by removing spaces and replacing `,` with `.` before\n * parsing. Invalid inputs return the configured fallback.\n *\n * @template TFallback Fallback value type returned when parsing fails.\n * @param input Raw value to parse.\n * @param userSettings Parser settings merged with `number.defaultSettings`.\n * @returns Parsed number or fallback value.\n *\n * @example\n * ```ts\n * number('1 234,5'); // 1234.5\n * ```\n *\n * @example\n * ```ts\n * number('bad', { fallback: 0 }); // 0\n * ```\n */\nexport const number = <TFallback = number>(\n input: Maybe<unknown>,\n userSettings?: Maybe<NumberParserSettings<TFallback>>,\n): number | TFallback => {\n const settings = {\n ...number.defaultSettings,\n ...userSettings,\n };\n\n const fallback = (\n 'fallback' in settings ? settings.fallback : 0\n ) as TFallback;\n\n let result: number;\n\n if (typeGuard.isNumber(input)) {\n result = input;\n } else if (typeGuard.isString(input)) {\n const formattedInput = format.skipSpaces(input).replace(',', '.');\n if (formattedInput === '') {\n result = fallback as any;\n } else {\n result = Number(formattedInput);\n }\n } else {\n result = fallback as any;\n }\n\n if (typeGuard.isNumber(result)) {\n if (settings?.clamped != null) {\n result = Math.max(\n settings.clamped[0] ?? -Infinity,\n Math.min(result, settings.clamped[1] ?? Infinity),\n );\n }\n\n if (settings?.ceil != null) {\n result = Math.ceil(result);\n }\n\n if (settings?.floor != null) {\n result = Math.floor(result);\n }\n\n if (settings?.digits != null) {\n result = +result.toFixed(settings.digits);\n }\n\n return result;\n } else {\n return fallback;\n }\n};\n\nnumber.defaultSettings = {} as NumberParserSettings;\n","import type { Maybe } from 'yummies/types';\n\nimport { type NumberParserSettings, number } from './number.js';\n\n/**\n * Converts a value into a percentage of `maxValue` and parses the result with\n * the shared numeric parser.\n *\n * @template TFallback Fallback value type returned when parsing fails.\n * @param value Current value.\n * @param maxValue Maximum value representing `100%`.\n * @param settings Numeric parser settings for the computed percentage.\n * @returns Parsed percentage or fallback value.\n *\n * @example\n * ```ts\n * percent(25, 200); // 12.5\n * ```\n *\n * @example\n * ```ts\n * percent('bad', 100, { fallback: 0 }); // 0\n * ```\n */\nexport const percent = <TFallback = number>(\n value: Maybe<string | number>,\n maxValue?: Maybe<string | number>,\n settings?: Maybe<NumberParserSettings<TFallback>>,\n) => {\n return number<TFallback>((Number(value) / Number(maxValue)) * 100, settings);\n};\n","import { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface StringParserSettings<TFallback = string> {\n fallback?: TFallback;\n prettyJson?: boolean;\n}\n\n/**\n * Converts arbitrary input into a string representation.\n *\n * Objects are serialized with `JSON.stringify`, optionally pretty-printed, and\n * nullish values resolve to the configured fallback.\n *\n * @template TFallback Fallback value type returned for nullish input.\n * @param input Raw value to stringify.\n * @param settings String conversion settings.\n * @returns Stringified input or fallback value.\n *\n * @example\n * ```ts\n * string(123); // '123'\n * ```\n *\n * @example\n * ```ts\n * string({ id: 1 }, { prettyJson: true });\n * ```\n */\nexport const string = <TFallback = string>(\n input: Maybe<unknown>,\n settings?: Maybe<StringParserSettings<TFallback>>,\n): string | TFallback => {\n const fallback =\n settings && 'fallback' in settings ? (settings.fallback as TFallback) : '';\n\n if (input == null) {\n return fallback;\n }\n\n if (typeGuard.isObject(input)) {\n if (settings?.prettyJson) {\n return JSON.stringify(input, null, 2);\n }\n\n return JSON.stringify(input);\n }\n\n return String(input);\n};\n","/**\n * ---header-docs-section---\n * # yummies/parser\n *\n * ## Description\n *\n * Parsers for user-entered **numbers, percents, and strings** with tolerant input and typed\n * results. Use when normalizing form values, query params, or CSV-like text before validation\n * schemas run, without duplicating regex and `parseFloat` edge cases in every feature module.\n *\n * ## Usage\n *\n * ```ts\n * import { parser } from \"yummies/parser\";\n * ```\n */\n\nexport * from './number.js';\nexport * from './percent.js';\nexport * from './string.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,UACX,OACA,iBACuB;CACvB,MAAM,WAAW;EACf,GAAG,OAAO;EACV,GAAG;CACL;CAEA,MAAM,WACJ,cAAc,WAAW,SAAS,WAAW;CAG/C,IAAI;CAEJ,IAAI,mBAAA,UAAU,SAAS,KAAK,GAC1B,SAAS;MACJ,IAAI,mBAAA,UAAU,SAAS,KAAK,GAAG;EACpC,MAAM,iBAAiB,eAAA,OAAO,WAAW,KAAK,EAAE,QAAQ,KAAK,GAAG;EAChE,IAAI,mBAAmB,IACrB,SAAS;OAET,SAAS,OAAO,cAAc;CAElC,OACE,SAAS;CAGX,IAAI,mBAAA,UAAU,SAAS,MAAM,GAAG;EAC9B,IAAI,UAAU,WAAW,MACvB,SAAS,KAAK,IACZ,SAAS,QAAQ,MAAM,WACvB,KAAK,IAAI,QAAQ,SAAS,QAAQ,MAAM,QAAQ,CAClD;EAGF,IAAI,UAAU,QAAQ,MACpB,SAAS,KAAK,KAAK,MAAM;EAG3B,IAAI,UAAU,SAAS,MACrB,SAAS,KAAK,MAAM,MAAM;EAG5B,IAAI,UAAU,UAAU,MACtB,SAAS,CAAC,OAAO,QAAQ,SAAS,MAAM;EAG1C,OAAO;CACT,OACE,OAAO;AAEX;AAEA,OAAO,kBAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;ACxE1B,IAAa,WACX,OACA,UACA,aACG;CACH,OAAO,OAAmB,OAAO,KAAK,IAAI,OAAO,QAAQ,IAAK,KAAK,QAAQ;AAC7E;;;;;;;;;;;;;;;;;;;;;;;;ACDA,IAAa,UACX,OACA,aACuB;CACvB,MAAM,WACJ,YAAY,cAAc,WAAY,SAAS,WAAyB;CAE1E,IAAI,SAAS,MACX,OAAO;CAGT,IAAI,mBAAA,UAAU,SAAS,KAAK,GAAG;EAC7B,IAAI,UAAU,YACZ,OAAO,KAAK,UAAU,OAAO,MAAM,CAAC;EAGtC,OAAO,KAAK,UAAU,KAAK;CAC7B;CAEA,OAAO,OAAO,KAAK;AACrB"}
|
package/parser.js
CHANGED
package/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","names":[],"sources":["../src/parser/number.ts","../src/parser/percent.ts","../src/parser/string.ts","../src/parser/_exports.ts"],"sourcesContent":["import { format } from 'yummies/format';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface NumberParserSettings<TFallback = number> {\n digits?: number;\n fallback?: TFallback;\n /**\n * Round to upper boundary\n * 5.1 -> 6\n */\n ceil?: boolean;\n /**\n * Round to bottom boundary\n * 5.9 -> 5\n */\n floor?: boolean;\n clamped?: [min?: Maybe<number>, max?: Maybe<number>];\n}\n\n/**\n * Parses a number from raw input and optionally clamps, rounds or limits\n * fractional digits.\n *\n * Strings are normalized by removing spaces and replacing `,` with `.` before\n * parsing. Invalid inputs return the configured fallback.\n *\n * @template TFallback Fallback value type returned when parsing fails.\n * @param input Raw value to parse.\n * @param userSettings Parser settings merged with `number.defaultSettings`.\n * @returns Parsed number or fallback value.\n *\n * @example\n * ```ts\n * number('1 234,5'); // 1234.5\n * ```\n *\n * @example\n * ```ts\n * number('bad', { fallback: 0 }); // 0\n * ```\n */\nexport const number = <TFallback = number>(\n input: Maybe<unknown>,\n userSettings?: Maybe<NumberParserSettings<TFallback>>,\n): number | TFallback => {\n const settings = {\n ...number.defaultSettings,\n ...userSettings,\n };\n\n const fallback = (\n 'fallback' in settings ? settings.fallback : 0\n ) as TFallback;\n\n let result: number;\n\n if (typeGuard.isNumber(input)) {\n result = input;\n } else if (typeGuard.isString(input)) {\n const formattedInput = format.skipSpaces(input).replace(',', '.');\n if (formattedInput === '') {\n result = fallback as any;\n } else {\n result = Number(formattedInput);\n }\n } else {\n result = fallback as any;\n }\n\n if (typeGuard.isNumber(result)) {\n if (settings?.clamped != null) {\n result = Math.max(\n settings.clamped[0] ?? -Infinity,\n Math.min(result, settings.clamped[1] ?? Infinity),\n );\n }\n\n if (settings?.ceil != null) {\n result = Math.ceil(result);\n }\n\n if (settings?.floor != null) {\n result = Math.floor(result);\n }\n\n if (settings?.digits != null) {\n result = +result.toFixed(settings.digits);\n }\n\n return result;\n } else {\n return fallback;\n }\n};\n\nnumber.defaultSettings = {} as NumberParserSettings;\n","import type { Maybe } from 'yummies/types';\n\nimport { type NumberParserSettings, number } from './number.js';\n\n/**\n * Converts a value into a percentage of `maxValue` and parses the result with\n * the shared numeric parser.\n *\n * @template TFallback Fallback value type returned when parsing fails.\n * @param value Current value.\n * @param maxValue Maximum value representing `100%`.\n * @param settings Numeric parser settings for the computed percentage.\n * @returns Parsed percentage or fallback value.\n *\n * @example\n * ```ts\n * percent(25, 200); // 12.5\n * ```\n *\n * @example\n * ```ts\n * percent('bad', 100, { fallback: 0 }); // 0\n * ```\n */\nexport const percent = <TFallback = number>(\n value: Maybe<string | number>,\n maxValue?: Maybe<string | number>,\n settings?: Maybe<NumberParserSettings<TFallback>>,\n) => {\n return number<TFallback>((Number(value) / Number(maxValue)) * 100, settings);\n};\n","import { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface StringParserSettings<TFallback = string> {\n fallback?: TFallback;\n prettyJson?: boolean;\n}\n\n/**\n * Converts arbitrary input into a string representation.\n *\n * Objects are serialized with `JSON.stringify`, optionally pretty-printed, and\n * nullish values resolve to the configured fallback.\n *\n * @template TFallback Fallback value type returned for nullish input.\n * @param input Raw value to stringify.\n * @param settings String conversion settings.\n * @returns Stringified input or fallback value.\n *\n * @example\n * ```ts\n * string(123); // '123'\n * ```\n *\n * @example\n * ```ts\n * string({ id: 1 }, { prettyJson: true });\n * ```\n */\nexport const string = <TFallback = string>(\n input: Maybe<unknown>,\n settings?: Maybe<StringParserSettings<TFallback>>,\n): string | TFallback => {\n const fallback =\n settings && 'fallback' in settings ? (settings.fallback as TFallback) : '';\n\n if (input == null) {\n return fallback;\n }\n\n if (typeGuard.isObject(input)) {\n if (settings?.prettyJson) {\n return JSON.stringify(input, null, 2);\n }\n\n return JSON.stringify(input);\n }\n\n return String(input);\n};\n","/**\n * ---header-docs-section---\n * # yummies/parser\n *\n * ## Description\n *\n * Parsers for user-entered **numbers, percents, and strings** with tolerant input and typed\n * results. Use when normalizing form values, query params, or CSV-like text before validation\n * schemas run, without duplicating regex and `parseFloat` edge cases in every feature module.\n *\n * ## Usage\n *\n * ```ts\n * import { parser } from \"yummies/parser\";\n * ```\n */\n\nexport * from './number.js';\nexport * from './percent.js';\nexport * from './string.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,UACX,OACA,iBACuB;CACvB,MAAM,WAAW;EACf,GAAG,OAAO;EACV,GAAG;
|
|
1
|
+
{"version":3,"file":"parser.js","names":[],"sources":["../src/parser/number.ts","../src/parser/percent.ts","../src/parser/string.ts","../src/parser/_exports.ts"],"sourcesContent":["import { format } from 'yummies/format';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface NumberParserSettings<TFallback = number> {\n digits?: number;\n fallback?: TFallback;\n /**\n * Round to upper boundary\n * 5.1 -> 6\n */\n ceil?: boolean;\n /**\n * Round to bottom boundary\n * 5.9 -> 5\n */\n floor?: boolean;\n clamped?: [min?: Maybe<number>, max?: Maybe<number>];\n}\n\n/**\n * Parses a number from raw input and optionally clamps, rounds or limits\n * fractional digits.\n *\n * Strings are normalized by removing spaces and replacing `,` with `.` before\n * parsing. Invalid inputs return the configured fallback.\n *\n * @template TFallback Fallback value type returned when parsing fails.\n * @param input Raw value to parse.\n * @param userSettings Parser settings merged with `number.defaultSettings`.\n * @returns Parsed number or fallback value.\n *\n * @example\n * ```ts\n * number('1 234,5'); // 1234.5\n * ```\n *\n * @example\n * ```ts\n * number('bad', { fallback: 0 }); // 0\n * ```\n */\nexport const number = <TFallback = number>(\n input: Maybe<unknown>,\n userSettings?: Maybe<NumberParserSettings<TFallback>>,\n): number | TFallback => {\n const settings = {\n ...number.defaultSettings,\n ...userSettings,\n };\n\n const fallback = (\n 'fallback' in settings ? settings.fallback : 0\n ) as TFallback;\n\n let result: number;\n\n if (typeGuard.isNumber(input)) {\n result = input;\n } else if (typeGuard.isString(input)) {\n const formattedInput = format.skipSpaces(input).replace(',', '.');\n if (formattedInput === '') {\n result = fallback as any;\n } else {\n result = Number(formattedInput);\n }\n } else {\n result = fallback as any;\n }\n\n if (typeGuard.isNumber(result)) {\n if (settings?.clamped != null) {\n result = Math.max(\n settings.clamped[0] ?? -Infinity,\n Math.min(result, settings.clamped[1] ?? Infinity),\n );\n }\n\n if (settings?.ceil != null) {\n result = Math.ceil(result);\n }\n\n if (settings?.floor != null) {\n result = Math.floor(result);\n }\n\n if (settings?.digits != null) {\n result = +result.toFixed(settings.digits);\n }\n\n return result;\n } else {\n return fallback;\n }\n};\n\nnumber.defaultSettings = {} as NumberParserSettings;\n","import type { Maybe } from 'yummies/types';\n\nimport { type NumberParserSettings, number } from './number.js';\n\n/**\n * Converts a value into a percentage of `maxValue` and parses the result with\n * the shared numeric parser.\n *\n * @template TFallback Fallback value type returned when parsing fails.\n * @param value Current value.\n * @param maxValue Maximum value representing `100%`.\n * @param settings Numeric parser settings for the computed percentage.\n * @returns Parsed percentage or fallback value.\n *\n * @example\n * ```ts\n * percent(25, 200); // 12.5\n * ```\n *\n * @example\n * ```ts\n * percent('bad', 100, { fallback: 0 }); // 0\n * ```\n */\nexport const percent = <TFallback = number>(\n value: Maybe<string | number>,\n maxValue?: Maybe<string | number>,\n settings?: Maybe<NumberParserSettings<TFallback>>,\n) => {\n return number<TFallback>((Number(value) / Number(maxValue)) * 100, settings);\n};\n","import { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface StringParserSettings<TFallback = string> {\n fallback?: TFallback;\n prettyJson?: boolean;\n}\n\n/**\n * Converts arbitrary input into a string representation.\n *\n * Objects are serialized with `JSON.stringify`, optionally pretty-printed, and\n * nullish values resolve to the configured fallback.\n *\n * @template TFallback Fallback value type returned for nullish input.\n * @param input Raw value to stringify.\n * @param settings String conversion settings.\n * @returns Stringified input or fallback value.\n *\n * @example\n * ```ts\n * string(123); // '123'\n * ```\n *\n * @example\n * ```ts\n * string({ id: 1 }, { prettyJson: true });\n * ```\n */\nexport const string = <TFallback = string>(\n input: Maybe<unknown>,\n settings?: Maybe<StringParserSettings<TFallback>>,\n): string | TFallback => {\n const fallback =\n settings && 'fallback' in settings ? (settings.fallback as TFallback) : '';\n\n if (input == null) {\n return fallback;\n }\n\n if (typeGuard.isObject(input)) {\n if (settings?.prettyJson) {\n return JSON.stringify(input, null, 2);\n }\n\n return JSON.stringify(input);\n }\n\n return String(input);\n};\n","/**\n * ---header-docs-section---\n * # yummies/parser\n *\n * ## Description\n *\n * Parsers for user-entered **numbers, percents, and strings** with tolerant input and typed\n * results. Use when normalizing form values, query params, or CSV-like text before validation\n * schemas run, without duplicating regex and `parseFloat` edge cases in every feature module.\n *\n * ## Usage\n *\n * ```ts\n * import { parser } from \"yummies/parser\";\n * ```\n */\n\nexport * from './number.js';\nexport * from './percent.js';\nexport * from './string.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,UACX,OACA,iBACuB;CACvB,MAAM,WAAW;EACf,GAAG,OAAO;EACV,GAAG;CACL;CAEA,MAAM,WACJ,cAAc,WAAW,SAAS,WAAW;CAG/C,IAAI;CAEJ,IAAI,UAAU,SAAS,KAAK,GAC1B,SAAS;MACJ,IAAI,UAAU,SAAS,KAAK,GAAG;EACpC,MAAM,iBAAiB,OAAO,WAAW,KAAK,EAAE,QAAQ,KAAK,GAAG;EAChE,IAAI,mBAAmB,IACrB,SAAS;OAET,SAAS,OAAO,cAAc;CAElC,OACE,SAAS;CAGX,IAAI,UAAU,SAAS,MAAM,GAAG;EAC9B,IAAI,UAAU,WAAW,MACvB,SAAS,KAAK,IACZ,SAAS,QAAQ,MAAM,WACvB,KAAK,IAAI,QAAQ,SAAS,QAAQ,MAAM,QAAQ,CAClD;EAGF,IAAI,UAAU,QAAQ,MACpB,SAAS,KAAK,KAAK,MAAM;EAG3B,IAAI,UAAU,SAAS,MACrB,SAAS,KAAK,MAAM,MAAM;EAG5B,IAAI,UAAU,UAAU,MACtB,SAAS,CAAC,OAAO,QAAQ,SAAS,MAAM;EAG1C,OAAO;CACT,OACE,OAAO;AAEX;AAEA,OAAO,kBAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;ACxE1B,IAAa,WACX,OACA,UACA,aACG;CACH,OAAO,OAAmB,OAAO,KAAK,IAAI,OAAO,QAAQ,IAAK,KAAK,QAAQ;AAC7E;;;;;;;;;;;;;;;;;;;;;;;;ACDA,IAAa,UACX,OACA,aACuB;CACvB,MAAM,WACJ,YAAY,cAAc,WAAY,SAAS,WAAyB;CAE1E,IAAI,SAAS,MACX,OAAO;CAGT,IAAI,UAAU,SAAS,KAAK,GAAG;EAC7B,IAAI,UAAU,YACZ,OAAO,KAAK,UAAU,OAAO,MAAM,CAAC;EAGtC,OAAO,KAAK,UAAU,KAAK;CAC7B;CAEA,OAAO,OAAO,KAAK;AACrB"}
|
package/price.cjs
CHANGED
package/price.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.cjs","names":[],"sources":["../src/price.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"price.cjs","names":[],"sources":["../src/price/format-price.ts"],"sourcesContent":["export interface PriceFormatOptions\n extends Partial<Omit<Intl.NumberFormatOptions, 'currency'>> {\n withoutSymbol?: boolean;\n customSymbol?: string;\n}\n\n/**\n * Formats a numeric price using locale and currency options.\n *\n * @example\n * ```ts\n * formatPrice(1990, 'ru-RU', 'RUB');\n * ```\n */\nexport const formatPrice = (\n price: number,\n locale: string,\n currency?: string,\n { withoutSymbol, customSymbol, ...options }: PriceFormatOptions = {},\n) => {\n const priceFormatter = new Intl.NumberFormat(locale, {\n style: 'currency',\n currency,\n minimumFractionDigits: 0,\n currencyDisplay: 'narrowSymbol',\n ...options,\n });\n\n const zeroPrice = priceFormatter.format(0);\n const currencySymbol = zeroPrice.replace('0', '');\n const rawPrice = priceFormatter.format(price);\n const priceWithoutCurrency = rawPrice.replace(currencySymbol, '');\n\n if (withoutSymbol) {\n return priceWithoutCurrency;\n }\n\n return `${priceWithoutCurrency} ${\n customSymbol ?? (currency === 'RUB' ? 'р' : currencySymbol)\n }`.replace(/\\s{2,}/, ' ');\n};\n"],"mappings":";;;;;;;;;;AAcA,IAAa,eACX,OACA,QACA,UACA,EAAE,eAAe,cAAc,GAAG,YAAgC,CAAC,MAChE;CACH,MAAM,iBAAiB,IAAI,KAAK,aAAa,QAAQ;EACnD,OAAO;EACP;EACA,uBAAuB;EACvB,iBAAiB;EACjB,GAAG;CACL,CAAC;CAGD,MAAM,iBADY,eAAe,OAAO,CACjB,EAAU,QAAQ,KAAK,EAAE;CAEhD,MAAM,uBADW,eAAe,OAAO,KACV,EAAS,QAAQ,gBAAgB,EAAE;CAEhE,IAAI,eACF,OAAO;CAGT,OAAO,GAAG,qBAAqB,GAC7B,iBAAiB,aAAa,QAAQ,MAAM,kBAC3C,QAAQ,UAAU,GAAG;AAC1B"}
|
package/price.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ---header-docs-section---
|
|
3
|
-
* # yummies/price
|
|
4
|
-
*
|
|
5
|
-
* ## Description
|
|
6
|
-
*
|
|
7
|
-
* Locale-aware **money formatting** via `Intl.NumberFormat`, with optional symbol hiding and
|
|
8
|
-
* custom currency symbols for legacy UI. It wraps browser i18n APIs so storefronts and dashboards
|
|
9
|
-
* share one implementation for RUB/EUR/USD-style output without pulling a heavy formatting library.
|
|
10
|
-
*
|
|
11
|
-
* ## Usage
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { formatPrice } from "yummies/price";
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
1
|
interface PriceFormatOptions extends Partial<Omit<Intl.NumberFormatOptions, 'currency'>> {
|
|
18
2
|
withoutSymbol?: boolean;
|
|
19
3
|
customSymbol?: string;
|
package/price.js
CHANGED
package/price.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.js","names":[],"sources":["../src/price.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"price.js","names":[],"sources":["../src/price/format-price.ts"],"sourcesContent":["export interface PriceFormatOptions\n extends Partial<Omit<Intl.NumberFormatOptions, 'currency'>> {\n withoutSymbol?: boolean;\n customSymbol?: string;\n}\n\n/**\n * Formats a numeric price using locale and currency options.\n *\n * @example\n * ```ts\n * formatPrice(1990, 'ru-RU', 'RUB');\n * ```\n */\nexport const formatPrice = (\n price: number,\n locale: string,\n currency?: string,\n { withoutSymbol, customSymbol, ...options }: PriceFormatOptions = {},\n) => {\n const priceFormatter = new Intl.NumberFormat(locale, {\n style: 'currency',\n currency,\n minimumFractionDigits: 0,\n currencyDisplay: 'narrowSymbol',\n ...options,\n });\n\n const zeroPrice = priceFormatter.format(0);\n const currencySymbol = zeroPrice.replace('0', '');\n const rawPrice = priceFormatter.format(price);\n const priceWithoutCurrency = rawPrice.replace(currencySymbol, '');\n\n if (withoutSymbol) {\n return priceWithoutCurrency;\n }\n\n return `${priceWithoutCurrency} ${\n customSymbol ?? (currency === 'RUB' ? 'р' : currencySymbol)\n }`.replace(/\\s{2,}/, ' ');\n};\n"],"mappings":";;;;;;;;;AAcA,IAAa,eACX,OACA,QACA,UACA,EAAE,eAAe,cAAc,GAAG,YAAgC,CAAC,MAChE;CACH,MAAM,iBAAiB,IAAI,KAAK,aAAa,QAAQ;EACnD,OAAO;EACP;EACA,uBAAuB;EACvB,iBAAiB;EACjB,GAAG;CACL,CAAC;CAGD,MAAM,iBADY,eAAe,OAAO,CACjB,EAAU,QAAQ,KAAK,EAAE;CAEhD,MAAM,uBADW,eAAe,OAAO,KACV,EAAS,QAAQ,gBAAgB,EAAE;CAEhE,IAAI,eACF,OAAO;CAGT,OAAO,GAAG,qBAAqB,GAC7B,iBAAiB,aAAa,QAAQ,MAAM,kBAC3C,QAAQ,UAAU,GAAG;AAC1B"}
|
package/random.cjs
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/random.ts
|
|
2
|
+
//#region src/random/get-frequency-value.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* # yummies/random
|
|
6
|
-
*
|
|
7
|
-
* ## Description
|
|
8
|
-
*
|
|
9
|
-
* Small RNG helpers for UI demos, games, and sampling: floats, integers, and random choices from
|
|
10
|
-
* arrays. They wrap `Math.random` (not cryptographically secure) so prefer platform `crypto` when
|
|
11
|
-
* generating secrets, tokens, or lottery outcomes.
|
|
12
|
-
*
|
|
13
|
-
* ## Usage
|
|
4
|
+
* Returns `true` with the provided probability from `0` to `1`.
|
|
14
5
|
*
|
|
6
|
+
* @example
|
|
15
7
|
* ```ts
|
|
16
|
-
*
|
|
8
|
+
* const shouldRun = getFrequencyValue(0.25);
|
|
17
9
|
* ```
|
|
18
10
|
*/
|
|
11
|
+
var getFrequencyValue = (frequency) => {
|
|
12
|
+
return Math.random() < frequency;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/random/get-random-float.ts
|
|
19
16
|
/**
|
|
20
17
|
* Returns a random floating-point number between `min` and `max`.
|
|
21
18
|
*
|
|
@@ -25,6 +22,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
25
22
|
* ```
|
|
26
23
|
*/
|
|
27
24
|
var getRandomFloat = (min = 0, max = 1) => Math.random() * (max - min) + min;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/random/get-random-int.ts
|
|
28
27
|
/**
|
|
29
28
|
* Returns a random integer between `min` and `max`.
|
|
30
29
|
*
|
|
@@ -34,24 +33,34 @@ var getRandomFloat = (min = 0, max = 1) => Math.random() * (max - min) + min;
|
|
|
34
33
|
* ```
|
|
35
34
|
*/
|
|
36
35
|
var getRandomInt = (min = 0, max = 1) => min === max ? min : Math.round(getRandomFloat(min, max));
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/random/get-major-random-bool.ts
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
+
* Returns `true` more often than `false`.
|
|
39
40
|
*
|
|
40
41
|
* @example
|
|
41
42
|
* ```ts
|
|
42
|
-
* const
|
|
43
|
+
* const value = getMajorRandomBool();
|
|
43
44
|
* ```
|
|
44
45
|
*/
|
|
45
|
-
var
|
|
46
|
+
var getMajorRandomBool = () => {
|
|
47
|
+
return getRandomInt(0, 10) <= 6;
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/random/get-minor-random-bool.ts
|
|
46
51
|
/**
|
|
47
|
-
*
|
|
52
|
+
* Returns `true` less often than `false`.
|
|
48
53
|
*
|
|
49
54
|
* @example
|
|
50
55
|
* ```ts
|
|
51
|
-
* const
|
|
56
|
+
* const value = getMinorRandomBool();
|
|
52
57
|
* ```
|
|
53
58
|
*/
|
|
54
|
-
var
|
|
59
|
+
var getMinorRandomBool = () => {
|
|
60
|
+
return !getMajorRandomBool();
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/random/get-random-bool.ts
|
|
55
64
|
/**
|
|
56
65
|
* Returns a uniformly random boolean.
|
|
57
66
|
*
|
|
@@ -61,39 +70,28 @@ var getRandomSizeArray = (min = 0, max = 10) => Array.from({ length: getRandomIn
|
|
|
61
70
|
* ```
|
|
62
71
|
*/
|
|
63
72
|
var getRandomBool = () => getRandomInt(0, 1) === 1;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/random/get-random-choice.ts
|
|
64
75
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* const value = getMajorRandomBool();
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
var getMajorRandomBool = () => {
|
|
73
|
-
return getRandomInt(0, 10) <= 6;
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Returns `true` less often than `false`.
|
|
76
|
+
* Picks a random element from the provided array.
|
|
77
77
|
*
|
|
78
78
|
* @example
|
|
79
79
|
* ```ts
|
|
80
|
-
* const
|
|
80
|
+
* const fruit = getRandomChoice(['apple', 'banana', 'orange']);
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
var getRandomChoice = (arr) => arr[getRandomInt(0, arr.length - 1)];
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/random/get-random-size-array.ts
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
87
|
+
* Creates an array filled with `null` values using a random length.
|
|
88
88
|
*
|
|
89
89
|
* @example
|
|
90
90
|
* ```ts
|
|
91
|
-
* const
|
|
91
|
+
* const items = getRandomSizeArray(2, 5);
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
94
|
-
var
|
|
95
|
-
return Math.random() < frequency;
|
|
96
|
-
};
|
|
94
|
+
var getRandomSizeArray = (min = 0, max = 10) => Array.from({ length: getRandomInt(min, max) }).fill(null);
|
|
97
95
|
//#endregion
|
|
98
96
|
exports.getFrequencyValue = getFrequencyValue;
|
|
99
97
|
exports.getMajorRandomBool = getMajorRandomBool;
|
package/random.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.cjs","names":[],"sources":["../src/random.ts"
|
|
1
|
+
{"version":3,"file":"random.cjs","names":[],"sources":["../src/random/get-frequency-value.ts","../src/random/get-random-float.ts","../src/random/get-random-int.ts","../src/random/get-major-random-bool.ts","../src/random/get-minor-random-bool.ts","../src/random/get-random-bool.ts","../src/random/get-random-choice.ts","../src/random/get-random-size-array.ts"],"sourcesContent":["/**\n * Returns `true` with the provided probability from `0` to `1`.\n *\n * @example\n * ```ts\n * const shouldRun = getFrequencyValue(0.25);\n * ```\n */\nexport const getFrequencyValue = (frequency: number) => {\n return Math.random() < frequency;\n};\n","/**\n * Returns a random floating-point number between `min` and `max`.\n *\n * @example\n * ```ts\n * const value = getRandomFloat(1, 10);\n * ```\n */\nexport const getRandomFloat = <T extends number = number>(\n min = 0,\n max = 1,\n): T => (Math.random() * (max - min) + min) as T;\n","import { getRandomFloat } from './get-random-float.js';\n\n/**\n * Returns a random integer between `min` and `max`.\n *\n * @example\n * ```ts\n * const value = getRandomInt(1, 10);\n * ```\n */\nexport const getRandomInt = <T extends number = number>(min = 0, max = 1): T =>\n min === max ? (min as T) : (Math.round(getRandomFloat(min, max)) as T);\n","import { getRandomInt } from './get-random-int.js';\n\n/**\n * Returns `true` more often than `false`.\n *\n * @example\n * ```ts\n * const value = getMajorRandomBool();\n * ```\n */\nexport const getMajorRandomBool = () => {\n return getRandomInt(0, 10) <= 6;\n};\n","import { getMajorRandomBool } from './get-major-random-bool.js';\n\n/**\n * Returns `true` less often than `false`.\n *\n * @example\n * ```ts\n * const value = getMinorRandomBool();\n * ```\n */\nexport const getMinorRandomBool = () => {\n return !getMajorRandomBool();\n};\n","import { getRandomInt } from './get-random-int.js';\n\n/**\n * Returns a uniformly random boolean.\n *\n * @example\n * ```ts\n * const value = getRandomBool();\n * ```\n */\nexport const getRandomBool = () => getRandomInt(0, 1) === 1;\n","import { getRandomInt } from './get-random-int.js';\n\n/**\n * Picks a random element from the provided array.\n *\n * @example\n * ```ts\n * const fruit = getRandomChoice(['apple', 'banana', 'orange']);\n * ```\n */\nexport const getRandomChoice = <T>(arr: T[]): T =>\n arr[getRandomInt(0, arr.length - 1)];\n","import { getRandomInt } from './get-random-int.js';\n\n/**\n * Creates an array filled with `null` values using a random length.\n *\n * @example\n * ```ts\n * const items = getRandomSizeArray(2, 5);\n * ```\n */\nexport const getRandomSizeArray = (min = 0, max = 10) =>\n Array.from({ length: getRandomInt(min, max) }).fill(null);\n"],"mappings":";;;;;;;;;;AAQA,IAAa,qBAAqB,cAAsB;CACtD,OAAO,KAAK,OAAO,IAAI;AACzB;;;;;;;;;;;ACFA,IAAa,kBACX,MAAM,GACN,MAAM,MACC,KAAK,OAAO,KAAK,MAAM,OAAO;;;;;;;;;;;ACDvC,IAAa,gBAA2C,MAAM,GAAG,MAAM,MACrE,QAAQ,MAAO,MAAa,KAAK,MAAM,eAAe,KAAK,GAAG,CAAC;;;;;;;;;;;ACDjE,IAAa,2BAA2B;CACtC,OAAO,aAAa,GAAG,EAAE,KAAK;AAChC;;;;;;;;;;;ACFA,IAAa,2BAA2B;CACtC,OAAO,CAAC,mBAAmB;AAC7B;;;;;;;;;;;ACFA,IAAa,sBAAsB,aAAa,GAAG,CAAC,MAAM;;;;;;;;;;;ACA1D,IAAa,mBAAsB,QACjC,IAAI,aAAa,GAAG,IAAI,SAAS,CAAC;;;;;;;;;;;ACDpC,IAAa,sBAAsB,MAAM,GAAG,MAAM,OAChD,MAAM,KAAK,EAAE,QAAQ,aAAa,KAAK,GAAG,EAAE,CAAC,EAAE,KAAK,IAAI"}
|
package/random.d.ts
CHANGED
|
@@ -1,90 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* # yummies/random
|
|
4
|
-
*
|
|
5
|
-
* ## Description
|
|
6
|
-
*
|
|
7
|
-
* Small RNG helpers for UI demos, games, and sampling: floats, integers, and random choices from
|
|
8
|
-
* arrays. They wrap `Math.random` (not cryptographically secure) so prefer platform `crypto` when
|
|
9
|
-
* generating secrets, tokens, or lottery outcomes.
|
|
10
|
-
*
|
|
11
|
-
* ## Usage
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { getRandomInt, getRandomChoice } from "yummies/random";
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Returns a random floating-point number between `min` and `max`.
|
|
2
|
+
* Returns `true` with the provided probability from `0` to `1`.
|
|
19
3
|
*
|
|
20
4
|
* @example
|
|
21
5
|
* ```ts
|
|
22
|
-
* const
|
|
6
|
+
* const shouldRun = getFrequencyValue(0.25);
|
|
23
7
|
* ```
|
|
24
8
|
*/
|
|
25
|
-
declare const
|
|
9
|
+
declare const getFrequencyValue: (frequency: number) => boolean;
|
|
10
|
+
|
|
26
11
|
/**
|
|
27
|
-
* Returns
|
|
12
|
+
* Returns `true` more often than `false`.
|
|
28
13
|
*
|
|
29
14
|
* @example
|
|
30
15
|
* ```ts
|
|
31
|
-
* const value =
|
|
16
|
+
* const value = getMajorRandomBool();
|
|
32
17
|
* ```
|
|
33
18
|
*/
|
|
34
|
-
declare const
|
|
19
|
+
declare const getMajorRandomBool: () => boolean;
|
|
20
|
+
|
|
35
21
|
/**
|
|
36
|
-
*
|
|
22
|
+
* Returns `true` less often than `false`.
|
|
37
23
|
*
|
|
38
24
|
* @example
|
|
39
25
|
* ```ts
|
|
40
|
-
* const
|
|
26
|
+
* const value = getMinorRandomBool();
|
|
41
27
|
* ```
|
|
42
28
|
*/
|
|
43
|
-
declare const
|
|
29
|
+
declare const getMinorRandomBool: () => boolean;
|
|
30
|
+
|
|
44
31
|
/**
|
|
45
|
-
*
|
|
32
|
+
* Returns a uniformly random boolean.
|
|
46
33
|
*
|
|
47
34
|
* @example
|
|
48
35
|
* ```ts
|
|
49
|
-
* const
|
|
36
|
+
* const value = getRandomBool();
|
|
50
37
|
* ```
|
|
51
38
|
*/
|
|
52
|
-
declare const
|
|
39
|
+
declare const getRandomBool: () => boolean;
|
|
40
|
+
|
|
53
41
|
/**
|
|
54
|
-
*
|
|
42
|
+
* Picks a random element from the provided array.
|
|
55
43
|
*
|
|
56
44
|
* @example
|
|
57
45
|
* ```ts
|
|
58
|
-
* const
|
|
46
|
+
* const fruit = getRandomChoice(['apple', 'banana', 'orange']);
|
|
59
47
|
* ```
|
|
60
48
|
*/
|
|
61
|
-
declare const
|
|
49
|
+
declare const getRandomChoice: <T>(arr: T[]) => T;
|
|
50
|
+
|
|
62
51
|
/**
|
|
63
|
-
* Returns
|
|
52
|
+
* Returns a random floating-point number between `min` and `max`.
|
|
64
53
|
*
|
|
65
54
|
* @example
|
|
66
55
|
* ```ts
|
|
67
|
-
* const value =
|
|
56
|
+
* const value = getRandomFloat(1, 10);
|
|
68
57
|
* ```
|
|
69
58
|
*/
|
|
70
|
-
declare const
|
|
59
|
+
declare const getRandomFloat: <T extends number = number>(min?: number, max?: number) => T;
|
|
60
|
+
|
|
71
61
|
/**
|
|
72
|
-
* Returns
|
|
62
|
+
* Returns a random integer between `min` and `max`.
|
|
73
63
|
*
|
|
74
64
|
* @example
|
|
75
65
|
* ```ts
|
|
76
|
-
* const value =
|
|
66
|
+
* const value = getRandomInt(1, 10);
|
|
77
67
|
* ```
|
|
78
68
|
*/
|
|
79
|
-
declare const
|
|
69
|
+
declare const getRandomInt: <T extends number = number>(min?: number, max?: number) => T;
|
|
70
|
+
|
|
80
71
|
/**
|
|
81
|
-
*
|
|
72
|
+
* Creates an array filled with `null` values using a random length.
|
|
82
73
|
*
|
|
83
74
|
* @example
|
|
84
75
|
* ```ts
|
|
85
|
-
* const
|
|
76
|
+
* const items = getRandomSizeArray(2, 5);
|
|
86
77
|
* ```
|
|
87
78
|
*/
|
|
88
|
-
declare const
|
|
79
|
+
declare const getRandomSizeArray: (min?: number, max?: number) => unknown[];
|
|
89
80
|
|
|
90
81
|
export { getFrequencyValue, getMajorRandomBool, getMinorRandomBool, getRandomBool, getRandomChoice, getRandomFloat, getRandomInt, getRandomSizeArray };
|