@bessemer/cornerstone 0.5.59 → 0.5.61

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.
@@ -1,8 +1,7 @@
1
- import Zod, { ZodType } from 'zod';
2
- import { NominalType } from '@bessemer/cornerstone/types';
3
- export type AspectRatio = NominalType<string, 'AspectRatio'>;
4
- export declare const buildSchema: (fieldName?: string) => ZodType<AspectRatio>;
5
- export declare const AspectRatioSchema: Zod.ZodType<AspectRatio, Zod.ZodTypeDef, AspectRatio>;
1
+ import { ZodType } from 'zod';
2
+ import { TaggedType } from '@bessemer/cornerstone/types';
3
+ export type AspectRatio = TaggedType<string, 'AspectRatio'>;
4
+ export declare const Schema: ZodType<AspectRatio>;
6
5
  export declare const of: (aspectRatio: string) => AspectRatio;
7
6
  export declare const fromString: (aspectRatio: string) => AspectRatio;
8
7
  export declare const fromDimensions: (width: number, height: number) => AspectRatio;
@@ -1 +1 @@
1
- {"version":3,"file":"aspect-ratio.d.ts","sourceRoot":"","sources":["../src/aspect-ratio.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;AAE5D,eAAO,MAAM,WAAW,GAAI,YAAW,MAAuB,KAAG,OAAO,CAAC,WAAW,CAMnF,CAAA;AAED,eAAO,MAAM,iBAAiB,uDAAgB,CAAA;AAE9C,eAAO,MAAM,EAAE,GAAI,aAAa,MAAM,KAAG,WAExC,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,aAAa,MAAM,KAAG,WAEhD,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAG,WAK9D,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,aAAa,WAAW,KAAG,MAGvD,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,EAAE,aAAa,WAAW,KAAG,MAGzE,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,EAAE,aAAa,WAAW,KAAG,MAGzE,CAAA"}
1
+ {"version":3,"file":"aspect-ratio.d.ts","sourceRoot":"","sources":["../src/aspect-ratio.ts"],"names":[],"mappings":"AAAA,OAAY,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;AAE3D,eAAO,MAAM,MAAM,EAAE,OAAO,CAAC,WAAW,CAEyE,CAAA;AAEjH,eAAO,MAAM,EAAE,GAAI,aAAa,MAAM,KAAG,WAExC,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,aAAa,MAAM,KAAG,WAEhD,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAG,WAK9D,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,aAAa,WAAW,KAAG,MAGvD,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,EAAE,aAAa,WAAW,KAAG,MAGzE,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,EAAE,aAAa,WAAW,KAAG,MAGzE,CAAA"}
@@ -1,23 +1,18 @@
1
1
  // src/aspect-ratio.ts
2
2
  import Zod from "zod";
3
3
  import { greatestCommonFactor } from "@bessemer/cornerstone/math";
4
- var buildSchema = (fieldName = "Aspect Ratio") => {
5
- return Zod.string({
6
- required_error: `${fieldName} is required`
7
- }).trim().regex(/^[1-9]\d*:[1-9]\d*$/, `${fieldName} must be in the format 'width:height' (e.g., '16:9', '4:3')`);
8
- };
9
- var AspectRatioSchema = buildSchema();
4
+ var Schema = Zod.string().trim().regex(/^[1-9]\d*:[1-9]\d*$/, `Aspect Ratio must be in the format 'width:height' (e.g., '16:9', '4:3')`);
10
5
  var of = (aspectRatio) => {
11
6
  return aspectRatio;
12
7
  };
13
8
  var fromString = (aspectRatio) => {
14
- return AspectRatioSchema.parse(aspectRatio);
9
+ return Schema.parse(aspectRatio);
15
10
  };
16
11
  var fromDimensions = (width, height) => {
17
12
  const factor = greatestCommonFactor(width, height);
18
13
  const ratioWidth = width / factor;
19
14
  const ratioHeight = height / factor;
20
- return `${ratioWidth}:${ratioHeight}`;
15
+ return of(`${ratioWidth}:${ratioHeight}`);
21
16
  };
22
17
  var numericValue = (aspectRatio) => {
23
18
  const [width, height] = aspectRatio.split(":").map(Number);
@@ -32,8 +27,7 @@ var calculateWidth = (height, aspectRatio) => {
32
27
  return height * ratio;
33
28
  };
34
29
  export {
35
- AspectRatioSchema,
36
- buildSchema,
30
+ Schema,
37
31
  calculateHeight,
38
32
  calculateWidth,
39
33
  fromDimensions,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/aspect-ratio.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { greatestCommonFactor } from '@bessemer/cornerstone/math'\nimport { NominalType } from '@bessemer/cornerstone/types'\n\nexport type AspectRatio = NominalType<string, 'AspectRatio'>\n\nexport const buildSchema = (fieldName: string = 'Aspect Ratio'): ZodType<AspectRatio> => {\n return Zod.string({\n required_error: `${fieldName} is required`,\n })\n .trim()\n .regex(/^[1-9]\\d*:[1-9]\\d*$/, `${fieldName} must be in the format 'width:height' (e.g., '16:9', '4:3')`)\n}\n\nexport const AspectRatioSchema = buildSchema()\n\nexport const of = (aspectRatio: string): AspectRatio => {\n return aspectRatio\n}\n\nexport const fromString = (aspectRatio: string): AspectRatio => {\n return AspectRatioSchema.parse(aspectRatio)\n}\n\nexport const fromDimensions = (width: number, height: number): AspectRatio => {\n const factor = greatestCommonFactor(width, height)\n const ratioWidth = width / factor\n const ratioHeight = height / factor\n return `${ratioWidth}:${ratioHeight}`\n}\n\nexport const numericValue = (aspectRatio: AspectRatio): number => {\n const [width, height] = aspectRatio.split(':').map(Number)\n return width! / height!\n}\n\nexport const calculateHeight = (width: number, aspectRatio: AspectRatio): number => {\n const ratio = numericValue(aspectRatio)\n return width / ratio\n}\n\nexport const calculateWidth = (height: number, aspectRatio: AspectRatio): number => {\n const ratio = numericValue(aspectRatio)\n return height * ratio\n}\n"],"mappings":";AAAA,OAAO,SAAsB;AAC7B,SAAS,4BAA4B;AAK9B,IAAM,cAAc,CAAC,YAAoB,mBAAyC;AACvF,SAAO,IAAI,OAAO;AAAA,IAChB,gBAAgB,GAAG,SAAS;AAAA,EAC9B,CAAC,EACE,KAAK,EACL,MAAM,uBAAuB,GAAG,SAAS,6DAA6D;AAC3G;AAEO,IAAM,oBAAoB,YAAY;AAEtC,IAAM,KAAK,CAAC,gBAAqC;AACtD,SAAO;AACT;AAEO,IAAM,aAAa,CAAC,gBAAqC;AAC9D,SAAO,kBAAkB,MAAM,WAAW;AAC5C;AAEO,IAAM,iBAAiB,CAAC,OAAe,WAAgC;AAC5E,QAAM,SAAS,qBAAqB,OAAO,MAAM;AACjD,QAAM,aAAa,QAAQ;AAC3B,QAAM,cAAc,SAAS;AAC7B,SAAO,GAAG,UAAU,IAAI,WAAW;AACrC;AAEO,IAAM,eAAe,CAAC,gBAAqC;AAChE,QAAM,CAAC,OAAO,MAAM,IAAI,YAAY,MAAM,GAAG,EAAE,IAAI,MAAM;AACzD,SAAO,QAAS;AAClB;AAEO,IAAM,kBAAkB,CAAC,OAAe,gBAAqC;AAClF,QAAM,QAAQ,aAAa,WAAW;AACtC,SAAO,QAAQ;AACjB;AAEO,IAAM,iBAAiB,CAAC,QAAgB,gBAAqC;AAClF,QAAM,QAAQ,aAAa,WAAW;AACtC,SAAO,SAAS;AAClB;","names":[]}
1
+ {"version":3,"sources":["../src/aspect-ratio.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { greatestCommonFactor } from '@bessemer/cornerstone/math'\nimport { TaggedType } from '@bessemer/cornerstone/types'\n\nexport type AspectRatio = TaggedType<string, 'AspectRatio'>\n\nexport const Schema: ZodType<AspectRatio> = Zod.string()\n .trim()\n .regex(/^[1-9]\\d*:[1-9]\\d*$/, `Aspect Ratio must be in the format 'width:height' (e.g., '16:9', '4:3')`) as any\n\nexport const of = (aspectRatio: string): AspectRatio => {\n return aspectRatio as AspectRatio\n}\n\nexport const fromString = (aspectRatio: string): AspectRatio => {\n return Schema.parse(aspectRatio)\n}\n\nexport const fromDimensions = (width: number, height: number): AspectRatio => {\n const factor = greatestCommonFactor(width, height)\n const ratioWidth = width / factor\n const ratioHeight = height / factor\n return of(`${ratioWidth}:${ratioHeight}`)\n}\n\nexport const numericValue = (aspectRatio: AspectRatio): number => {\n const [width, height] = aspectRatio.split(':').map(Number)\n return width! / height!\n}\n\nexport const calculateHeight = (width: number, aspectRatio: AspectRatio): number => {\n const ratio = numericValue(aspectRatio)\n return width / ratio\n}\n\nexport const calculateWidth = (height: number, aspectRatio: AspectRatio): number => {\n const ratio = numericValue(aspectRatio)\n return height * ratio\n}\n"],"mappings":";AAAA,OAAO,SAAsB;AAC7B,SAAS,4BAA4B;AAK9B,IAAM,SAA+B,IAAI,OAAO,EACpD,KAAK,EACL,MAAM,uBAAuB,yEAAyE;AAElG,IAAM,KAAK,CAAC,gBAAqC;AACtD,SAAO;AACT;AAEO,IAAM,aAAa,CAAC,gBAAqC;AAC9D,SAAO,OAAO,MAAM,WAAW;AACjC;AAEO,IAAM,iBAAiB,CAAC,OAAe,WAAgC;AAC5E,QAAM,SAAS,qBAAqB,OAAO,MAAM;AACjD,QAAM,aAAa,QAAQ;AAC3B,QAAM,cAAc,SAAS;AAC7B,SAAO,GAAG,GAAG,UAAU,IAAI,WAAW,EAAE;AAC1C;AAEO,IAAM,eAAe,CAAC,gBAAqC;AAChE,QAAM,CAAC,OAAO,MAAM,IAAI,YAAY,MAAM,GAAG,EAAE,IAAI,MAAM;AACzD,SAAO,QAAS;AAClB;AAEO,IAAM,kBAAkB,CAAC,OAAe,gBAAqC;AAClF,QAAM,QAAQ,aAAa,WAAW;AACtC,SAAO,QAAQ;AACjB;AAEO,IAAM,iBAAiB,CAAC,QAAgB,gBAAqC;AAClF,QAAM,QAAQ,aAAa,WAAW;AACtC,SAAO,SAAS;AAClB;","names":[]}
@@ -1,35 +1,4 @@
1
- import Zod, { ZodType } from 'zod';
2
- export declare const schema: <T extends ZodType>(type: T) => Zod.ZodObject<{
3
- isSuccess: Zod.ZodBoolean;
4
- isError: Zod.ZodBoolean;
5
- isLoading: Zod.ZodBoolean;
6
- isFetching: Zod.ZodBoolean;
7
- data: Zod.ZodUnion<[T, Zod.ZodUnknown]>;
8
- }, "strip", Zod.ZodTypeAny, Zod.objectUtil.addQuestionMarks<Zod.baseObjectOutputType<{
9
- isSuccess: Zod.ZodBoolean;
10
- isError: Zod.ZodBoolean;
11
- isLoading: Zod.ZodBoolean;
12
- isFetching: Zod.ZodBoolean;
13
- data: Zod.ZodUnion<[T, Zod.ZodUnknown]>;
14
- }>, any> extends infer T_1 ? { [k in keyof T_1]: Zod.objectUtil.addQuestionMarks<Zod.baseObjectOutputType<{
15
- isSuccess: Zod.ZodBoolean;
16
- isError: Zod.ZodBoolean;
17
- isLoading: Zod.ZodBoolean;
18
- isFetching: Zod.ZodBoolean;
19
- data: Zod.ZodUnion<[T, Zod.ZodUnknown]>;
20
- }>, any>[k]; } : never, Zod.baseObjectInputType<{
21
- isSuccess: Zod.ZodBoolean;
22
- isError: Zod.ZodBoolean;
23
- isLoading: Zod.ZodBoolean;
24
- isFetching: Zod.ZodBoolean;
25
- data: Zod.ZodUnion<[T, Zod.ZodUnknown]>;
26
- }> extends infer T_2 ? { [k_1 in keyof T_2]: Zod.baseObjectInputType<{
27
- isSuccess: Zod.ZodBoolean;
28
- isError: Zod.ZodBoolean;
29
- isLoading: Zod.ZodBoolean;
30
- isFetching: Zod.ZodBoolean;
31
- data: Zod.ZodUnion<[T, Zod.ZodUnknown]>;
32
- }>[k_1]; } : never>;
1
+ import { ZodType } from 'zod';
33
2
  export type PendingValue = {
34
3
  isSuccess: false;
35
4
  isError: false;
@@ -73,6 +42,7 @@ export type SettledValue<T> = {
73
42
  data: T;
74
43
  };
75
44
  export type AsyncValue<T> = PendingValue | LoadingValue | ErrorValue | FetchingValueSuccess<T> | FetchingValueError | SettledValue<T>;
45
+ export declare const schema: <T>(_: ZodType<T>) => ZodType<AsyncValue<T>>;
76
46
  export declare const isSettled: <T>(value: AsyncValue<T>) => value is SettledValue<T>;
77
47
  export declare const loading: () => LoadingValue;
78
48
  export declare const fetching: <T>(data: T) => FetchingValueSuccess<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"async-value.d.ts","sourceRoot":"","sources":["../src/async-value.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAGlC,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAQhD,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,EAAE,KAAK,CAAA;IAChB,OAAO,EAAE,KAAK,CAAA;IACd,SAAS,EAAE,KAAK,CAAA;IAChB,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,EAAE,KAAK,CAAA;IAChB,OAAO,EAAE,KAAK,CAAA;IACd,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,KAAK,CAAA;IAChB,OAAO,EAAE,IAAI,CAAA;IACb,SAAS,EAAE,KAAK,CAAA;IAChB,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,OAAO,CAAA;CACd,CAAA;AAED,MAAM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AAC,CAAC,GAAG,IAAI,CAAC,EAC3B,UAAU;IAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAAC,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAA;CAAE,KACrG,CAYF,CAAA;AAED,eAAO,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAG,UAAU,CAAC,CAAC,CAMrF,CAAA"}
@@ -1,13 +1,13 @@
1
1
  // src/async-value.ts
2
2
  import Zod from "zod";
3
3
  import { Objects } from "@bessemer/cornerstone/index";
4
- var schema = (type) => {
4
+ var schema = (_) => {
5
5
  return Zod.object({
6
6
  isSuccess: Zod.boolean(),
7
7
  isError: Zod.boolean(),
8
8
  isLoading: Zod.boolean(),
9
9
  isFetching: Zod.boolean(),
10
- data: Zod.union([type, Zod.unknown()])
10
+ data: Zod.unknown()
11
11
  });
12
12
  };
13
13
  var isSettled = (value) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/async-value.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { Objects } from '@bessemer/cornerstone/index'\n\nexport const schema = <T extends ZodType>(type: T) => {\n return Zod.object({\n isSuccess: Zod.boolean(),\n isError: Zod.boolean(),\n isLoading: Zod.boolean(),\n isFetching: Zod.boolean(),\n data: Zod.union([type, Zod.unknown()]),\n })\n}\n\nexport type PendingValue = {\n isSuccess: false\n isError: false\n isLoading: false\n isFetching: boolean\n data: undefined\n}\n\nexport type LoadingValue = {\n isSuccess: false\n isError: false\n isLoading: true\n isFetching: boolean\n data: undefined\n}\n\nexport type ErrorValue = {\n isSuccess: false\n isError: true\n isLoading: false\n isFetching: boolean\n data: unknown\n}\n\nexport type FetchingValueSuccess<T> = {\n isSuccess: true\n isError: false\n isLoading: false\n isFetching: true\n data: T\n}\n\nexport type FetchingValueError = {\n isSuccess: false\n isError: true\n isLoading: false\n isFetching: true\n data: unknown\n}\n\nexport type SettledValue<T> = {\n isSuccess: true\n isError: false\n isLoading: false\n isFetching: false\n data: T\n}\n\nexport type AsyncValue<T> = PendingValue | LoadingValue | ErrorValue | FetchingValueSuccess<T> | FetchingValueError | SettledValue<T>\n\nexport const isSettled = <T>(value: AsyncValue<T>): value is SettledValue<T> => {\n return value.isSuccess && !value.isError && !value.isLoading && !value.isFetching\n}\n\nexport const loading = (): LoadingValue => ({ isSuccess: false, isError: false, isLoading: true, isFetching: true, data: undefined })\n\nexport const fetching = <T>(data: T): FetchingValueSuccess<T> => ({\n isSuccess: true,\n isError: false,\n isLoading: false,\n isFetching: true,\n data,\n})\n\nexport const settled = <T>(data: T): SettledValue<T> => ({ isSuccess: true, isError: false, isLoading: false, isFetching: false, data })\n\nexport const error = (error: unknown): ErrorValue => ({ isSuccess: false, isError: true, isLoading: false, isFetching: false, data: error })\n\nexport const handle = <T, N>(\n value: AsyncValue<T | null>,\n handlers: { loading: () => N; error: (error: unknown) => N; absent: () => N; success: (data: T) => N }\n): N => {\n if (value.isLoading || (value.isError && value.isFetching)) {\n return handlers.loading()\n }\n if (value.isError) {\n return handlers.error(value.data)\n }\n if (Objects.isNil(value.data)) {\n return handlers.absent()\n }\n\n return handlers.success(value.data)\n}\n\nexport const map = <T, N>(value: AsyncValue<T>, mapper: (value: T) => N): AsyncValue<N> => {\n if (!value.isSuccess) {\n return value\n }\n\n return { ...value, data: mapper(value.data) }\n}\n"],"mappings":";AAAA,OAAO,SAAsB;AAC7B,SAAS,eAAe;AAEjB,IAAM,SAAS,CAAoB,SAAY;AACpD,SAAO,IAAI,OAAO;AAAA,IAChB,WAAW,IAAI,QAAQ;AAAA,IACvB,SAAS,IAAI,QAAQ;AAAA,IACrB,WAAW,IAAI,QAAQ;AAAA,IACvB,YAAY,IAAI,QAAQ;AAAA,IACxB,MAAM,IAAI,MAAM,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC;AAAA,EACvC,CAAC;AACH;AAoDO,IAAM,YAAY,CAAI,UAAmD;AAC9E,SAAO,MAAM,aAAa,CAAC,MAAM,WAAW,CAAC,MAAM,aAAa,CAAC,MAAM;AACzE;AAEO,IAAM,UAAU,OAAqB,EAAE,WAAW,OAAO,SAAS,OAAO,WAAW,MAAM,YAAY,MAAM,MAAM,OAAU;AAE5H,IAAM,WAAW,CAAI,UAAsC;AAAA,EAChE,WAAW;AAAA,EACX,SAAS;AAAA,EACT,WAAW;AAAA,EACX,YAAY;AAAA,EACZ;AACF;AAEO,IAAM,UAAU,CAAI,UAA8B,EAAE,WAAW,MAAM,SAAS,OAAO,WAAW,OAAO,YAAY,OAAO,KAAK;AAE/H,IAAM,QAAQ,CAACA,YAAgC,EAAE,WAAW,OAAO,SAAS,MAAM,WAAW,OAAO,YAAY,OAAO,MAAMA,OAAM;AAEnI,IAAM,SAAS,CACpB,OACA,aACM;AACN,MAAI,MAAM,aAAc,MAAM,WAAW,MAAM,YAAa;AAC1D,WAAO,SAAS,QAAQ;AAAA,EAC1B;AACA,MAAI,MAAM,SAAS;AACjB,WAAO,SAAS,MAAM,MAAM,IAAI;AAAA,EAClC;AACA,MAAI,QAAQ,MAAM,MAAM,IAAI,GAAG;AAC7B,WAAO,SAAS,OAAO;AAAA,EACzB;AAEA,SAAO,SAAS,QAAQ,MAAM,IAAI;AACpC;AAEO,IAAM,MAAM,CAAO,OAAsB,WAA2C;AACzF,MAAI,CAAC,MAAM,WAAW;AACpB,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,GAAG,OAAO,MAAM,OAAO,MAAM,IAAI,EAAE;AAC9C;","names":["error"]}
1
+ {"version":3,"sources":["../src/async-value.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { Objects } from '@bessemer/cornerstone/index'\n\nexport type PendingValue = {\n isSuccess: false\n isError: false\n isLoading: false\n isFetching: boolean\n data: undefined\n}\n\nexport type LoadingValue = {\n isSuccess: false\n isError: false\n isLoading: true\n isFetching: boolean\n data: undefined\n}\n\nexport type ErrorValue = {\n isSuccess: false\n isError: true\n isLoading: false\n isFetching: boolean\n data: unknown\n}\n\nexport type FetchingValueSuccess<T> = {\n isSuccess: true\n isError: false\n isLoading: false\n isFetching: true\n data: T\n}\n\nexport type FetchingValueError = {\n isSuccess: false\n isError: true\n isLoading: false\n isFetching: true\n data: unknown\n}\n\nexport type SettledValue<T> = {\n isSuccess: true\n isError: false\n isLoading: false\n isFetching: false\n data: T\n}\n\nexport type AsyncValue<T> = PendingValue | LoadingValue | ErrorValue | FetchingValueSuccess<T> | FetchingValueError | SettledValue<T>\n\nexport const schema = <T>(_: ZodType<T>): ZodType<AsyncValue<T>> => {\n return Zod.object({\n isSuccess: Zod.boolean(),\n isError: Zod.boolean(),\n isLoading: Zod.boolean(),\n isFetching: Zod.boolean(),\n data: Zod.unknown(),\n }) as any\n}\n\nexport const isSettled = <T>(value: AsyncValue<T>): value is SettledValue<T> => {\n return value.isSuccess && !value.isError && !value.isLoading && !value.isFetching\n}\n\nexport const loading = (): LoadingValue => ({ isSuccess: false, isError: false, isLoading: true, isFetching: true, data: undefined })\n\nexport const fetching = <T>(data: T): FetchingValueSuccess<T> => ({\n isSuccess: true,\n isError: false,\n isLoading: false,\n isFetching: true,\n data,\n})\n\nexport const settled = <T>(data: T): SettledValue<T> => ({ isSuccess: true, isError: false, isLoading: false, isFetching: false, data })\n\nexport const error = (error: unknown): ErrorValue => ({ isSuccess: false, isError: true, isLoading: false, isFetching: false, data: error })\n\nexport const handle = <T, N>(\n value: AsyncValue<T | null>,\n handlers: { loading: () => N; error: (error: unknown) => N; absent: () => N; success: (data: T) => N }\n): N => {\n if (value.isLoading || (value.isError && value.isFetching)) {\n return handlers.loading()\n }\n if (value.isError) {\n return handlers.error(value.data)\n }\n if (Objects.isNil(value.data)) {\n return handlers.absent()\n }\n\n return handlers.success(value.data)\n}\n\nexport const map = <T, N>(value: AsyncValue<T>, mapper: (value: T) => N): AsyncValue<N> => {\n if (!value.isSuccess) {\n return value\n }\n\n return { ...value, data: mapper(value.data) }\n}\n"],"mappings":";AAAA,OAAO,SAAsB;AAC7B,SAAS,eAAe;AAoDjB,IAAM,SAAS,CAAI,MAA0C;AAClE,SAAO,IAAI,OAAO;AAAA,IAChB,WAAW,IAAI,QAAQ;AAAA,IACvB,SAAS,IAAI,QAAQ;AAAA,IACrB,WAAW,IAAI,QAAQ;AAAA,IACvB,YAAY,IAAI,QAAQ;AAAA,IACxB,MAAM,IAAI,QAAQ;AAAA,EACpB,CAAC;AACH;AAEO,IAAM,YAAY,CAAI,UAAmD;AAC9E,SAAO,MAAM,aAAa,CAAC,MAAM,WAAW,CAAC,MAAM,aAAa,CAAC,MAAM;AACzE;AAEO,IAAM,UAAU,OAAqB,EAAE,WAAW,OAAO,SAAS,OAAO,WAAW,MAAM,YAAY,MAAM,MAAM,OAAU;AAE5H,IAAM,WAAW,CAAI,UAAsC;AAAA,EAChE,WAAW;AAAA,EACX,SAAS;AAAA,EACT,WAAW;AAAA,EACX,YAAY;AAAA,EACZ;AACF;AAEO,IAAM,UAAU,CAAI,UAA8B,EAAE,WAAW,MAAM,SAAS,OAAO,WAAW,OAAO,YAAY,OAAO,KAAK;AAE/H,IAAM,QAAQ,CAACA,YAAgC,EAAE,WAAW,OAAO,SAAS,MAAM,WAAW,OAAO,YAAY,OAAO,MAAMA,OAAM;AAEnI,IAAM,SAAS,CACpB,OACA,aACM;AACN,MAAI,MAAM,aAAc,MAAM,WAAW,MAAM,YAAa;AAC1D,WAAO,SAAS,QAAQ;AAAA,EAC1B;AACA,MAAI,MAAM,SAAS;AACjB,WAAO,SAAS,MAAM,MAAM,IAAI;AAAA,EAClC;AACA,MAAI,QAAQ,MAAM,MAAM,IAAI,GAAG;AAC7B,WAAO,SAAS,OAAO;AAAA,EACzB;AAEA,SAAO,SAAS,QAAQ,MAAM,IAAI;AACpC;AAEO,IAAM,MAAM,CAAO,OAAsB,WAA2C;AACzF,MAAI,CAAC,MAAM,WAAW;AACpB,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,GAAG,OAAO,MAAM,OAAO,MAAM,IAAI,EAAE;AAC9C;","names":["error"]}
@@ -0,0 +1,13 @@
1
+ import { TaggedType } from '@bessemer/cornerstone/types';
2
+ import { ZodType } from 'zod';
3
+ export type CurrencyCode = TaggedType<string, 'CurrencyCode'>;
4
+ export declare const Schema: ZodType<CurrencyCode>;
5
+ export declare const of: (value: string) => CurrencyCode;
6
+ export declare const fromString: (value: string) => CurrencyCode;
7
+ export declare const USD: CurrencyCode;
8
+ export declare const EUR: CurrencyCode;
9
+ export declare const GBP: CurrencyCode;
10
+ export declare const JPY: CurrencyCode;
11
+ export declare const CAD: CurrencyCode;
12
+ export declare const AUD: CurrencyCode;
13
+ //# sourceMappingURL=currency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAY,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAElC,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AAC7D,eAAO,MAAM,MAAM,EAAE,OAAO,CAAC,YAAY,CAGM,CAAA;AAE/C,eAAO,MAAM,EAAE,GAAI,OAAO,MAAM,KAAG,YAElC,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,YAE1C,CAAA;AAED,eAAO,MAAM,GAAG,cAAY,CAAA;AAC5B,eAAO,MAAM,GAAG,cAAY,CAAA;AAC5B,eAAO,MAAM,GAAG,cAAY,CAAA;AAC5B,eAAO,MAAM,GAAG,cAAY,CAAA;AAC5B,eAAO,MAAM,GAAG,cAAY,CAAA;AAC5B,eAAO,MAAM,GAAG,cAAY,CAAA"}
@@ -0,0 +1,27 @@
1
+ // src/currency.ts
2
+ import Zod from "zod";
3
+ var Schema = Zod.string().trim().regex(/^[a-zA-Z]{3}$/, "Currency Code must be exactly 3 letters").transform((val) => val.toUpperCase());
4
+ var of = (value) => {
5
+ return value;
6
+ };
7
+ var fromString = (value) => {
8
+ return Schema.parse(value);
9
+ };
10
+ var USD = of("USD");
11
+ var EUR = of("EUR");
12
+ var GBP = of("GBP");
13
+ var JPY = of("JPY");
14
+ var CAD = of("CAD");
15
+ var AUD = of("AUD");
16
+ export {
17
+ AUD,
18
+ CAD,
19
+ EUR,
20
+ GBP,
21
+ JPY,
22
+ Schema,
23
+ USD,
24
+ fromString,
25
+ of
26
+ };
27
+ //# sourceMappingURL=currency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/currency.ts"],"sourcesContent":["import { TaggedType } from '@bessemer/cornerstone/types'\nimport Zod, { ZodType } from 'zod'\n\nexport type CurrencyCode = TaggedType<string, 'CurrencyCode'>\nexport const Schema: ZodType<CurrencyCode> = Zod.string()\n .trim()\n .regex(/^[a-zA-Z]{3}$/, 'Currency Code must be exactly 3 letters')\n .transform((val) => val.toUpperCase()) as any\n\nexport const of = (value: string): CurrencyCode => {\n return value as CurrencyCode\n}\n\nexport const fromString = (value: string): CurrencyCode => {\n return Schema.parse(value)\n}\n\nexport const USD = of('USD')\nexport const EUR = of('EUR')\nexport const GBP = of('GBP')\nexport const JPY = of('JPY')\nexport const CAD = of('CAD')\nexport const AUD = of('AUD')\n"],"mappings":";AACA,OAAO,SAAsB;AAGtB,IAAM,SAAgC,IAAI,OAAO,EACrD,KAAK,EACL,MAAM,iBAAiB,yCAAyC,EAChE,UAAU,CAAC,QAAQ,IAAI,YAAY,CAAC;AAEhC,IAAM,KAAK,CAAC,UAAgC;AACjD,SAAO;AACT;AAEO,IAAM,aAAa,CAAC,UAAgC;AACzD,SAAO,OAAO,MAAM,KAAK;AAC3B;AAEO,IAAM,MAAM,GAAG,KAAK;AACpB,IAAM,MAAM,GAAG,KAAK;AACpB,IAAM,MAAM,GAAG,KAAK;AACpB,IAAM,MAAM,GAAG,KAAK;AACpB,IAAM,MAAM,GAAG,KAAK;AACpB,IAAM,MAAM,GAAG,KAAK;","names":[]}
package/dist/index.d.ts CHANGED
@@ -43,5 +43,7 @@ import * as Json from '@bessemer/cornerstone/json';
43
43
  import * as AspectRatios from '@bessemer/cornerstone/aspect-ratio';
44
44
  import * as DataSizes from '@bessemer/cornerstone/data-size';
45
45
  import * as MimeTypes from '@bessemer/cornerstone/mime-type';
46
- export { Objects, Functions, Arrays, Strings, Async, AsyncValues, Maths, Sets, Dates, Comparators, Equalitors, Durations, Uris, Urls, Loggers, Errors, ErrorEvents, Assertions, Uuids, Ulids, Entries, Hashes, Crypto, Globs, Ranges, ZodUtil, Tags, Promises, References, Signatures, Eithers, Results, Lazy, Patches, Content, Combinables, Properties, RichTexts, Retry, Stores, Misc, Json, AspectRatios, DataSizes, MimeTypes, };
46
+ import * as Currencies from '@bessemer/cornerstone/currency';
47
+ import * as MonetaryAmounts from '@bessemer/cornerstone/monetary-amount';
48
+ export { Objects, Functions, Arrays, Strings, Async, AsyncValues, Maths, Sets, Dates, Comparators, Equalitors, Durations, Uris, Urls, Loggers, Errors, ErrorEvents, Assertions, Uuids, Ulids, Entries, Hashes, Crypto, Globs, Ranges, ZodUtil, Tags, Promises, References, Signatures, Eithers, Results, Lazy, Patches, Content, Combinables, Properties, RichTexts, Retry, Stores, Misc, Json, AspectRatios, DataSizes, MimeTypes, Currencies, MonetaryAmounts, };
47
49
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,8BAA8B,CAAA;AACvD,OAAO,KAAK,SAAS,MAAM,gCAAgC,CAAA;AAC3D,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAA;AACrD,OAAO,KAAK,OAAO,MAAM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EACJ,OAAO,EACP,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EACT,KAAK,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,SAAS,EACT,UAAU,EACV,eAAe,GAChB,CAAA"}
package/dist/index.js CHANGED
@@ -44,6 +44,8 @@ import * as Json from "@bessemer/cornerstone/json";
44
44
  import * as AspectRatios from "@bessemer/cornerstone/aspect-ratio";
45
45
  import * as DataSizes from "@bessemer/cornerstone/data-size";
46
46
  import * as MimeTypes from "@bessemer/cornerstone/mime-type";
47
+ import * as Currencies from "@bessemer/cornerstone/currency";
48
+ import * as MonetaryAmounts from "@bessemer/cornerstone/monetary-amount";
47
49
  export {
48
50
  Arrays,
49
51
  AspectRatios,
@@ -54,6 +56,7 @@ export {
54
56
  Comparators,
55
57
  Content,
56
58
  Crypto,
59
+ Currencies,
57
60
  DataSizes,
58
61
  Dates,
59
62
  Durations,
@@ -71,6 +74,7 @@ export {
71
74
  Maths,
72
75
  MimeTypes,
73
76
  Misc,
77
+ MonetaryAmounts,
74
78
  Objects,
75
79
  Patches,
76
80
  Promises,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import * as Objects from '@bessemer/cornerstone/object'\nimport * as Functions from '@bessemer/cornerstone/function'\nimport * as Arrays from '@bessemer/cornerstone/array'\nimport * as Strings from '@bessemer/cornerstone/string'\nimport * as Async from '@bessemer/cornerstone/async'\nimport * as AsyncValues from '@bessemer/cornerstone/async-value'\nimport * as Maths from '@bessemer/cornerstone/math'\nimport * as Sets from '@bessemer/cornerstone/set'\nimport * as Dates from '@bessemer/cornerstone/date'\nimport * as Comparators from '@bessemer/cornerstone/comparator'\nimport * as Equalitors from '@bessemer/cornerstone/equalitor'\nimport * as Durations from '@bessemer/cornerstone/duration'\nimport * as Uris from '@bessemer/cornerstone/uri'\nimport * as Urls from '@bessemer/cornerstone/url'\nimport * as Loggers from '@bessemer/cornerstone/logger'\nimport * as Errors from '@bessemer/cornerstone/error'\nimport * as ErrorEvents from '@bessemer/cornerstone/error-event'\nimport * as Assertions from '@bessemer/cornerstone/assertion'\nimport * as Uuids from '@bessemer/cornerstone/uuid'\nimport * as Ulids from '@bessemer/cornerstone/ulid'\nimport * as Entries from '@bessemer/cornerstone/entry'\nimport * as Hashes from '@bessemer/cornerstone/hash'\nimport * as Crypto from '@bessemer/cornerstone/crypto'\nimport * as Globs from '@bessemer/cornerstone/glob'\nimport * as Ranges from '@bessemer/cornerstone/range'\n\nimport * as ZodUtil from '@bessemer/cornerstone/zod-util'\nimport * as Tags from '@bessemer/cornerstone/tag'\nimport * as Promises from '@bessemer/cornerstone/promise'\nimport * as References from '@bessemer/cornerstone/reference'\nimport * as Signatures from '@bessemer/cornerstone/signature'\nimport * as Eithers from '@bessemer/cornerstone/either'\nimport * as Results from '@bessemer/cornerstone/result'\nimport * as Lazy from '@bessemer/cornerstone/lazy'\nimport * as Patches from '@bessemer/cornerstone/patch'\nimport * as Content from '@bessemer/cornerstone/content'\nimport * as Combinables from '@bessemer/cornerstone/combinable'\nimport * as Properties from '@bessemer/cornerstone/property'\nimport * as RichTexts from '@bessemer/cornerstone/rich-text'\nimport * as Retry from '@bessemer/cornerstone/retry'\nimport * as Stores from '@bessemer/cornerstone/store'\nimport * as Misc from '@bessemer/cornerstone/misc'\nimport * as Json from '@bessemer/cornerstone/json'\nimport * as AspectRatios from '@bessemer/cornerstone/aspect-ratio'\nimport * as DataSizes from '@bessemer/cornerstone/data-size'\nimport * as MimeTypes from '@bessemer/cornerstone/mime-type'\n\nexport {\n Objects,\n Functions,\n Arrays,\n Strings,\n Async,\n AsyncValues,\n Maths,\n Sets,\n Dates,\n Comparators,\n Equalitors,\n Durations,\n Uris,\n Urls,\n Loggers,\n Errors,\n ErrorEvents,\n Assertions,\n Uuids,\n Ulids,\n Entries,\n Hashes,\n Crypto,\n Globs,\n Ranges,\n ZodUtil,\n Tags,\n Promises,\n References,\n Signatures,\n Eithers,\n Results,\n Lazy,\n Patches,\n Content,\n Combinables,\n Properties,\n RichTexts,\n Retry,\n Stores,\n Misc,\n Json,\n AspectRatios,\n DataSizes,\n MimeTypes,\n}\n"],"mappings":";AAAA,YAAY,aAAa;AACzB,YAAY,eAAe;AAC3B,YAAY,YAAY;AACxB,YAAY,aAAa;AACzB,YAAY,WAAW;AACvB,YAAY,iBAAiB;AAC7B,YAAY,WAAW;AACvB,YAAY,UAAU;AACtB,YAAY,WAAW;AACvB,YAAY,iBAAiB;AAC7B,YAAY,gBAAgB;AAC5B,YAAY,eAAe;AAC3B,YAAY,UAAU;AACtB,YAAY,UAAU;AACtB,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,iBAAiB;AAC7B,YAAY,gBAAgB;AAC5B,YAAY,WAAW;AACvB,YAAY,WAAW;AACvB,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,YAAY;AACxB,YAAY,WAAW;AACvB,YAAY,YAAY;AAExB,YAAY,aAAa;AACzB,YAAY,UAAU;AACtB,YAAY,cAAc;AAC1B,YAAY,gBAAgB;AAC5B,YAAY,gBAAgB;AAC5B,YAAY,aAAa;AACzB,YAAY,aAAa;AACzB,YAAY,UAAU;AACtB,YAAY,aAAa;AACzB,YAAY,aAAa;AACzB,YAAY,iBAAiB;AAC7B,YAAY,gBAAgB;AAC5B,YAAY,eAAe;AAC3B,YAAY,WAAW;AACvB,YAAY,YAAY;AACxB,YAAY,UAAU;AACtB,YAAY,UAAU;AACtB,YAAY,kBAAkB;AAC9B,YAAY,eAAe;AAC3B,YAAY,eAAe;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import * as Objects from '@bessemer/cornerstone/object'\nimport * as Functions from '@bessemer/cornerstone/function'\nimport * as Arrays from '@bessemer/cornerstone/array'\nimport * as Strings from '@bessemer/cornerstone/string'\nimport * as Async from '@bessemer/cornerstone/async'\nimport * as AsyncValues from '@bessemer/cornerstone/async-value'\nimport * as Maths from '@bessemer/cornerstone/math'\nimport * as Sets from '@bessemer/cornerstone/set'\nimport * as Dates from '@bessemer/cornerstone/date'\nimport * as Comparators from '@bessemer/cornerstone/comparator'\nimport * as Equalitors from '@bessemer/cornerstone/equalitor'\nimport * as Durations from '@bessemer/cornerstone/duration'\nimport * as Uris from '@bessemer/cornerstone/uri'\nimport * as Urls from '@bessemer/cornerstone/url'\nimport * as Loggers from '@bessemer/cornerstone/logger'\nimport * as Errors from '@bessemer/cornerstone/error'\nimport * as ErrorEvents from '@bessemer/cornerstone/error-event'\nimport * as Assertions from '@bessemer/cornerstone/assertion'\nimport * as Uuids from '@bessemer/cornerstone/uuid'\nimport * as Ulids from '@bessemer/cornerstone/ulid'\nimport * as Entries from '@bessemer/cornerstone/entry'\nimport * as Hashes from '@bessemer/cornerstone/hash'\nimport * as Crypto from '@bessemer/cornerstone/crypto'\nimport * as Globs from '@bessemer/cornerstone/glob'\nimport * as Ranges from '@bessemer/cornerstone/range'\n\nimport * as ZodUtil from '@bessemer/cornerstone/zod-util'\nimport * as Tags from '@bessemer/cornerstone/tag'\nimport * as Promises from '@bessemer/cornerstone/promise'\nimport * as References from '@bessemer/cornerstone/reference'\nimport * as Signatures from '@bessemer/cornerstone/signature'\nimport * as Eithers from '@bessemer/cornerstone/either'\nimport * as Results from '@bessemer/cornerstone/result'\nimport * as Lazy from '@bessemer/cornerstone/lazy'\nimport * as Patches from '@bessemer/cornerstone/patch'\nimport * as Content from '@bessemer/cornerstone/content'\nimport * as Combinables from '@bessemer/cornerstone/combinable'\nimport * as Properties from '@bessemer/cornerstone/property'\nimport * as RichTexts from '@bessemer/cornerstone/rich-text'\nimport * as Retry from '@bessemer/cornerstone/retry'\nimport * as Stores from '@bessemer/cornerstone/store'\nimport * as Misc from '@bessemer/cornerstone/misc'\nimport * as Json from '@bessemer/cornerstone/json'\nimport * as AspectRatios from '@bessemer/cornerstone/aspect-ratio'\nimport * as DataSizes from '@bessemer/cornerstone/data-size'\nimport * as MimeTypes from '@bessemer/cornerstone/mime-type'\nimport * as Currencies from '@bessemer/cornerstone/currency'\nimport * as MonetaryAmounts from '@bessemer/cornerstone/monetary-amount'\n\nexport {\n Objects,\n Functions,\n Arrays,\n Strings,\n Async,\n AsyncValues,\n Maths,\n Sets,\n Dates,\n Comparators,\n Equalitors,\n Durations,\n Uris,\n Urls,\n Loggers,\n Errors,\n ErrorEvents,\n Assertions,\n Uuids,\n Ulids,\n Entries,\n Hashes,\n Crypto,\n Globs,\n Ranges,\n ZodUtil,\n Tags,\n Promises,\n References,\n Signatures,\n Eithers,\n Results,\n Lazy,\n Patches,\n Content,\n Combinables,\n Properties,\n RichTexts,\n Retry,\n Stores,\n Misc,\n Json,\n AspectRatios,\n DataSizes,\n MimeTypes,\n Currencies,\n MonetaryAmounts,\n}\n"],"mappings":";AAAA,YAAY,aAAa;AACzB,YAAY,eAAe;AAC3B,YAAY,YAAY;AACxB,YAAY,aAAa;AACzB,YAAY,WAAW;AACvB,YAAY,iBAAiB;AAC7B,YAAY,WAAW;AACvB,YAAY,UAAU;AACtB,YAAY,WAAW;AACvB,YAAY,iBAAiB;AAC7B,YAAY,gBAAgB;AAC5B,YAAY,eAAe;AAC3B,YAAY,UAAU;AACtB,YAAY,UAAU;AACtB,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,iBAAiB;AAC7B,YAAY,gBAAgB;AAC5B,YAAY,WAAW;AACvB,YAAY,WAAW;AACvB,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,YAAY;AACxB,YAAY,WAAW;AACvB,YAAY,YAAY;AAExB,YAAY,aAAa;AACzB,YAAY,UAAU;AACtB,YAAY,cAAc;AAC1B,YAAY,gBAAgB;AAC5B,YAAY,gBAAgB;AAC5B,YAAY,aAAa;AACzB,YAAY,aAAa;AACzB,YAAY,UAAU;AACtB,YAAY,aAAa;AACzB,YAAY,aAAa;AACzB,YAAY,iBAAiB;AAC7B,YAAY,gBAAgB;AAC5B,YAAY,eAAe;AAC3B,YAAY,WAAW;AACvB,YAAY,YAAY;AACxB,YAAY,UAAU;AACtB,YAAY,UAAU;AACtB,YAAY,kBAAkB;AAC9B,YAAY,eAAe;AAC3B,YAAY,eAAe;AAC3B,YAAY,gBAAgB;AAC5B,YAAY,qBAAqB;","names":[]}
@@ -0,0 +1,27 @@
1
+ import { CurrencyCode } from '@bessemer/cornerstone/currency';
2
+ import { ZodType } from 'zod';
3
+ export type MonetaryAmount = {
4
+ amount: number;
5
+ currency: CurrencyCode;
6
+ };
7
+ export declare const Schema: ZodType<MonetaryAmount>;
8
+ export declare const of: (amount: number, currency: CurrencyCode) => MonetaryAmount;
9
+ export declare const zero: (currency: CurrencyCode) => MonetaryAmount;
10
+ export declare const apply: <T>(first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => T) => T;
11
+ export declare const operate: (first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => number) => MonetaryAmount;
12
+ /** Determines whether two MonetaryAmounts are considered equivalent */
13
+ export declare const equal: (first?: MonetaryAmount | null, second?: MonetaryAmount | null) => boolean;
14
+ export declare const sum: (first: MonetaryAmount, second?: MonetaryAmount | null) => MonetaryAmount;
15
+ export declare const subtract: (first: MonetaryAmount, second: MonetaryAmount) => MonetaryAmount;
16
+ export declare const multiply: (money: MonetaryAmount, value: number) => MonetaryAmount;
17
+ export declare const divide: (money: MonetaryAmount, value: number) => MonetaryAmount;
18
+ export declare function sumAll(monetaryAmounts: [MonetaryAmount, ...MonetaryAmount[]]): MonetaryAmount;
19
+ export declare function sumAll(monetaryAmounts: Array<MonetaryAmount>): MonetaryAmount | null;
20
+ export declare const negate: (monetaryAmount: MonetaryAmount) => MonetaryAmount;
21
+ export declare const isZero: (monetaryAmount: MonetaryAmount) => boolean;
22
+ export declare const greaterThan: (first: MonetaryAmount, second: MonetaryAmount) => boolean;
23
+ export type MonetaryAmountFormatOptions = {
24
+ hideCents?: boolean;
25
+ };
26
+ export declare const format: (amount: MonetaryAmount, alpha2Code: string, options?: MonetaryAmountFormatOptions) => string;
27
+ //# sourceMappingURL=monetary-amount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monetary-amount.d.ts","sourceRoot":"","sources":["../src/monetary-amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgC,MAAM,gCAAgC,CAAA;AAC3F,OAAY,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAMlC,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,YAAY,CAAA;CACvB,CAAA;AACD,eAAO,MAAM,MAAM,EAAE,OAAO,CAAC,cAAc,CAGzC,CAAA;AAEF,eAAO,MAAM,EAAE,GAAI,QAAQ,MAAM,EAAE,UAAU,YAAY,KAAG,cAG3D,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,UAAU,YAAY,KAAG,cAE7C,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,OAAO,cAAc,EAAE,QAAQ,cAAc,EAAE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC,KAAG,CAMxH,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,OAAO,cAAc,EAAE,QAAQ,cAAc,EAAE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,KAAG,cAE5H,CAAA;AAED,uEAAuE;AACvE,eAAO,MAAM,KAAK,GAAI,QAAQ,cAAc,GAAG,IAAI,EAAE,SAAS,cAAc,GAAG,IAAI,KAAG,OASrF,CAAA;AAED,eAAO,MAAM,GAAG,GAAI,OAAO,cAAc,EAAE,SAAS,cAAc,GAAG,IAAI,KAAG,cAE3E,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,cAAc,EAAE,QAAQ,cAAc,KAAG,cAExE,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,cAAc,EAAE,OAAO,MAAM,KAAG,cAE/D,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,OAAO,cAAc,EAAE,OAAO,MAAM,KAAG,cAE7D,CAAA;AAED,wBAAgB,MAAM,CAAC,eAAe,EAAE,CAAC,cAAc,EAAE,GAAG,cAAc,EAAE,CAAC,GAAG,cAAc,CAAA;AAC9F,wBAAgB,MAAM,CAAC,eAAe,EAAE,KAAK,CAAC,cAAc,CAAC,GAAG,cAAc,GAAG,IAAI,CAAA;AASrF,eAAO,MAAM,MAAM,GAAI,gBAAgB,cAAc,KAAG,cAOvD,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,gBAAgB,cAAc,KAAG,OAEvD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,cAAc,EAAE,QAAQ,cAAc,KAAG,OAE3E,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,QAAQ,cAAc,EAAE,YAAY,MAAM,EAAE,UAAU,2BAA2B,KAAG,MAgB1G,CAAA"}
@@ -0,0 +1,97 @@
1
+ // src/monetary-amount.ts
2
+ import { Schema as CurrencyCodeSchema } from "@bessemer/cornerstone/currency";
3
+ import Zod from "zod";
4
+ import { assertTrue } from "@bessemer/cornerstone/assertion";
5
+ import { isNil } from "@bessemer/cornerstone/object";
6
+ import { roundHalfEven } from "@bessemer/cornerstone/math";
7
+ import { isEmpty } from "@bessemer/cornerstone/array";
8
+ var Schema = Zod.object({
9
+ amount: Zod.number().int(),
10
+ currency: CurrencyCodeSchema
11
+ });
12
+ var of = (amount, currency) => {
13
+ assertTrue(Number.isInteger(amount));
14
+ return { amount, currency };
15
+ };
16
+ var zero = (currency) => {
17
+ return { amount: 0, currency };
18
+ };
19
+ var apply = (first, second, operator) => {
20
+ if (first.currency !== second.currency) {
21
+ throw new Error(`Currency mismatch in operation on MonetaryAmount: ${first.currency}, ${second.currency}`);
22
+ }
23
+ return operator(first.amount, second.amount);
24
+ };
25
+ var operate = (first, second, operator) => {
26
+ return of(apply(first, second, operator), first.currency);
27
+ };
28
+ var equal = (first, second) => {
29
+ if (isNil(first) && isNil(second)) {
30
+ return true;
31
+ }
32
+ if (isNil(first) || isNil(second)) {
33
+ return false;
34
+ }
35
+ return apply(first, second, (first2, second2) => first2 === second2);
36
+ };
37
+ var sum = (first, second) => {
38
+ return operate(first, second ?? zero(first.currency), (first2, second2) => first2 + second2);
39
+ };
40
+ var subtract = (first, second) => {
41
+ return operate(first, second, (first2, second2) => first2 - second2);
42
+ };
43
+ var multiply = (money, value) => {
44
+ return of(roundHalfEven(money.amount * value, 0), money.currency);
45
+ };
46
+ var divide = (money, value) => {
47
+ return of(roundHalfEven(money.amount / value, 0), money.currency);
48
+ };
49
+ function sumAll(monetaryAmounts) {
50
+ if (isEmpty(monetaryAmounts)) {
51
+ return null;
52
+ }
53
+ return monetaryAmounts.reduce((first, second) => sum(second, first), null);
54
+ }
55
+ var negate = (monetaryAmount) => {
56
+ if (isZero(monetaryAmount)) {
57
+ return monetaryAmount;
58
+ }
59
+ return of(-monetaryAmount.amount, monetaryAmount.currency);
60
+ };
61
+ var isZero = (monetaryAmount) => {
62
+ return monetaryAmount.amount === 0;
63
+ };
64
+ var greaterThan = (first, second) => {
65
+ return apply(first, second, (first2, second2) => first2 > second2);
66
+ };
67
+ var format = (amount, alpha2Code, options) => {
68
+ const hideCents = options?.hideCents ?? false;
69
+ const isWholeNumber = amount.amount % 100 === 0;
70
+ const formatCurrency = new Intl.NumberFormat(alpha2Code, {
71
+ style: "currency",
72
+ currency: amount.currency,
73
+ ...hideCents ? {
74
+ minimumFractionDigits: isWholeNumber ? 0 : 2,
75
+ maximumFractionDigits: 2
76
+ } : {}
77
+ });
78
+ return formatCurrency.format(amount.amount / 100);
79
+ };
80
+ export {
81
+ Schema,
82
+ apply,
83
+ divide,
84
+ equal,
85
+ format,
86
+ greaterThan,
87
+ isZero,
88
+ multiply,
89
+ negate,
90
+ of,
91
+ operate,
92
+ subtract,
93
+ sum,
94
+ sumAll,
95
+ zero
96
+ };
97
+ //# sourceMappingURL=monetary-amount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/monetary-amount.ts"],"sourcesContent":["import { CurrencyCode, Schema as CurrencyCodeSchema } from '@bessemer/cornerstone/currency'\nimport Zod, { ZodType } from 'zod'\nimport { assertTrue } from '@bessemer/cornerstone/assertion'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { roundHalfEven } from '@bessemer/cornerstone/math'\nimport { isEmpty } from '@bessemer/cornerstone/array'\n\nexport type MonetaryAmount = {\n amount: number\n currency: CurrencyCode\n}\nexport const Schema: ZodType<MonetaryAmount> = Zod.object({\n amount: Zod.number().int(),\n currency: CurrencyCodeSchema,\n})\n\nexport const of = (amount: number, currency: CurrencyCode): MonetaryAmount => {\n assertTrue(Number.isInteger(amount))\n return { amount, currency }\n}\n\nexport const zero = (currency: CurrencyCode): MonetaryAmount => {\n return { amount: 0, currency }\n}\n\nexport const apply = <T>(first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => T): T => {\n if (first.currency !== second.currency) {\n throw new Error(`Currency mismatch in operation on MonetaryAmount: ${first.currency}, ${second.currency}`)\n }\n\n return operator(first.amount, second.amount)\n}\n\nexport const operate = (first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => number): MonetaryAmount => {\n return of(apply(first, second, operator), first.currency)\n}\n\n/** Determines whether two MonetaryAmounts are considered equivalent */\nexport const equal = (first?: MonetaryAmount | null, second?: MonetaryAmount | null): boolean => {\n if (isNil(first) && isNil(second)) {\n return true\n }\n if (isNil(first) || isNil(second)) {\n return false\n }\n\n return apply(first, second, (first, second) => first === second)\n}\n\nexport const sum = (first: MonetaryAmount, second?: MonetaryAmount | null): MonetaryAmount => {\n return operate(first, second ?? zero(first.currency), (first, second) => first + second)\n}\n\nexport const subtract = (first: MonetaryAmount, second: MonetaryAmount): MonetaryAmount => {\n return operate(first, second, (first, second) => first - second)\n}\n\nexport const multiply = (money: MonetaryAmount, value: number): MonetaryAmount => {\n return of(roundHalfEven(money.amount * value, 0), money.currency)\n}\n\nexport const divide = (money: MonetaryAmount, value: number): MonetaryAmount => {\n return of(roundHalfEven(money.amount / value, 0), money.currency)\n}\n\nexport function sumAll(monetaryAmounts: [MonetaryAmount, ...MonetaryAmount[]]): MonetaryAmount\nexport function sumAll(monetaryAmounts: Array<MonetaryAmount>): MonetaryAmount | null\nexport function sumAll(monetaryAmounts: Array<MonetaryAmount>): MonetaryAmount | null {\n if (isEmpty(monetaryAmounts)) {\n return null\n }\n\n return monetaryAmounts.reduce<MonetaryAmount | null>((first, second) => sum(second, first), null)\n}\n\nexport const negate = (monetaryAmount: MonetaryAmount): MonetaryAmount => {\n // Avoid creating a negative 0, which is a real thing!\n if (isZero(monetaryAmount)) {\n return monetaryAmount\n }\n\n return of(-monetaryAmount.amount, monetaryAmount.currency)\n}\n\nexport const isZero = (monetaryAmount: MonetaryAmount): boolean => {\n return monetaryAmount.amount === 0\n}\n\nexport const greaterThan = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first > second)\n}\n\nexport type MonetaryAmountFormatOptions = {\n hideCents?: boolean\n}\n\nexport const format = (amount: MonetaryAmount, alpha2Code: string, options?: MonetaryAmountFormatOptions): string => {\n const hideCents = options?.hideCents ?? false\n const isWholeNumber = amount.amount % 100 === 0\n\n const formatCurrency = new Intl.NumberFormat(alpha2Code, {\n style: 'currency',\n currency: amount.currency,\n ...(hideCents\n ? {\n minimumFractionDigits: isWholeNumber ? 0 : 2,\n maximumFractionDigits: 2,\n }\n : {}),\n })\n\n return formatCurrency.format(amount.amount / 100)\n}\n"],"mappings":";AAAA,SAAuB,UAAU,0BAA0B;AAC3D,OAAO,SAAsB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAC9B,SAAS,eAAe;AAMjB,IAAM,SAAkC,IAAI,OAAO;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AAC,OAAuB,UAAkC;AAC9E,SAAO,GAAG,cAAc,MAAM,SAAS,OAAO,CAAC,GAAG,MAAM,QAAQ;AAClE;AAIO,SAAS,OAAO,iBAA+D;AACpF,MAAI,QAAQ,eAAe,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO,gBAAgB,OAA8B,CAAC,OAAO,WAAW,IAAI,QAAQ,KAAK,GAAG,IAAI;AAClG;AAEO,IAAM,SAAS,CAAC,mBAAmD;AAExE,MAAI,OAAO,cAAc,GAAG;AAC1B,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,CAAC,eAAe,QAAQ,eAAe,QAAQ;AAC3D;AAEO,IAAM,SAAS,CAAC,mBAA4C;AACjE,SAAO,eAAe,WAAW;AACnC;AAEO,IAAM,cAAc,CAAC,OAAuB,WAAoC;AACrF,SAAO,MAAM,OAAO,QAAQ,CAACD,QAAOC,YAAWD,SAAQC,OAAM;AAC/D;AAMO,IAAM,SAAS,CAAC,QAAwB,YAAoB,YAAkD;AACnH,QAAM,YAAY,SAAS,aAAa;AACxC,QAAM,gBAAgB,OAAO,SAAS,QAAQ;AAE9C,QAAM,iBAAiB,IAAI,KAAK,aAAa,YAAY;AAAA,IACvD,OAAO;AAAA,IACP,UAAU,OAAO;AAAA,IACjB,GAAI,YACA;AAAA,MACE,uBAAuB,gBAAgB,IAAI;AAAA,MAC3C,uBAAuB;AAAA,IACzB,IACA,CAAC;AAAA,EACP,CAAC;AAED,SAAO,eAAe,OAAO,OAAO,SAAS,GAAG;AAClD;","names":["first","second"]}
package/dist/range.d.ts CHANGED
@@ -2,8 +2,8 @@ import Zod, { ZodType } from 'zod';
2
2
  import { TaggedType } from '@bessemer/cornerstone/types';
3
3
  export type Bounds<T> = TaggedType<[T | null, T | null], 'Bounds'>;
4
4
  export type BoundsInput<T> = [lower: T | null, upper?: T | null] | Bounds<T>;
5
- export declare const schema: <T extends ZodType>(type: T) => Zod.ZodTuple<[Zod.ZodNullable<T>, Zod.ZodNullable<T>], null>;
5
+ export declare const schema: <T>(type: ZodType<T>) => ZodType<Bounds<T>>;
6
6
  export type NumericBounds<T> = Bounds<number>;
7
- export declare const NumericSchema: Zod.ZodTuple<[Zod.ZodNullable<Zod.ZodNumber>, Zod.ZodNullable<Zod.ZodNumber>], null>;
7
+ export declare const NumericSchema: Zod.ZodType<Bounds<number>, Zod.ZodTypeDef, Bounds<number>>;
8
8
  export declare const of: <T>(bounds: BoundsInput<T>) => Bounds<T>;
9
9
  //# sourceMappingURL=range.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAA;AAClE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;AAE5E,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC,iEAEhD,CAAA;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,CAAA;AAC7C,eAAO,MAAM,aAAa,sFAAuB,CAAA;AAEjD,eAAO,MAAM,EAAE,GAAI,CAAC,EAAE,QAAQ,WAAW,CAAC,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,CAMtD,CAAA"}
1
+ {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAA;AAClE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;AAE5E,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAE7D,CAAA;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,CAAA;AAC7C,eAAO,MAAM,aAAa,6DAAuB,CAAA;AAEjD,eAAO,MAAM,EAAE,GAAI,CAAC,EAAE,QAAQ,WAAW,CAAC,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,CAMtD,CAAA"}
package/dist/range.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/range.ts"],"sourcesContent":["import { Objects } from '@bessemer/cornerstone'\nimport Zod, { ZodType } from 'zod'\nimport { TaggedType } from '@bessemer/cornerstone/types'\n\nexport type Bounds<T> = TaggedType<[T | null, T | null], 'Bounds'>\nexport type BoundsInput<T> = [lower: T | null, upper?: T | null] | Bounds<T>\n\nexport const schema = <T extends ZodType>(type: T) => {\n return Zod.tuple([type.nullable(), type.nullable()])\n}\n\nexport type NumericBounds<T> = Bounds<number>\nexport const NumericSchema = schema(Zod.number())\n\nexport const of = <T>(bounds: BoundsInput<T>): Bounds<T> => {\n if (Objects.isUndefined(bounds[1])) {\n return [bounds[0], null] as Bounds<T>\n }\n\n return bounds as Bounds<T>\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,OAAO,SAAsB;AAMtB,IAAM,SAAS,CAAoB,SAAY;AACpD,SAAO,IAAI,MAAM,CAAC,KAAK,SAAS,GAAG,KAAK,SAAS,CAAC,CAAC;AACrD;AAGO,IAAM,gBAAgB,OAAO,IAAI,OAAO,CAAC;AAEzC,IAAM,KAAK,CAAI,WAAsC;AAC1D,MAAI,QAAQ,YAAY,OAAO,CAAC,CAAC,GAAG;AAClC,WAAO,CAAC,OAAO,CAAC,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/range.ts"],"sourcesContent":["import { Objects } from '@bessemer/cornerstone'\nimport Zod, { ZodType } from 'zod'\nimport { TaggedType } from '@bessemer/cornerstone/types'\n\nexport type Bounds<T> = TaggedType<[T | null, T | null], 'Bounds'>\nexport type BoundsInput<T> = [lower: T | null, upper?: T | null] | Bounds<T>\n\nexport const schema = <T>(type: ZodType<T>): ZodType<Bounds<T>> => {\n return Zod.tuple([type.nullable(), type.nullable()]) as any\n}\n\nexport type NumericBounds<T> = Bounds<number>\nexport const NumericSchema = schema(Zod.number())\n\nexport const of = <T>(bounds: BoundsInput<T>): Bounds<T> => {\n if (Objects.isUndefined(bounds[1])) {\n return [bounds[0], null] as Bounds<T>\n }\n\n return bounds as Bounds<T>\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,OAAO,SAAsB;AAMtB,IAAM,SAAS,CAAI,SAAyC;AACjE,SAAO,IAAI,MAAM,CAAC,KAAK,SAAS,GAAG,KAAK,SAAS,CAAC,CAAC;AACrD;AAGO,IAAM,gBAAgB,OAAO,IAAI,OAAO,CAAC;AAEzC,IAAM,KAAK,CAAI,WAAsC;AAC1D,MAAI,QAAQ,YAAY,OAAO,CAAC,CAAC,GAAG;AAClC,WAAO,CAAC,OAAO,CAAC,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bessemer/cornerstone",
3
3
  "type": "module",
4
- "version": "0.5.59",
4
+ "version": "0.5.61",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "sideEffects": false,