@bessemer/cornerstone 0.5.97 → 0.5.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.d.ts +62 -1
- package/dist/array.d.ts.map +1 -1
- package/dist/array.js +24 -11
- package/dist/array.js.map +1 -1
- package/dist/aspect-ratio.d.ts +1 -1
- package/dist/aspect-ratio.d.ts.map +1 -1
- package/dist/aspect-ratio.js +4 -4
- package/dist/aspect-ratio.js.map +1 -1
- package/dist/async-value.d.ts +10 -2
- package/dist/async-value.d.ts.map +1 -1
- package/dist/async-value.js +33 -2
- package/dist/async-value.js.map +1 -1
- package/dist/cache.js +1 -1
- package/dist/cache.js.map +1 -1
- package/dist/equalitor.d.ts +1 -0
- package/dist/equalitor.d.ts.map +1 -1
- package/dist/equalitor.js +3 -0
- package/dist/equalitor.js.map +1 -1
- package/dist/error/error-cause.d.ts +35 -0
- package/dist/error/error-cause.d.ts.map +1 -0
- package/dist/error/error-cause.js +97 -0
- package/dist/error/error-cause.js.map +1 -0
- package/dist/error/error-code.d.ts +17 -0
- package/dist/error/error-code.d.ts.map +1 -0
- package/dist/error/error-code.js +32 -0
- package/dist/error/error-code.js.map +1 -0
- package/dist/error/error-event.d.ts +29 -48
- package/dist/error/error-event.d.ts.map +1 -1
- package/dist/error/error-event.js +62 -151
- package/dist/error/error-event.js.map +1 -1
- package/dist/error/error-type.d.ts +1 -0
- package/dist/error/error-type.d.ts.map +1 -1
- package/dist/error/error-type.js +4 -2
- package/dist/error/error-type.js.map +1 -1
- package/dist/function.d.ts +1 -1
- package/dist/function.d.ts.map +1 -1
- package/dist/function.js +3 -2
- package/dist/function.js.map +1 -1
- package/dist/glob.d.ts +1 -1
- package/dist/glob.d.ts.map +1 -1
- package/dist/glob.js +4 -4
- package/dist/glob.js.map +1 -1
- package/dist/hex-code.d.ts +1 -1
- package/dist/hex-code.d.ts.map +1 -1
- package/dist/hex-code.js +4 -4
- package/dist/hex-code.js.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/dist/intl/country-code.d.ts +1 -1
- package/dist/intl/country-code.d.ts.map +1 -1
- package/dist/intl/country-code.js +4 -4
- package/dist/intl/country-code.js.map +1 -1
- package/dist/intl/country-subdivision-code.d.ts +1 -1
- package/dist/intl/country-subdivision-code.d.ts.map +1 -1
- package/dist/intl/country-subdivision-code.js +4 -4
- package/dist/intl/country-subdivision-code.js.map +1 -1
- package/dist/intl/currency-code.d.ts +1 -1
- package/dist/intl/currency-code.d.ts.map +1 -1
- package/dist/intl/currency-code.js +4 -4
- package/dist/intl/currency-code.js.map +1 -1
- package/dist/intl/language-code.d.ts +1 -1
- package/dist/intl/language-code.d.ts.map +1 -1
- package/dist/intl/language-code.js +4 -4
- package/dist/intl/language-code.js.map +1 -1
- package/dist/intl/locale.d.ts +1 -1
- package/dist/intl/locale.d.ts.map +1 -1
- package/dist/intl/locale.js +6 -6
- package/dist/intl/locale.js.map +1 -1
- package/dist/mime-type.d.ts +1 -1
- package/dist/mime-type.d.ts.map +1 -1
- package/dist/mime-type.js +4 -4
- package/dist/mime-type.js.map +1 -1
- package/dist/net/domain-name.d.ts +10 -0
- package/dist/net/domain-name.d.ts.map +1 -0
- package/dist/net/domain-name.js +30 -0
- package/dist/net/domain-name.js.map +1 -0
- package/dist/net/ipv4-address.d.ts +10 -0
- package/dist/net/ipv4-address.d.ts.map +1 -0
- package/dist/net/ipv4-address.js +30 -0
- package/dist/net/ipv4-address.js.map +1 -0
- package/dist/net/ipv6-address.d.ts +10 -0
- package/dist/net/ipv6-address.d.ts.map +1 -0
- package/dist/net/ipv6-address.js +30 -0
- package/dist/net/ipv6-address.js.map +1 -0
- package/dist/net/uri-host-name.d.ts +12 -0
- package/dist/net/uri-host-name.d.ts.map +1 -0
- package/dist/net/uri-host-name.js +44 -0
- package/dist/net/uri-host-name.js.map +1 -0
- package/dist/net/uri.d.ts +249 -0
- package/dist/net/uri.d.ts.map +1 -0
- package/dist/net/uri.js +444 -0
- package/dist/net/uri.js.map +1 -0
- package/dist/net/url.d.ts +58 -0
- package/dist/net/url.d.ts.map +1 -0
- package/dist/net/url.js +211 -0
- package/dist/net/url.js.map +1 -0
- package/dist/object/object-path.d.ts +1 -1
- package/dist/object/object-path.d.ts.map +1 -1
- package/dist/object/object-path.js +4 -4
- package/dist/object/object-path.js.map +1 -1
- package/dist/object/type-path.d.ts +1 -1
- package/dist/object/type-path.d.ts.map +1 -1
- package/dist/object/type-path.js +3 -3
- package/dist/object/type-path.js.map +1 -1
- package/dist/object.d.ts +1 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +8 -6
- package/dist/object.js.map +1 -1
- package/dist/property.d.ts +2 -3
- package/dist/property.d.ts.map +1 -1
- package/dist/property.js.map +1 -1
- package/dist/resource-key.d.ts +7 -5
- package/dist/resource-key.d.ts.map +1 -1
- package/dist/resource-key.js +27 -15
- package/dist/resource-key.js.map +1 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -3
- package/dist/result.js.map +1 -1
- package/dist/string.d.ts +10 -21
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +54 -25
- package/dist/string.js.map +1 -1
- package/dist/tag.d.ts +2 -2
- package/dist/tag.d.ts.map +1 -1
- package/dist/tag.js +11 -12
- package/dist/tag.js.map +1 -1
- package/dist/temporal/duration.d.ts +4 -5
- package/dist/temporal/duration.d.ts.map +1 -1
- package/dist/temporal/duration.js +3 -7
- package/dist/temporal/duration.js.map +1 -1
- package/dist/temporal/instant.d.ts +4 -5
- package/dist/temporal/instant.d.ts.map +1 -1
- package/dist/temporal/instant.js +3 -7
- package/dist/temporal/instant.js.map +1 -1
- package/dist/temporal/plain-date-time.d.ts +4 -5
- package/dist/temporal/plain-date-time.d.ts.map +1 -1
- package/dist/temporal/plain-date-time.js +3 -7
- package/dist/temporal/plain-date-time.js.map +1 -1
- package/dist/temporal/plain-date.d.ts +8 -9
- package/dist/temporal/plain-date.d.ts.map +1 -1
- package/dist/temporal/plain-date.js +3 -7
- package/dist/temporal/plain-date.js.map +1 -1
- package/dist/temporal/plain-time.d.ts +6 -7
- package/dist/temporal/plain-time.d.ts.map +1 -1
- package/dist/temporal/plain-time.js +4 -8
- package/dist/temporal/plain-time.js.map +1 -1
- package/dist/temporal/time-zone-id.d.ts +1 -1
- package/dist/temporal/time-zone-id.d.ts.map +1 -1
- package/dist/temporal/time-zone-id.js +4 -4
- package/dist/temporal/time-zone-id.js.map +1 -1
- package/dist/temporal/time-zone-offset.d.ts +1 -1
- package/dist/temporal/time-zone-offset.d.ts.map +1 -1
- package/dist/temporal/time-zone-offset.js +4 -4
- package/dist/temporal/time-zone-offset.js.map +1 -1
- package/dist/temporal/zoned-date-time.d.ts +51 -0
- package/dist/temporal/zoned-date-time.d.ts.map +1 -0
- package/dist/temporal/zoned-date-time.js +106 -0
- package/dist/temporal/zoned-date-time.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/{ulid.d.ts → uuid/ulid.d.ts} +2 -2
- package/dist/uuid/ulid.d.ts.map +1 -0
- package/dist/uuid/ulid.js +29 -0
- package/dist/uuid/ulid.js.map +1 -0
- package/dist/uuid/uuid-v4.d.ts +11 -0
- package/dist/uuid/uuid-v4.d.ts.map +1 -0
- package/dist/{uuid.js → uuid/uuid-v4.js} +11 -11
- package/dist/uuid/uuid-v4.js.map +1 -0
- package/dist/uuid/uuid-v7.d.ts +18 -0
- package/dist/uuid/uuid-v7.d.ts.map +1 -0
- package/dist/uuid/uuid-v7.js +44 -0
- package/dist/uuid/uuid-v7.js.map +1 -0
- package/package.json +1 -1
- package/dist/ulid.d.ts.map +0 -1
- package/dist/ulid.js +0 -29
- package/dist/ulid.js.map +0 -1
- package/dist/uri.d.ts +0 -52
- package/dist/uri.d.ts.map +0 -1
- package/dist/uri.js +0 -222
- package/dist/uri.js.map +0 -1
- package/dist/url.d.ts +0 -26
- package/dist/url.d.ts.map +0 -1
- package/dist/url.js +0 -120
- package/dist/url.js.map +0 -1
- package/dist/uuid.d.ts +0 -11
- package/dist/uuid.d.ts.map +0 -1
- package/dist/uuid.js.map +0 -1
package/dist/object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0E,SAAS,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAEhI,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAC/E,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAMpD,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAErD,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,IAEhD,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,IAAI,GAAG,SAEtD,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,IAAI,WAAW,CAAC,CAAC,CAE7D,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,QAAQ,GAAG,KAAG,KAAK,IAAI,UAAU,CAAC,OAAO,CAOjE,CAAA;AAGD,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,KAAG,OAE1E,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,OAAO,EAAE,QAAQ,OAAO,KAAG,OAsD5D,CAAA;AAED,eAAO,MAAM,SAAS;;;;;;;;;;;;;CAAa,CAAA;AAEnC,eAAO,MAAM,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AW,CAAC,KAAG,mBAAmB,CAAC,CAAC,CAAC,GAAG,SAEvI,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,KAAG,CAAC,GAAG,SAE9D,CAAA"}
|
package/dist/object.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/object.ts
|
|
2
|
-
import {
|
|
2
|
+
import { cloneDeep as _cloneDeep, mapValues as _mapValues, merge as unsafeMerge, mergeWith as unsafeMergeWith } from "lodash-es";
|
|
3
3
|
import { isNumber } from "@bessemer/cornerstone/math";
|
|
4
4
|
import { isString } from "@bessemer/cornerstone/string";
|
|
5
5
|
import { isDate } from "@bessemer/cornerstone/temporal/date";
|
|
@@ -7,8 +7,11 @@ import { _isInstant } from "@bessemer/cornerstone/temporal/chrono";
|
|
|
7
7
|
var isUndefined = (value) => {
|
|
8
8
|
return value === void 0;
|
|
9
9
|
};
|
|
10
|
+
var isNull = (value) => {
|
|
11
|
+
return value === null;
|
|
12
|
+
};
|
|
10
13
|
var isNil = (value) => {
|
|
11
|
-
return value
|
|
14
|
+
return isNull(value) || isUndefined(value);
|
|
12
15
|
};
|
|
13
16
|
var isPresent = (value) => {
|
|
14
17
|
return !isNil(value);
|
|
@@ -66,7 +69,6 @@ var deepEqual = (value1, value2) => {
|
|
|
66
69
|
return false;
|
|
67
70
|
};
|
|
68
71
|
var mapValues = _mapValues;
|
|
69
|
-
var clone = _clone;
|
|
70
72
|
var cloneDeep = _cloneDeep;
|
|
71
73
|
function deepMerge(object, ...otherArgs) {
|
|
72
74
|
return unsafeMerge({}, object, ...otherArgs);
|
|
@@ -78,8 +80,8 @@ function deepMergeInto(source, values) {
|
|
|
78
80
|
unsafeMerge(source, values);
|
|
79
81
|
}
|
|
80
82
|
var deepMergeWith = (...args) => {
|
|
81
|
-
const
|
|
82
|
-
return unsafeMergeWith.apply(null, [
|
|
83
|
+
const clone = cloneDeep(args[0]);
|
|
84
|
+
return unsafeMergeWith.apply(null, [clone, ...args.slice(1)]);
|
|
83
85
|
};
|
|
84
86
|
function diffShallow(original, updated) {
|
|
85
87
|
const result = {
|
|
@@ -125,7 +127,6 @@ var coerceNil = (value) => {
|
|
|
125
127
|
return isNil(value) ? void 0 : value;
|
|
126
128
|
};
|
|
127
129
|
export {
|
|
128
|
-
clone,
|
|
129
130
|
cloneDeep,
|
|
130
131
|
coerceNil,
|
|
131
132
|
deepEqual,
|
|
@@ -140,6 +141,7 @@ export {
|
|
|
140
141
|
isBoolean,
|
|
141
142
|
isEmpty,
|
|
142
143
|
isNil,
|
|
144
|
+
isNull,
|
|
143
145
|
isObject,
|
|
144
146
|
isPresent,
|
|
145
147
|
isPrimitive,
|
package/dist/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/object.ts"],"sourcesContent":["import { clone as _clone, cloneDeep as _cloneDeep, mapValues as _mapValues, merge as unsafeMerge, mergeWith as unsafeMergeWith } from 'lodash-es'\n\nimport { BasicType, Dictionary, TaggedType } from '@bessemer/cornerstone/types'\nimport { Primitive, UnknownRecord } from 'type-fest'\nimport { isNumber } from '@bessemer/cornerstone/math'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isDate } from '@bessemer/cornerstone/temporal/date'\nimport { _isInstant } from '@bessemer/cornerstone/temporal/chrono'\n\nexport const isUndefined = (value: unknown): value is undefined => {\n return value === undefined\n}\n\nexport const isNil = (value: unknown): value is null | undefined => {\n return value === null || value === undefined\n}\n\nexport const isPresent = <T>(value: T): value is NonNullable<T> => {\n return !isNil(value)\n}\n\nexport const isObject = (value?: any): value is Dictionary<unknown> => {\n if (value === null || value === undefined || typeof value !== 'object') {\n return false\n }\n\n const proto = Object.getPrototypeOf(value)\n return proto !== null && Object.getPrototypeOf(proto) === null\n}\n\n// JOHN should this also check for the nil case?\nexport const isEmpty = (value: Record<string | number | symbol, unknown>): boolean => {\n return Object.keys(value).length === 0\n}\n\nexport const deepEqual = (value1: unknown, value2: unknown): boolean => {\n if (value1 === value2) {\n return true\n }\n\n // If either value is null or undefined, they're not equal (since we already checked ===)\n if (isNil(value1) || isNil(value2)) {\n return false\n }\n\n if (isDate(value1) && isDate(value2)) {\n return value1.getTime() === value2.getTime()\n }\n\n if (value1 instanceof RegExp && value2 instanceof RegExp) {\n return value1.toString() === value2.toString()\n }\n\n if (typeof value1 !== typeof value2) {\n return false\n }\n\n if (Array.isArray(value1) && Array.isArray(value2)) {\n if (value1.length !== value2.length) {\n return false\n }\n\n for (let i = 0; i < value1.length; i++) {\n if (!deepEqual(value1[i], value2[i])) {\n return false\n }\n }\n\n return true\n }\n\n if (isObject(value1) && isObject(value2)) {\n const keys1 = Object.keys(value1)\n const keys2 = Object.keys(value2)\n\n if (keys1.length !== keys2.length) {\n return false\n }\n\n for (const key of keys1) {\n if (!deepEqual(value1[key], value2[key])) {\n return false\n }\n }\n\n return true\n }\n\n return false\n}\n\nexport const mapValues = _mapValues\n\nexport const clone = _clone\nexport const cloneDeep = _cloneDeep\n\nexport function deepMerge<TObject, TSource>(object: TObject, source: TSource): TObject & TSource\nexport function deepMerge<TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2\nexport function deepMerge<TObject, TSource1, TSource2, TSource3>(\n object: TObject,\n source1: TSource1,\n source2: TSource2,\n source3: TSource3\n): TObject & TSource1 & TSource2 & TSource3\nexport function deepMerge<TObject, TSource1, TSource2, TSource3, TSource4>(\n object: TObject,\n source1: TSource1,\n source2: TSource2,\n source3: TSource3,\n source4: TSource4\n): TObject & TSource1 & TSource2 & TSource3 & TSource4\nexport function deepMerge(object: any, ...otherArgs: any[]): any {\n return unsafeMerge({}, object, ...otherArgs)\n}\n\nexport const deepMergeAll = <T>(objects: Array<T>): T => {\n return objects.reduce((x, y) => deepMerge(x, y))\n}\n\nexport function deepMergeInto<Source1, Source2>(source: Source1, values: Source2): asserts source is Source1 & Source2 {\n unsafeMerge(source, values)\n}\n\nexport const deepMergeWith: typeof unsafeMergeWith = (...args: Array<any>) => {\n const clone = cloneDeep(args[0])\n return unsafeMergeWith.apply(null, [clone, ...args.slice(1)])\n}\n\nexport type ObjectDiffResult = {\n elementsUpdated: Record<string, { originalValue: unknown; updatedValue: unknown }>\n elementsAdded: UnknownRecord\n elementsRemoved: UnknownRecord\n}\n\nexport function diffShallow(original: UnknownRecord, updated: UnknownRecord): ObjectDiffResult {\n const result: ObjectDiffResult = {\n elementsUpdated: {},\n elementsAdded: {},\n elementsRemoved: {},\n }\n\n for (const [key, originalValue] of Object.entries(original)) {\n const updatedValue = updated[key]\n if (updatedValue === undefined) {\n result.elementsRemoved[key] = originalValue\n } else if (!deepEqual(originalValue, updatedValue)) {\n result.elementsUpdated[key] = { originalValue: originalValue, updatedValue: updatedValue }\n }\n }\n\n for (const [key, updatedValue] of Object.entries(updated)) {\n const originalValue = original[key]\n if (originalValue === undefined) {\n result.elementsAdded[key] = updatedValue\n }\n }\n return result\n}\n\nexport const isValidKey = (field: PropertyKey, obj: object): field is keyof typeof obj => {\n return field in obj\n}\n\n/** Determines if the list of fields are present on the object (not null or undefined), with type inference */\nexport function fieldsPresent<T extends object, K extends keyof T>(\n object: T,\n fields: Array<K>\n): object is Exclude<T, K> & Required<{ [P in K]: NonNullable<T[P]> }> {\n return fields.every((field) => isPresent(object[field]))\n}\n\nexport const isPrimitive = (value: any): value is Primitive => {\n return value === null || (typeof value !== 'object' && typeof value !== 'function')\n}\n\nexport const isBasic = (value: any): value is BasicType => {\n return isNumber(value) || isString(value) || isDate(value) || isBoolean(value) || _isInstant(value)\n}\n\nexport const isBoolean = (value: unknown): value is boolean => {\n return typeof value === 'boolean'\n}\n\ntype TransformFunction = (value: any, path: (string | number)[], key: string | number, parent: any) => any\n\nconst walk = (value: any, transform: TransformFunction, path: (string | number)[] = []): any => {\n if (isNil(value) || isPrimitive(value)) {\n return value\n }\n\n if (Array.isArray(value)) {\n return value.map((value, index) => {\n const currentPath = [...path, index]\n return walk(transform(value, currentPath, index, value), transform, currentPath)\n })\n }\n\n const result: any = {}\n for (const key in value) {\n if (Object.prototype.hasOwnProperty.call(value, key)) {\n const currentPath = [...path, key]\n const transformedValue = transform(value[key], currentPath, key, value)\n result[key] = walk(transformedValue, transform, currentPath)\n }\n }\n\n return result\n}\n\nexport type RecordAttribute<Type = unknown, Class extends string = 'RecordAttribute'> = TaggedType<string, [Type, Class]>\ntype RecordAttributeType<Attribute> = Attribute extends RecordAttribute<infer Type, string> ? Type : never\n\nexport const getAttribute = <T extends RecordAttribute<unknown, string>>(record: UnknownRecord, attribute: T): RecordAttributeType<T> | undefined => {\n return record[attribute] as RecordAttributeType<T> | undefined\n}\n\nexport const coerceNil = <T>(value: T | null | undefined): T | undefined => {\n return isNil(value) ? undefined : value\n}\n"],"mappings":";AAAA,SAAS,SAAS,QAAQ,aAAa,YAAY,aAAa,YAAY,SAAS,aAAa,aAAa,uBAAuB;AAItI,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAEpB,IAAM,cAAc,CAAC,UAAuC;AACjE,SAAO,UAAU;AACnB;AAEO,IAAM,QAAQ,CAAC,UAA8C;AAClE,SAAO,UAAU,QAAQ,UAAU;AACrC;AAEO,IAAM,YAAY,CAAI,UAAsC;AACjE,SAAO,CAAC,MAAM,KAAK;AACrB;AAEO,IAAM,WAAW,CAAC,UAA8C;AACrE,MAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU,UAAU;AACtE,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,OAAO,eAAe,KAAK;AACzC,SAAO,UAAU,QAAQ,OAAO,eAAe,KAAK,MAAM;AAC5D;AAGO,IAAM,UAAU,CAAC,UAA8D;AACpF,SAAO,OAAO,KAAK,KAAK,EAAE,WAAW;AACvC;AAEO,IAAM,YAAY,CAAC,QAAiB,WAA6B;AACtE,MAAI,WAAW,QAAQ;AACrB,WAAO;AAAA,EACT;AAGA,MAAI,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AM,YAAY,CAAC,UAAqC;AAC7D,SAAO,OAAO,UAAU;AAC1B;AA+BO,IAAM,eAAe,CAA6C,QAAuB,cAAqD;AACnJ,SAAO,OAAO,SAAS;AACzB;AAEO,IAAM,YAAY,CAAI,UAA+C;AAC1E,SAAO,MAAM,KAAK,IAAI,SAAY;AACpC;","names":["clone"]}
|
|
1
|
+
{"version":3,"sources":["../src/object.ts"],"sourcesContent":["import { cloneDeep as _cloneDeep, mapValues as _mapValues, merge as unsafeMerge, mergeWith as unsafeMergeWith } from 'lodash-es'\n\nimport { BasicType, Dictionary, TaggedType } from '@bessemer/cornerstone/types'\nimport { Primitive, UnknownRecord } from 'type-fest'\nimport { isNumber } from '@bessemer/cornerstone/math'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isDate } from '@bessemer/cornerstone/temporal/date'\nimport { _isInstant } from '@bessemer/cornerstone/temporal/chrono'\n\nexport const isUndefined = (value: unknown): value is undefined => {\n return value === undefined\n}\n\nexport const isNull = (value: unknown): value is null => {\n return value === null\n}\n\nexport const isNil = (value: unknown): value is null | undefined => {\n return isNull(value) || isUndefined(value)\n}\n\nexport const isPresent = <T>(value: T): value is NonNullable<T> => {\n return !isNil(value)\n}\n\nexport const isObject = (value?: any): value is Dictionary<unknown> => {\n if (value === null || value === undefined || typeof value !== 'object') {\n return false\n }\n\n const proto = Object.getPrototypeOf(value)\n return proto !== null && Object.getPrototypeOf(proto) === null\n}\n\n// JOHN should this also check for the nil case?\nexport const isEmpty = (value: Record<string | number | symbol, unknown>): boolean => {\n return Object.keys(value).length === 0\n}\n\nexport const deepEqual = (value1: unknown, value2: unknown): boolean => {\n if (value1 === value2) {\n return true\n }\n\n // If either value is null or undefined, they're not equal (since we already checked ===)\n if (isNil(value1) || isNil(value2)) {\n return false\n }\n\n if (isDate(value1) && isDate(value2)) {\n return value1.getTime() === value2.getTime()\n }\n\n if (value1 instanceof RegExp && value2 instanceof RegExp) {\n return value1.toString() === value2.toString()\n }\n\n if (typeof value1 !== typeof value2) {\n return false\n }\n\n if (Array.isArray(value1) && Array.isArray(value2)) {\n if (value1.length !== value2.length) {\n return false\n }\n\n for (let i = 0; i < value1.length; i++) {\n if (!deepEqual(value1[i], value2[i])) {\n return false\n }\n }\n\n return true\n }\n\n if (isObject(value1) && isObject(value2)) {\n const keys1 = Object.keys(value1)\n const keys2 = Object.keys(value2)\n\n if (keys1.length !== keys2.length) {\n return false\n }\n\n for (const key of keys1) {\n if (!deepEqual(value1[key], value2[key])) {\n return false\n }\n }\n\n return true\n }\n\n return false\n}\n\nexport const mapValues = _mapValues\n\nexport const cloneDeep = _cloneDeep\n\nexport function deepMerge<TObject, TSource>(object: TObject, source: TSource): TObject & TSource\nexport function deepMerge<TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2\nexport function deepMerge<TObject, TSource1, TSource2, TSource3>(\n object: TObject,\n source1: TSource1,\n source2: TSource2,\n source3: TSource3\n): TObject & TSource1 & TSource2 & TSource3\nexport function deepMerge<TObject, TSource1, TSource2, TSource3, TSource4>(\n object: TObject,\n source1: TSource1,\n source2: TSource2,\n source3: TSource3,\n source4: TSource4\n): TObject & TSource1 & TSource2 & TSource3 & TSource4\nexport function deepMerge(object: any, ...otherArgs: any[]): any {\n return unsafeMerge({}, object, ...otherArgs)\n}\n\nexport const deepMergeAll = <T>(objects: Array<T>): T => {\n return objects.reduce((x, y) => deepMerge(x, y))\n}\n\nexport function deepMergeInto<Source1, Source2>(source: Source1, values: Source2): asserts source is Source1 & Source2 {\n unsafeMerge(source, values)\n}\n\nexport const deepMergeWith: typeof unsafeMergeWith = (...args: Array<any>) => {\n const clone = cloneDeep(args[0])\n return unsafeMergeWith.apply(null, [clone, ...args.slice(1)])\n}\n\nexport type ObjectDiffResult = {\n elementsUpdated: Record<string, { originalValue: unknown; updatedValue: unknown }>\n elementsAdded: UnknownRecord\n elementsRemoved: UnknownRecord\n}\n\nexport function diffShallow(original: UnknownRecord, updated: UnknownRecord): ObjectDiffResult {\n const result: ObjectDiffResult = {\n elementsUpdated: {},\n elementsAdded: {},\n elementsRemoved: {},\n }\n\n for (const [key, originalValue] of Object.entries(original)) {\n const updatedValue = updated[key]\n if (updatedValue === undefined) {\n result.elementsRemoved[key] = originalValue\n } else if (!deepEqual(originalValue, updatedValue)) {\n result.elementsUpdated[key] = { originalValue: originalValue, updatedValue: updatedValue }\n }\n }\n\n for (const [key, updatedValue] of Object.entries(updated)) {\n const originalValue = original[key]\n if (originalValue === undefined) {\n result.elementsAdded[key] = updatedValue\n }\n }\n return result\n}\n\nexport const isValidKey = (field: PropertyKey, obj: object): field is keyof typeof obj => {\n return field in obj\n}\n\n/** Determines if the list of fields are present on the object (not null or undefined), with type inference */\nexport function fieldsPresent<T extends object, K extends keyof T>(\n object: T,\n fields: Array<K>\n): object is Exclude<T, K> & Required<{ [P in K]: NonNullable<T[P]> }> {\n return fields.every((field) => isPresent(object[field]))\n}\n\nexport const isPrimitive = (value: any): value is Primitive => {\n return value === null || (typeof value !== 'object' && typeof value !== 'function')\n}\n\nexport const isBasic = (value: any): value is BasicType => {\n return isNumber(value) || isString(value) || isDate(value) || isBoolean(value) || _isInstant(value)\n}\n\nexport const isBoolean = (value: unknown): value is boolean => {\n return typeof value === 'boolean'\n}\n\ntype TransformFunction = (value: any, path: (string | number)[], key: string | number, parent: any) => any\n\nconst walk = (value: any, transform: TransformFunction, path: (string | number)[] = []): any => {\n if (isNil(value) || isPrimitive(value)) {\n return value\n }\n\n if (Array.isArray(value)) {\n return value.map((value, index) => {\n const currentPath = [...path, index]\n return walk(transform(value, currentPath, index, value), transform, currentPath)\n })\n }\n\n const result: any = {}\n for (const key in value) {\n if (Object.prototype.hasOwnProperty.call(value, key)) {\n const currentPath = [...path, key]\n const transformedValue = transform(value[key], currentPath, key, value)\n result[key] = walk(transformedValue, transform, currentPath)\n }\n }\n\n return result\n}\n\nexport type RecordAttribute<Type = unknown, Class extends string = 'RecordAttribute'> = TaggedType<string, [Type, Class]>\ntype RecordAttributeType<Attribute> = Attribute extends RecordAttribute<infer Type, string> ? Type : never\n\nexport const getAttribute = <T extends RecordAttribute<unknown, string>>(record: UnknownRecord, attribute: T): RecordAttributeType<T> | undefined => {\n return record[attribute] as RecordAttributeType<T> | undefined\n}\n\nexport const coerceNil = <T>(value: T | null | undefined): T | undefined => {\n return isNil(value) ? undefined : value\n}\n"],"mappings":";AAAA,SAAS,aAAa,YAAY,aAAa,YAAY,SAAS,aAAa,aAAa,uBAAuB;AAIrH,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAEpB,IAAM,cAAc,CAAC,UAAuC;AACjE,SAAO,UAAU;AACnB;AAEO,IAAM,SAAS,CAAC,UAAkC;AACvD,SAAO,UAAU;AACnB;AAEO,IAAM,QAAQ,CAAC,UAA8C;AAClE,SAAO,OAAO,KAAK,KAAK,YAAY,KAAK;AAC3C;AAEO,IAAM,YAAY,CAAI,UAAsC;AACjE,SAAO,CAAC,MAAM,KAAK;AACrB;AAEO,IAAM,WAAW,CAAC,UAA8C;AACrE,MAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU,UAAU;AACtE,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,OAAO,eAAe,KAAK;AACzC,SAAO,UAAU,QAAQ,OAAO,eAAe,KAAK,MAAM;AAC5D;AAGO,IAAM,UAAU,CAAC,UAA8D;AACpF,SAAO,OAAO,KAAK,KAAK,EAAE,WAAW;AACvC;AAEO,IAAM,YAAY,CAAC,QAAiB,WAA6B;AACtE,MAAI,WAAW,QAAQ;AACrB,WAAO;AAAA,EACT;AAGA,MAAI,MAAM,MAAM,KAAK,MAAM,MAAM,GAAG;AAClC,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,MAAM,KAAK,OAAO,MAAM,GAAG;AACpC,WAAO,OAAO,QAAQ,MAAM,OAAO,QAAQ;AAAA,EAC7C;AAEA,MAAI,kBAAkB,UAAU,kBAAkB,QA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d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { SerializedTags, Tag, TaggedValue } from '@bessemer/cornerstone/tag';
|
|
2
|
-
import { UnknownRecord } from 'type-fest';
|
|
3
|
-
import { DeepPartial } from '@bessemer/cornerstone/types';
|
|
2
|
+
import { PartialDeep, UnknownRecord } from 'type-fest';
|
|
4
3
|
export type PropertyRecord<T extends UnknownRecord> = {
|
|
5
4
|
values: T;
|
|
6
5
|
overrides: Record<SerializedTags, PropertyOverride<T>>;
|
|
7
6
|
};
|
|
8
|
-
export type PropertyOverride<T> = TaggedValue<
|
|
7
|
+
export type PropertyOverride<T> = TaggedValue<PartialDeep<T>>;
|
|
9
8
|
export declare const properties: <T extends UnknownRecord>(values: T, overrides?: Array<PropertyOverride<T>>) => PropertyRecord<T>;
|
|
10
9
|
export declare const resolve: <T extends UnknownRecord>(properties: PropertyRecord<T>, tags: Array<Tag>) => T;
|
|
11
10
|
//# sourceMappingURL=property.d.ts.map
|
package/dist/property.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../src/property.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,cAAc,EAAiB,GAAG,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAClH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../src/property.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,cAAc,EAAiB,GAAG,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAClH,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAGtD,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,aAAa,IAAI;IACpD,MAAM,EAAE,CAAC,CAAA;IACT,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAA;CACvD,CAAA;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7D,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,aAAa,EAAE,QAAQ,CAAC,EAAE,YAAY,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,KAAG,cAAc,CAAC,CAAC,CAWvH,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,aAAa,EAAE,YAAY,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,KAAG,CAGlG,CAAA"}
|
package/dist/property.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/property.ts"],"sourcesContent":["import { resolve as resolveTag, SerializedTags, serializeTags, Tag, TaggedValue } from '@bessemer/cornerstone/tag'\nimport { UnknownRecord } from 'type-fest'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/property.ts"],"sourcesContent":["import { resolve as resolveTag, SerializedTags, serializeTags, Tag, TaggedValue } from '@bessemer/cornerstone/tag'\nimport { PartialDeep, UnknownRecord } from 'type-fest'\nimport { deepMergeAll } from '@bessemer/cornerstone/object'\n\nexport type PropertyRecord<T extends UnknownRecord> = {\n values: T\n overrides: Record<SerializedTags, PropertyOverride<T>>\n}\n\nexport type PropertyOverride<T> = TaggedValue<PartialDeep<T>>\n\nexport const properties = <T extends UnknownRecord>(values: T, overrides?: Array<PropertyOverride<T>>): PropertyRecord<T> => {\n const propertyOverrideEntries = (overrides ?? []).map((override) => {\n return [serializeTags(override.tags), override]\n })\n\n const propertyOverrides: Record<SerializedTags, PropertyOverride<T>> = Object.fromEntries(propertyOverrideEntries)\n\n return {\n values,\n overrides: propertyOverrides,\n }\n}\n\nexport const resolve = <T extends UnknownRecord>(properties: PropertyRecord<T>, tags: Array<Tag>): T => {\n const overrides = resolveTag(Object.values(properties.overrides), tags)\n return deepMergeAll([properties.values, ...overrides.reverse()]) as T\n}\n"],"mappings":";AAAA,SAAS,WAAW,YAA4B,qBAAuC;AAEvF,SAAS,oBAAoB;AAStB,IAAM,aAAa,CAA0B,QAAW,cAA8D;AAC3H,QAAM,2BAA2B,aAAa,CAAC,GAAG,IAAI,CAAC,aAAa;AAClE,WAAO,CAAC,cAAc,SAAS,IAAI,GAAG,QAAQ;AAAA,EAChD,CAAC;AAED,QAAM,oBAAiE,OAAO,YAAY,uBAAuB;AAEjH,SAAO;AAAA,IACL;AAAA,IACA,WAAW;AAAA,EACb;AACF;AAEO,IAAM,UAAU,CAA0BA,aAA+B,SAAwB;AACtG,QAAM,YAAY,WAAW,OAAO,OAAOA,YAAW,SAAS,GAAG,IAAI;AACtE,SAAO,aAAa,CAACA,YAAW,QAAQ,GAAG,UAAU,QAAQ,CAAC,CAAC;AACjE;","names":["properties"]}
|
package/dist/resource-key.d.ts
CHANGED
|
@@ -9,13 +9,15 @@ export type NamespacedKey<KeyType extends ResourceKey = ResourceKey, NamespaceTy
|
|
|
9
9
|
NamespaceType
|
|
10
10
|
]>;
|
|
11
11
|
export declare const emptyNamespace: () => ResourceNamespace<undefined>;
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const createNamespace: <T extends NamespaceKey>(value: T) => ResourceNamespace<T>;
|
|
13
|
+
export declare const createCompositeNamespace: (...names: Array<ResourceNamespace>) => ResourceNamespace;
|
|
13
14
|
export declare const ResourceNamespaceSchema: Zod.ZodPipe<Zod.ZodOptional<Zod.ZodString>, Zod.ZodTransform<(string & import("@bessemer/cornerstone/types").NominalTyping<"ResourceNamespace">) | undefined, string | undefined>>;
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
15
|
+
export declare const namespaceKey: <KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey>(key: KeyType, namespace: ResourceNamespace<NamespaceType>) => NamespacedKey<KeyType, NamespaceType>;
|
|
16
|
+
export declare const namespaceKeys: <KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey>(keys: Array<KeyType>, namespace: ResourceNamespace<NamespaceType>) => Array<NamespacedKey<KeyType, NamespaceType>>;
|
|
17
|
+
export declare const destructureKey: <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(key: NamespacedKey<KeyType, NamespaceType>) => [KeyType, ResourceNamespace<NamespaceType>];
|
|
17
18
|
export declare const getKey: <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(namespacedKey: NamespacedKey<KeyType, NamespaceType>) => KeyType;
|
|
18
|
-
export declare const
|
|
19
|
+
export declare const getNamespace: <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(namespacedKey: NamespacedKey<KeyType, NamespaceType>) => ResourceNamespace<NamespaceType>;
|
|
20
|
+
export declare const extendNamespace: <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(namespacedKey: NamespacedKey<KeyType, NamespaceType>, additionalNamespace: ResourceNamespace) => NamespacedKey<KeyType>;
|
|
19
21
|
export declare const encodeKey: (key: ResourceKey) => ResourceKey;
|
|
20
22
|
export declare const decodeKey: (encodedKey: ResourceKey) => ResourceKey;
|
|
21
23
|
//# sourceMappingURL=resource-key.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-key.d.ts","sourceRoot":"","sources":["../src/resource-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,GAAG,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"resource-key.d.ts","sourceRoot":"","sources":["../src/resource-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,GAAG,MAAM,KAAK,CAAA;AAGrB,MAAM,MAAM,WAAW,GAAG,MAAM,CAAA;AAGhC,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,CAAA;AAC7C,MAAM,MAAM,iBAAiB,CAAC,aAAa,SAAS,YAAY,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,aAAa,SAAS,YAAY,EACpF,eAAe,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,KACnD,OAGF,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,WAAW,EAAE,aAAa,SAAS,YAAY,EAC1F,eAAe,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,KACnD,iBAAiB,CAAC,aAAa,CAGjC,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,OAAO,SAAS,WAAW,EAAE,aAAa,SAAS,YAAY,EAC7F,eAAe,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,EACpD,qBAAqB,iBAAiB,KACrC,aAAa,CAAC,OAAO,CAIvB,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,WAAW,KAAG,WAE5C,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,YAAY,WAAW,KAAG,WAEnD,CAAA"}
|
package/dist/resource-key.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// src/resource-key.ts
|
|
2
2
|
import Zod from "zod";
|
|
3
|
+
import { isPresent } from "@bessemer/cornerstone/object";
|
|
3
4
|
var ResourceNamespaceSeparator = "/";
|
|
4
5
|
var emptyNamespace = () => {
|
|
5
6
|
return void 0;
|
|
6
7
|
};
|
|
7
|
-
var
|
|
8
|
+
var createNamespace = (value) => {
|
|
8
9
|
if (value === void 0) {
|
|
9
10
|
return value;
|
|
10
11
|
}
|
|
@@ -13,17 +14,20 @@ var namespace = (value) => {
|
|
|
13
14
|
}
|
|
14
15
|
return value;
|
|
15
16
|
};
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
var createCompositeNamespace = (...names) => {
|
|
18
|
+
return names.filter(isPresent).join(ResourceNamespaceSeparator);
|
|
19
|
+
};
|
|
20
|
+
var ResourceNamespaceSchema = Zod.string().optional().transform(createNamespace);
|
|
21
|
+
var namespaceKey = (key, namespace) => {
|
|
22
|
+
if (namespace === void 0) {
|
|
19
23
|
return encodeKey(key);
|
|
20
24
|
}
|
|
21
|
-
return `${
|
|
25
|
+
return `${namespace}${ResourceNamespaceSeparator}${encodeKey(key)}`;
|
|
22
26
|
};
|
|
23
|
-
var
|
|
24
|
-
return keys.map((it) =>
|
|
27
|
+
var namespaceKeys = (keys, namespace) => {
|
|
28
|
+
return keys.map((it) => namespaceKey(it, namespace));
|
|
25
29
|
};
|
|
26
|
-
var
|
|
30
|
+
var destructureKey = (key) => {
|
|
27
31
|
const lastIndex = key.lastIndexOf(ResourceNamespaceSeparator);
|
|
28
32
|
if (lastIndex !== -1) {
|
|
29
33
|
const namespacePart = key.substring(0, lastIndex);
|
|
@@ -35,11 +39,17 @@ var splitNamespace = (key) => {
|
|
|
35
39
|
}
|
|
36
40
|
};
|
|
37
41
|
var getKey = (namespacedKey) => {
|
|
38
|
-
const [key, _] =
|
|
42
|
+
const [key, _] = destructureKey(namespacedKey);
|
|
39
43
|
return key;
|
|
40
44
|
};
|
|
41
|
-
var
|
|
42
|
-
|
|
45
|
+
var getNamespace = (namespacedKey) => {
|
|
46
|
+
const [_, namespace] = destructureKey(namespacedKey);
|
|
47
|
+
return namespace;
|
|
48
|
+
};
|
|
49
|
+
var extendNamespace = (namespacedKey, additionalNamespace) => {
|
|
50
|
+
const [type, namespace] = destructureKey(namespacedKey);
|
|
51
|
+
const extendedNamespace = createCompositeNamespace(additionalNamespace, namespace);
|
|
52
|
+
return namespaceKey(type, extendedNamespace);
|
|
43
53
|
};
|
|
44
54
|
var encodeKey = (key) => {
|
|
45
55
|
return key.replace(/%/g, "%25").replace(/\//g, "%2F");
|
|
@@ -49,14 +59,16 @@ var decodeKey = (encodedKey) => {
|
|
|
49
59
|
};
|
|
50
60
|
export {
|
|
51
61
|
ResourceNamespaceSchema,
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
createCompositeNamespace,
|
|
63
|
+
createNamespace,
|
|
54
64
|
decodeKey,
|
|
65
|
+
destructureKey,
|
|
55
66
|
emptyNamespace,
|
|
56
67
|
encodeKey,
|
|
57
68
|
extendNamespace,
|
|
58
69
|
getKey,
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
getNamespace,
|
|
71
|
+
namespaceKey,
|
|
72
|
+
namespaceKeys
|
|
61
73
|
};
|
|
62
74
|
//# sourceMappingURL=resource-key.js.map
|
package/dist/resource-key.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/resource-key.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\n\nexport type ResourceKey = string\nconst ResourceNamespaceSeparator = '/'\n\nexport type NamespaceKey = string | undefined\nexport type ResourceNamespace<NamespaceType extends NamespaceKey = NamespaceKey> = NominalType<NamespaceType, 'ResourceNamespace'> | undefined\n\nexport type NamespacedKey<KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey> = NominalType<\n string,\n ['NamespacedKey', KeyType, NamespaceType]\n>\n\nexport const emptyNamespace = (): ResourceNamespace<undefined> => {\n return undefined\n}\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../src/resource-key.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport { isPresent } from '@bessemer/cornerstone/object'\n\nexport type ResourceKey = string\nconst ResourceNamespaceSeparator = '/'\n\nexport type NamespaceKey = string | undefined\nexport type ResourceNamespace<NamespaceType extends NamespaceKey = NamespaceKey> = NominalType<NamespaceType, 'ResourceNamespace'> | undefined\n\nexport type NamespacedKey<KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey> = NominalType<\n string,\n ['NamespacedKey', KeyType, NamespaceType]\n>\n\nexport const emptyNamespace = (): ResourceNamespace<undefined> => {\n return undefined\n}\n\nexport const createNamespace = <T extends NamespaceKey>(value: T): ResourceNamespace<T> => {\n if (value === undefined) {\n return value as any as ResourceNamespace<T>\n }\n\n if (!/^[^\\s\\/][^\\s\\/]*(?:\\/[^\\s\\/][^\\s\\/]*)*$/.test(value)) {\n throw new Error(`Unsupported Namespace format: ${value}`)\n }\n\n return value as ResourceNamespace<T>\n}\n\nexport const createCompositeNamespace = (...names: Array<ResourceNamespace>): ResourceNamespace => {\n return names.filter(isPresent).join(ResourceNamespaceSeparator) as ResourceNamespace\n}\n\nexport const ResourceNamespaceSchema = Zod.string().optional().transform(createNamespace)\n\nexport const namespaceKey = <KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey>(\n key: KeyType,\n namespace: ResourceNamespace<NamespaceType>\n): NamespacedKey<KeyType, NamespaceType> => {\n if (namespace === undefined) {\n return encodeKey(key) as NamespacedKey<KeyType, NamespaceType>\n }\n\n return `${namespace}${ResourceNamespaceSeparator}${encodeKey(key)}` as NamespacedKey<KeyType, NamespaceType>\n}\n\nexport const namespaceKeys = <KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey>(\n keys: Array<KeyType>,\n namespace: ResourceNamespace<NamespaceType>\n): Array<NamespacedKey<KeyType, NamespaceType>> => {\n return keys.map((it) => namespaceKey(it, namespace))\n}\n\nexport const destructureKey = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n key: NamespacedKey<KeyType, NamespaceType>\n): [KeyType, ResourceNamespace<NamespaceType>] => {\n const lastIndex = key.lastIndexOf(ResourceNamespaceSeparator)\n\n if (lastIndex !== -1) {\n const namespacePart = key.substring(0, lastIndex)\n const keyPart = key.substring(lastIndex + 1)\n\n return [decodeKey(keyPart) as KeyType, namespacePart as ResourceNamespace<NamespaceType>]\n } else {\n const keyPart = key\n return [decodeKey(keyPart) as KeyType, undefined as ResourceNamespace<NamespaceType>]\n }\n}\n\nexport const getKey = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n namespacedKey: NamespacedKey<KeyType, NamespaceType>\n): KeyType => {\n const [key, _] = destructureKey(namespacedKey)\n return key\n}\n\nexport const getNamespace = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n namespacedKey: NamespacedKey<KeyType, NamespaceType>\n): ResourceNamespace<NamespaceType> => {\n const [_, namespace] = destructureKey(namespacedKey)\n return namespace\n}\n\nexport const extendNamespace = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n namespacedKey: NamespacedKey<KeyType, NamespaceType>,\n additionalNamespace: ResourceNamespace\n): NamespacedKey<KeyType> => {\n const [type, namespace] = destructureKey(namespacedKey)\n const extendedNamespace = createCompositeNamespace(additionalNamespace, namespace)\n return namespaceKey(type, extendedNamespace)\n}\n\nexport const encodeKey = (key: ResourceKey): ResourceKey => {\n return key.replace(/%/g, '%25').replace(/\\//g, '%2F')\n}\n\nexport const decodeKey = (encodedKey: ResourceKey): ResourceKey => {\n return encodedKey.replace(/%2F/g, '/').replace(/%25/g, '%')\n}\n"],"mappings":";AACA,OAAO,SAAS;AAChB,SAAS,iBAAiB;AAG1B,IAAM,6BAA6B;AAU5B,IAAM,iBAAiB,MAAoC;AAChE,SAAO;AACT;AAEO,IAAM,kBAAkB,CAAyB,UAAmC;AACzF,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,0CAA0C,KAAK,KAAK,GAAG;AAC1D,UAAM,IAAI,MAAM,iCAAiC,KAAK,EAAE;AAAA,EAC1D;AAEA,SAAO;AACT;AAEO,IAAM,2BAA2B,IAAI,UAAuD;AACjG,SAAO,MAAM,OAAO,SAAS,EAAE,KAAK,0BAA0B;AAChE;AAEO,IAAM,0BAA0B,IAAI,OAAO,EAAE,SAAS,EAAE,UAAU,eAAe;AAEjF,IAAM,eAAe,CAC1B,KACA,cAC0C;AAC1C,MAAI,cAAc,QAAW;AAC3B,WAAO,UAAU,GAAG;AAAA,EACtB;AAEA,SAAO,GAAG,SAAS,GAAG,0BAA0B,GAAG,UAAU,GAAG,CAAC;AACnE;AAEO,IAAM,gBAAgB,CAC3B,MACA,cACiD;AACjD,SAAO,KAAK,IAAI,CAAC,OAAO,aAAa,IAAI,SAAS,CAAC;AACrD;AAEO,IAAM,iBAAiB,CAC5B,QACgD;AAChD,QAAM,YAAY,IAAI,YAAY,0BAA0B;AAE5D,MAAI,cAAc,IAAI;AACpB,UAAM,gBAAgB,IAAI,UAAU,GAAG,SAAS;AAChD,UAAM,UAAU,IAAI,UAAU,YAAY,CAAC;AAE3C,WAAO,CAAC,UAAU,OAAO,GAAc,aAAiD;AAAA,EAC1F,OAAO;AACL,UAAM,UAAU;AAChB,WAAO,CAAC,UAAU,OAAO,GAAc,MAA6C;AAAA,EACtF;AACF;AAEO,IAAM,SAAS,CACpB,kBACY;AACZ,QAAM,CAAC,KAAK,CAAC,IAAI,eAAe,aAAa;AAC7C,SAAO;AACT;AAEO,IAAM,eAAe,CAC1B,kBACqC;AACrC,QAAM,CAAC,GAAG,SAAS,IAAI,eAAe,aAAa;AACnD,SAAO;AACT;AAEO,IAAM,kBAAkB,CAC7B,eACA,wBAC2B;AAC3B,QAAM,CAAC,MAAM,SAAS,IAAI,eAAe,aAAa;AACtD,QAAM,oBAAoB,yBAAyB,qBAAqB,SAAS;AACjF,SAAO,aAAa,MAAM,iBAAiB;AAC7C;AAEO,IAAM,YAAY,CAAC,QAAkC;AAC1D,SAAO,IAAI,QAAQ,MAAM,KAAK,EAAE,QAAQ,OAAO,KAAK;AACtD;AAEO,IAAM,YAAY,CAAC,eAAyC;AACjE,SAAO,WAAW,QAAQ,QAAQ,GAAG,EAAE,QAAQ,QAAQ,GAAG;AAC5D;","names":[]}
|
package/dist/result.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAGvD,MAAM,MAAM,OAAO,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AW,CAAC,YAAY,CAAC,CAAA;AAc7G,wBAAgB,SAAS,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EACzD,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,EACrC,WAAW,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,UAAU,GAC/C,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,CAS/B"}
|
package/dist/result.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/result.ts
|
|
2
|
-
import
|
|
2
|
+
import * as Eithers from "@bessemer/cornerstone/either";
|
|
3
3
|
import { isPromise } from "@bessemer/cornerstone/promise";
|
|
4
4
|
var success = (value) => {
|
|
5
|
-
return { ...right(value), isSuccess: true };
|
|
5
|
+
return { ...Eithers.right(value), isSuccess: true };
|
|
6
6
|
};
|
|
7
7
|
function failure(failure2) {
|
|
8
|
-
return { ...left(failure2 ?? null), isSuccess: false };
|
|
8
|
+
return { ...Eithers.left(failure2 ?? null), isSuccess: false };
|
|
9
9
|
}
|
|
10
10
|
var getValueOrThrow = (result) => {
|
|
11
11
|
if (result.isSuccess) {
|
package/dist/result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/result.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/result.ts"],"sourcesContent":["import * as Eithers from '@bessemer/cornerstone/either'\nimport { Left, Right } from '@bessemer/cornerstone/either'\nimport { Throwable } from '@bessemer/cornerstone/types'\nimport { isPromise } from '@bessemer/cornerstone/promise'\n\nexport type Success<T> = Right<T> & {\n isSuccess: true\n}\n\nexport type Failure<N = Throwable> = Left<N> & {\n isSuccess: false\n}\n\nexport type Result<T, N = Throwable> = Success<T> | Failure<N>\n\nexport type AsyncResult<T, N = Throwable> = Promise<Result<T, N>>\n\nexport const success = <T>(value: T): Success<T> => {\n return { ...Eithers.right(value), isSuccess: true }\n}\n\nexport function failure(): Failure<never>\nexport function failure<N>(failure: N): Failure<N>\nexport function failure(failure?: unknown): Failure {\n return { ...Eithers.left(failure ?? null), isSuccess: false }\n}\n\nexport const getValueOrThrow = <T>(result: Result<T>): T => {\n if (result.isSuccess) {\n return result.value\n } else {\n throw result.value\n }\n}\n\nexport function tryValue<SOURCE_VALUE>(resolver: () => Promise<SOURCE_VALUE>): AsyncResult<SOURCE_VALUE>\nexport function tryValue<SOURCE_VALUE>(resolver: () => SOURCE_VALUE): Result<SOURCE_VALUE>\nexport function tryValue<SOURCE_VALUE>(resolver: () => SOURCE_VALUE | Promise<SOURCE_VALUE>): Result<SOURCE_VALUE> | Promise<Result<SOURCE_VALUE>> {\n try {\n let result = resolver()\n if (isPromise(result)) {\n return result.then((it) => success(it)).catch((it) => failure(it))\n } else {\n return success(result)\n }\n } catch (e: any) {\n return failure(e)\n }\n}\n\nexport function tryResult<SOURCE_VALUE>(resolver: () => Result<SOURCE_VALUE>): Result<SOURCE_VALUE>\nexport function tryResult<SOURCE_VALUE>(resolver: () => AsyncResult<SOURCE_VALUE>): AsyncResult<SOURCE_VALUE>\nexport function tryResult<SOURCE_VALUE>(resolver: () => Result<SOURCE_VALUE> | AsyncResult<SOURCE_VALUE>): ReturnType<typeof resolver> {\n try {\n let result = resolver()\n if (isPromise(result)) {\n return result.catch((it) => failure(it))\n } else {\n return result\n }\n } catch (e: any) {\n return failure(e)\n }\n}\n\nexport function mapResult<SourceType, TargetType, ErrorType>(\n result: Result<SourceType, ErrorType>,\n valueMapper: (element: SourceType) => TargetType\n): Result<TargetType, ErrorType> {\n if (result.isSuccess) {\n return {\n ...result,\n value: valueMapper(result.value),\n }\n } else {\n return result\n }\n}\n"],"mappings":";AAAA,YAAY,aAAa;AAGzB,SAAS,iBAAiB;AAcnB,IAAM,UAAU,CAAI,UAAyB;AAClD,SAAO,EAAE,GAAW,cAAM,KAAK,GAAG,WAAW,KAAK;AACpD;AAIO,SAAS,QAAQA,UAA4B;AAClD,SAAO,EAAE,GAAW,aAAKA,YAAW,IAAI,GAAG,WAAW,MAAM;AAC9D;AAEO,IAAM,kBAAkB,CAAI,WAAyB;AAC1D,MAAI,OAAO,WAAW;AACpB,WAAO,OAAO;AAAA,EAChB,OAAO;AACL,UAAM,OAAO;AAAA,EACf;AACF;AAIO,SAAS,SAAuB,UAA4G;AACjJ,MAAI;AACF,QAAI,SAAS,SAAS;AACtB,QAAI,UAAU,MAAM,GAAG;AACrB,aAAO,OAAO,KAAK,CAAC,OAAO,QAAQ,EAAE,CAAC,EAAE,MAAM,CAAC,OAAO,QAAQ,EAAE,CAAC;AAAA,IACnE,OAAO;AACL,aAAO,QAAQ,MAAM;AAAA,IACvB;AAAA,EACF,SAAS,GAAQ;AACf,WAAO,QAAQ,CAAC;AAAA,EAClB;AACF;AAIO,SAAS,UAAwB,UAA+F;AACrI,MAAI;AACF,QAAI,SAAS,SAAS;AACtB,QAAI,UAAU,MAAM,GAAG;AACrB,aAAO,OAAO,MAAM,CAAC,OAAO,QAAQ,EAAE,CAAC;AAAA,IACzC,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAQ;AACf,WAAO,QAAQ,CAAC;AAAA,EAClB;AACF;AAEO,SAAS,UACd,QACA,aAC+B;AAC/B,MAAI,OAAO,WAAW;AACpB,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,YAAY,OAAO,KAAK;AAAA,IACjC;AAAA,EACF,OAAO;AACL,WAAO;AAAA,EACT;AACF;","names":["failure"]}
|
package/dist/string.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { UnknownRecord } from 'type-fest';
|
|
2
|
-
export declare const isString: (value
|
|
3
|
-
export declare const isEmpty:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(value: string): value is "";
|
|
8
|
-
(value: Map<any, any> | Set<any> | import("lodash").List<any> | null | undefined): boolean;
|
|
9
|
-
(value: object): boolean;
|
|
10
|
-
<T extends object>(value: T | null | undefined): value is import("lodash").EmptyObjectOf<T> | null | undefined;
|
|
11
|
-
(value?: any): boolean;
|
|
12
|
-
};
|
|
2
|
+
export declare const isString: (value: any) => value is string;
|
|
3
|
+
export declare const isEmpty: (value: string) => boolean;
|
|
4
|
+
export declare const isEmptyOrNil: (value: string | null | undefined) => boolean;
|
|
5
|
+
export declare const emptyToNull: (value: string) => string | null;
|
|
6
|
+
export declare const isBlank: (str?: string | null) => boolean;
|
|
13
7
|
export type StringSplitResult = {
|
|
14
8
|
selection: string;
|
|
15
9
|
separator: string;
|
|
@@ -23,18 +17,13 @@ export declare const splitFirst: (str: string, splitter: string | RegExp) => Str
|
|
|
23
17
|
export declare const splitLast: (str: string, splitter: string | RegExp) => StringSplitResult;
|
|
24
18
|
export declare const splitLastRegex: (str: string, regex: RegExp) => StringSplitResult;
|
|
25
19
|
export declare const splitAt: (str: string, index: number) => [string, string];
|
|
26
|
-
export declare const startsWith: (string?: string, target?: string, position?: number) => boolean;
|
|
27
|
-
export declare const endsWith: (string?: string, target?: string, position?: number) => boolean;
|
|
28
20
|
export declare const removeStart: (string: string, substring: string) => string;
|
|
29
21
|
export declare const removeEnd: (string: string, substring: string) => string;
|
|
30
|
-
export declare const isBlank: (str?: string | null) => boolean;
|
|
31
22
|
export declare const mostCentralOccurrence: (str: string, substr: string) => number | null;
|
|
32
23
|
export declare const replacePlaceholders: (string: string, parameters: UnknownRecord, getParamPlaceholder?: (paramName: string) => string) => string;
|
|
33
|
-
export declare const padStart: (
|
|
34
|
-
export declare const padEnd: (
|
|
35
|
-
export declare const
|
|
36
|
-
export declare
|
|
37
|
-
|
|
38
|
-
(pattern: RegExp | string, replacement: import("lodash").ReplaceFunction | string): string;
|
|
39
|
-
};
|
|
24
|
+
export declare const padStart: (str: string, length: number, chars: string) => string;
|
|
25
|
+
export declare const padEnd: (str: string, length: number, chars: string) => string;
|
|
26
|
+
export declare const isNumber: (value: string) => boolean;
|
|
27
|
+
export declare namespace Schema {
|
|
28
|
+
}
|
|
40
29
|
//# sourceMappingURL=string.d.ts.map
|
package/dist/string.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAKzC,eAAO,MAAM,QAAQ,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,MAE9C,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,KAAG,OAEvC,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,OAM/D,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,GAAG,IAMpD,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,GAAG,IAAI,KAAG,OAG7C,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3I,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,GAAG,MAAM,KAAG,iBAqBnE,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,GAAG,MAAM,KAAG,iBAgClE,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,EAAE,OAAO,MAAM,KAAG,iBAuB3D,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,EAAE,OAAO,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CAEnE,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MAM/D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MAM7D,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,EAAE,QAAQ,MAAM,KAAG,MAAM,GAAG,IA2B5E,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,QAAQ,MAAM,EAAE,YAAY,aAAa,EAAE,uBAAuB,WAAW,MAAM,WAAuB,WAK7I,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,MASrE,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,KAAK,MAAM,EAAE,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,MASnE,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,OAOxC,CAAA;AAED,yBAAiB,MAAM,CAAC;CAMvB"}
|
package/dist/string.js
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
// src/string.ts
|
|
2
|
-
import {
|
|
3
|
-
endsWith as _endsWith,
|
|
4
|
-
includes as _includes,
|
|
5
|
-
isEmpty as _isEmpty,
|
|
6
|
-
padEnd as _padEnd,
|
|
7
|
-
padStart as _padStart,
|
|
8
|
-
replace as _replace,
|
|
9
|
-
startsWith as _startsWith
|
|
10
|
-
} from "lodash-es";
|
|
11
2
|
import { rest } from "@bessemer/cornerstone/array";
|
|
3
|
+
import { isNil } from "@bessemer/cornerstone/object";
|
|
4
|
+
import Zod from "zod";
|
|
12
5
|
var isString = (value) => {
|
|
13
6
|
return typeof value === "string";
|
|
14
7
|
};
|
|
15
|
-
var isEmpty =
|
|
8
|
+
var isEmpty = (value) => {
|
|
9
|
+
return value.length === 0;
|
|
10
|
+
};
|
|
11
|
+
var isEmptyOrNil = (value) => {
|
|
12
|
+
if (isNil(value)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return isEmpty(value);
|
|
16
|
+
};
|
|
17
|
+
var emptyToNull = (value) => {
|
|
18
|
+
if (isEmptyOrNil(value)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var isBlank = (str) => {
|
|
24
|
+
const testStr = str ?? "";
|
|
25
|
+
return /^\s*$/.test(testStr);
|
|
26
|
+
};
|
|
16
27
|
var splitFirst = (str, splitter) => {
|
|
17
28
|
if (isString(splitter)) {
|
|
18
29
|
const results = str.split(splitter);
|
|
@@ -81,8 +92,6 @@ var splitLastRegex = (str, regex) => {
|
|
|
81
92
|
var splitAt = (str, index) => {
|
|
82
93
|
return [str.slice(0, index), str.slice(index)];
|
|
83
94
|
};
|
|
84
|
-
var startsWith = _startsWith;
|
|
85
|
-
var endsWith = _endsWith;
|
|
86
95
|
var removeStart = (string, substring) => {
|
|
87
96
|
if (!string.startsWith(substring)) {
|
|
88
97
|
return string;
|
|
@@ -95,10 +104,6 @@ var removeEnd = (string, substring) => {
|
|
|
95
104
|
}
|
|
96
105
|
return string.slice(0, -substring.length);
|
|
97
106
|
};
|
|
98
|
-
var isBlank = (str) => {
|
|
99
|
-
const testStr = str ?? "";
|
|
100
|
-
return /^\s*$/.test(testStr);
|
|
101
|
-
};
|
|
102
107
|
var mostCentralOccurrence = (str, substr) => {
|
|
103
108
|
const occurrences = [];
|
|
104
109
|
let index = str.indexOf(substr);
|
|
@@ -127,27 +132,51 @@ var replacePlaceholders = (string, parameters, getParamPlaceholder = (paramName)
|
|
|
127
132
|
string
|
|
128
133
|
);
|
|
129
134
|
};
|
|
130
|
-
var padStart =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
var padStart = (str, length, chars) => {
|
|
136
|
+
if (str.length >= length) {
|
|
137
|
+
return str;
|
|
138
|
+
}
|
|
139
|
+
const padLength = length - str.length;
|
|
140
|
+
const padString = chars.repeat(Math.ceil(padLength / chars.length));
|
|
141
|
+
return padString.slice(0, padLength) + str;
|
|
142
|
+
};
|
|
143
|
+
var padEnd = (str, length, chars) => {
|
|
144
|
+
if (str.length >= length) {
|
|
145
|
+
return str;
|
|
146
|
+
}
|
|
147
|
+
const padLength = length - str.length;
|
|
148
|
+
const padString = chars.repeat(Math.ceil(padLength / chars.length));
|
|
149
|
+
return str + padString.slice(0, padLength);
|
|
150
|
+
};
|
|
151
|
+
var isNumber = (value) => {
|
|
152
|
+
if (value.trim() === "") {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const num = Number(value);
|
|
156
|
+
return !isNaN(num) && isFinite(num);
|
|
157
|
+
};
|
|
158
|
+
var Schema;
|
|
159
|
+
((Schema2) => {
|
|
160
|
+
const Text = Zod.string().trim().min(1);
|
|
161
|
+
const TextNullable = Zod.string().trim().transform((val) => isEmpty(val) ? null : val);
|
|
162
|
+
})(Schema || (Schema = {}));
|
|
134
163
|
export {
|
|
135
|
-
|
|
136
|
-
|
|
164
|
+
Schema,
|
|
165
|
+
emptyToNull,
|
|
137
166
|
isBlank,
|
|
138
167
|
isEmpty,
|
|
168
|
+
isEmptyOrNil,
|
|
169
|
+
isNumber,
|
|
139
170
|
isString,
|
|
140
171
|
mostCentralOccurrence,
|
|
141
172
|
padEnd,
|
|
142
173
|
padStart,
|
|
143
174
|
removeEnd,
|
|
144
175
|
removeStart,
|
|
145
|
-
replace,
|
|
146
176
|
replacePlaceholders,
|
|
147
177
|
splitAt,
|
|
148
178
|
splitFirst,
|
|
149
179
|
splitLast,
|
|
150
|
-
splitLastRegex
|
|
151
|
-
startsWith
|
|
180
|
+
splitLastRegex
|
|
152
181
|
};
|
|
153
182
|
//# sourceMappingURL=string.js.map
|
package/dist/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/string.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/string.ts"],"sourcesContent":["import { UnknownRecord } from 'type-fest'\nimport { rest } from '@bessemer/cornerstone/array'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport Zod from 'zod'\n\nexport const isString = (value: any): value is string => {\n return typeof value === 'string'\n}\n\nexport const isEmpty = (value: string): boolean => {\n return value.length === 0\n}\n\nexport const isEmptyOrNil = (value: string | null | undefined): boolean => {\n if (isNil(value)) {\n return true\n }\n\n return isEmpty(value)\n}\n\nexport const emptyToNull = (value: string): string | null => {\n if (isEmptyOrNil(value)) {\n return null\n }\n\n return value\n}\n\nexport const isBlank = (str?: string | null): boolean => {\n const testStr = str ?? ''\n return /^\\s*$/.test(testStr)\n}\n\nexport type StringSplitResult = { selection: string; separator: string; rest: string } | { selection: null; separator: null; rest: string }\n\nexport const splitFirst = (str: string, splitter: string | RegExp): StringSplitResult => {\n if (isString(splitter)) {\n const results = str.split(splitter)\n if (results.length === 1) {\n return { selection: null, separator: null, rest: str }\n }\n\n return { selection: results[0]!, separator: splitter, rest: rest(results).join(splitter) }\n } else {\n const match = splitter.exec(str)\n\n if (!match) {\n return { selection: null, separator: null, rest: str }\n }\n\n const matchIndex = match.index\n const beforeMatch = str.slice(0, matchIndex)\n const afterMatch = str.slice(matchIndex + match[0].length)\n const separator = match[0]\n return { selection: beforeMatch, separator, rest: afterMatch }\n }\n}\n\nexport const splitLast = (str: string, splitter: string | RegExp): StringSplitResult => {\n if (isString(splitter)) {\n const results = str.split(splitter)\n if (results.length === 1) {\n return { selection: null, separator: null, rest: str }\n }\n\n return { selection: results[results.length - 1]!, separator: splitter, rest: results.slice(0, results.length - 1).join(splitter) }\n } else {\n if (!splitter.global) {\n splitter = new RegExp(splitter.source, splitter.flags + 'g')\n }\n\n const matches = Array.from(str.matchAll(splitter))\n\n if (matches.length === 0) {\n return { selection: null, separator: null, rest: str }\n }\n\n // Use the last match\n const lastMatch = matches[matches.length - 1]!\n const matchIndex = lastMatch.index!\n const separator = lastMatch[0]!\n const beforeMatch = str.slice(0, matchIndex)\n const afterMatch = str.slice(matchIndex + separator.length)\n\n return {\n selection: afterMatch,\n separator: separator,\n rest: beforeMatch,\n }\n }\n}\n\nexport const splitLastRegex = (str: string, regex: RegExp): StringSplitResult => {\n // Find the last match using regex lastIndex\n let lastMatch: RegExpExecArray | null = null\n let match\n\n while ((match = regex.exec(str)) !== null) {\n lastMatch = match\n }\n\n if (!lastMatch) {\n return { selection: null, separator: null, rest: str }\n }\n\n const matchIndex = lastMatch.index!\n const separator = lastMatch[0]\n const beforeMatch = str.slice(0, matchIndex)\n const afterMatch = str.slice(matchIndex + separator.length)\n\n return {\n selection: afterMatch,\n separator,\n rest: beforeMatch,\n }\n}\n\nexport const splitAt = (str: string, index: number): [string, string] => {\n return [str.slice(0, index), str.slice(index)] as const\n}\n\nexport const removeStart = (string: string, substring: string): string => {\n if (!string.startsWith(substring)) {\n return string\n }\n\n return string.slice(substring.length)\n}\n\nexport const removeEnd = (string: string, substring: string): string => {\n if (!string.endsWith(substring)) {\n return string\n }\n\n return string.slice(0, -substring.length)\n}\n\nexport const mostCentralOccurrence = (str: string, substr: string): number | null => {\n const occurrences: number[] = []\n let index = str.indexOf(substr)\n\n while (index !== -1) {\n occurrences.push(index)\n index = str.indexOf(substr, index + 1)\n }\n\n if (occurrences.length === 0) {\n return null\n }\n\n const center = str.length / 2\n\n let closestIndex = occurrences[0]!\n let minDistance = Math.abs(center - closestIndex)\n\n for (let i = 1; i < occurrences.length; i++) {\n const distance = Math.abs(center - occurrences[i]!)\n if (distance < minDistance) {\n minDistance = distance\n closestIndex = occurrences[i]!\n }\n }\n\n return closestIndex\n}\n\nexport const replacePlaceholders = (string: string, parameters: UnknownRecord, getParamPlaceholder = (paramName: string) => `{{${paramName}}}`) => {\n return Object.entries(parameters).reduce(\n (intermediateString, [paramName, paramValue]) => intermediateString.replaceAll(getParamPlaceholder(paramName), `${paramValue}`),\n string\n )\n}\n\nexport const padStart = (str: string, length: number, chars: string): string => {\n if (str.length >= length) {\n return str\n }\n\n const padLength = length - str.length\n const padString = chars.repeat(Math.ceil(padLength / chars.length))\n\n return padString.slice(0, padLength) + str\n}\n\nexport const padEnd = (str: string, length: number, chars: string): string => {\n if (str.length >= length) {\n return str\n }\n\n const padLength = length - str.length\n const padString = chars.repeat(Math.ceil(padLength / chars.length))\n\n return str + padString.slice(0, padLength)\n}\n\nexport const isNumber = (value: string): boolean => {\n if (value.trim() === '') {\n return false\n }\n\n const num = Number(value)\n return !isNaN(num) && isFinite(num)\n}\n\nexport namespace Schema {\n const Text = Zod.string().trim().min(1)\n\n const TextNullable = Zod.string()\n .trim()\n .transform((val) => (isEmpty(val) ? null : val))\n}\n"],"mappings":";AACA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,OAAO,SAAS;AAET,IAAM,WAAW,CAAC,UAAgC;AACvD,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,UAAU,CAAC,UAA2B;AACjD,SAAO,MAAM,WAAW;AAC1B;AAEO,IAAM,eAAe,CAAC,UAA8C;AACzE,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,KAAK;AACtB;AAEO,IAAM,cAAc,CAAC,UAAiC;AAC3D,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,UAAU,CAAC,QAAiC;AACvD,QAAM,UAAU,OAAO;AACvB,SAAO,QAAQ,KAAK,OAAO;AAC7B;AAIO,IAAM,aAAa,CAAC,KAAa,aAAiD;AACvF,MAAI,SAAS,QAAQ,GAAG;AACtB,UAAM,UAAU,IAAI,MAAM,QAAQ;AAClC,QAAI,QAAQ,WAAW,GAAG;AACxB,aAAO,EAAE,WAAW,MAAM,WAAW,MAAM,MAAM,IAAI;AAAA,IACvD;AAEA,WAAO,EAAE,WAAW,QAAQ,CAAC,GAAI,WAAW,UAAU,MAAM,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE;AAAA,EAC3F,OAAO;AACL,UAAM,QAAQ,SAAS,KAAK,GAA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M,eAAe,IAAI,OAAO,EAC7B,KAAK,EACL,UAAU,CAAC,QAAS,QAAQ,GAAG,IAAI,OAAO,GAAI;AAAA,GALlC;","names":["Schema"]}
|
package/dist/tag.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export declare const value: <T>(value: T, tags: Array<Tag>) => {
|
|
|
15
15
|
value: T;
|
|
16
16
|
tags: Tag<unknown>[];
|
|
17
17
|
};
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
18
|
+
export declare const CompareBy: Comparator<Tag<any>>;
|
|
19
|
+
export declare const EqualBy: Equalitor<Tag<any>>;
|
|
20
20
|
export type SerializedTags = TaggedType<string, 'SerializedTags'>;
|
|
21
21
|
export declare const serializeTags: <T>(tags: Array<Tag<T>>) => SerializedTags;
|
|
22
22
|
export declare const resolve: <T>(values: Array<TaggedValue<T>>, tags: Array<Tag>) => Array<TaggedValue<T>>;
|
package/dist/tag.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../src/tag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../src/tag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAkB,MAAM,iCAAiC,CAAA;AAI3E,MAAM,MAAM,OAAO,CAAC,QAAQ,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAA;AAEzE,MAAM,MAAM,GAAG,CAAC,QAAQ,GAAG,OAAO,IAAI;IACpC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;IACvB,KAAK,EAAE,QAAQ,CAAA;CAChB,CAAA;AAED,MAAM,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