@nixxie-cms/fields-currency 1.0.1 → 2.0.0
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
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @nixxie-cms/fields-currency
|
|
2
|
+
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 450043a:
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [0fe028d]
|
|
12
|
+
- Updated dependencies [690e433]
|
|
13
|
+
- Updated dependencies [2c0d28c]
|
|
14
|
+
- Updated dependencies [450043a]
|
|
15
|
+
- @nixxie-cms/core@2.0.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IntegerFieldConfig } from '@nixxie-cms/core/fields';
|
|
2
|
-
import type {
|
|
3
|
-
export type CurrencyFieldConfig<
|
|
2
|
+
import type { BaseCollectionTypeInfo, FieldTypeFunc } from '@nixxie-cms/core/types';
|
|
3
|
+
export type CurrencyFieldConfig<CollectionTypeInfo extends BaseCollectionTypeInfo> = Omit<IntegerFieldConfig<CollectionTypeInfo>, 'validation' | 'defaultValue'> & {
|
|
4
4
|
/** ISO 4217 currency code stored only as documentation/metadata, e.g. 'USD'. Default: 'USD' */
|
|
5
5
|
currency?: string;
|
|
6
6
|
/** Allow negative amounts (e.g. refunds/credits). Default: false */
|
|
@@ -14,7 +14,7 @@ export type CurrencyFieldConfig<ListTypeInfo extends BaseListTypeInfo> = Omit<In
|
|
|
14
14
|
* A monetary field storing the amount in **minor units** (e.g. cents) as an integer, which avoids
|
|
15
15
|
* floating-point rounding errors. Format for display on the frontend with `Intl.NumberFormat`.
|
|
16
16
|
*/
|
|
17
|
-
export declare function currency<
|
|
17
|
+
export declare function currency<CollectionTypeInfo extends BaseCollectionTypeInfo>(config?: CurrencyFieldConfig<CollectionTypeInfo>): FieldTypeFunc<CollectionTypeInfo>;
|
|
18
18
|
/**
|
|
19
19
|
* Helper: format a minor-unit amount for display. When `minorUnitDigits` is omitted it is derived
|
|
20
20
|
* from the currency (2 for USD/EUR, 0 for JPY/KRW, 3 for KWD/BHD, …) so the divisor is correct for
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAEnF,MAAM,MAAM,mBAAmB,CAAC,kBAAkB,SAAS,sBAAsB,IAAI,IAAI,CACvF,kBAAkB,CAAC,kBAAkB,CAAC,EACtC,YAAY,GAAG,cAAc,CAC9B,GAAG;IACF,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,oEAAoE;IACpE,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,UAAU,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CACtC,CAAA;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,kBAAkB,SAAS,sBAAsB,EACxE,MAAM,GAAE,mBAAmB,CAAC,kBAAkB,CAAM,GACnD,aAAa,CAAC,kBAAkB,CAAC,CAYnC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,QAAQ,SAAQ,EAChB,MAAM,CAAC,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,MAAM,GACvB,MAAM,CAIR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nixxie-cms/fields-currency",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/nixxie-cms-fields-currency.cjs.js",
|
|
6
6
|
"module": "dist/nixxie-cms-fields-currency.esm.js",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"@babel/runtime": "^7.24.7"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@nixxie-cms/core": "^
|
|
19
|
+
"@nixxie-cms/core": "^2.0.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@nixxie-cms/core": "^
|
|
22
|
+
"@nixxie-cms/core": "^2.0.0"
|
|
23
23
|
},
|
|
24
24
|
"preconstruct": {
|
|
25
25
|
"entrypoints": [
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { integer } from '@nixxie-cms/core/fields'
|
|
2
2
|
import type { IntegerFieldConfig } from '@nixxie-cms/core/fields'
|
|
3
|
-
import type {
|
|
3
|
+
import type { BaseCollectionTypeInfo, FieldTypeFunc } from '@nixxie-cms/core/types'
|
|
4
4
|
|
|
5
|
-
export type CurrencyFieldConfig<
|
|
6
|
-
IntegerFieldConfig<
|
|
5
|
+
export type CurrencyFieldConfig<CollectionTypeInfo extends BaseCollectionTypeInfo> = Omit<
|
|
6
|
+
IntegerFieldConfig<CollectionTypeInfo>,
|
|
7
7
|
'validation' | 'defaultValue'
|
|
8
8
|
> & {
|
|
9
9
|
/** ISO 4217 currency code stored only as documentation/metadata, e.g. 'USD'. Default: 'USD' */
|
|
@@ -18,13 +18,13 @@ export type CurrencyFieldConfig<ListTypeInfo extends BaseListTypeInfo> = Omit<
|
|
|
18
18
|
* A monetary field storing the amount in **minor units** (e.g. cents) as an integer, which avoids
|
|
19
19
|
* floating-point rounding errors. Format for display on the frontend with `Intl.NumberFormat`.
|
|
20
20
|
*/
|
|
21
|
-
export function currency<
|
|
22
|
-
config: CurrencyFieldConfig<
|
|
23
|
-
): FieldTypeFunc<
|
|
21
|
+
export function currency<CollectionTypeInfo extends BaseCollectionTypeInfo>(
|
|
22
|
+
config: CurrencyFieldConfig<CollectionTypeInfo> = {}
|
|
23
|
+
): FieldTypeFunc<CollectionTypeInfo> {
|
|
24
24
|
const { currency = 'USD', allowNegative = false, defaultValue, validation, ...rest } = config
|
|
25
25
|
|
|
26
|
-
return integer<
|
|
27
|
-
...(rest as IntegerFieldConfig<
|
|
26
|
+
return integer<CollectionTypeInfo>({
|
|
27
|
+
...(rest as IntegerFieldConfig<CollectionTypeInfo>),
|
|
28
28
|
defaultValue: defaultValue ?? null,
|
|
29
29
|
validation: {
|
|
30
30
|
isRequired: validation?.isRequired,
|