@bessemer/cornerstone 0.5.113 → 0.5.115
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.map +1 -1
- package/dist/array.js +28 -28
- package/dist/array.js.map +1 -1
- package/dist/aspect-ratio.d.ts +3 -3
- package/dist/aspect-ratio.d.ts.map +1 -1
- package/dist/aspect-ratio.js +13 -12
- package/dist/aspect-ratio.js.map +1 -1
- package/dist/assertion.d.ts.map +1 -1
- package/dist/assertion.js +5 -5
- package/dist/assertion.js.map +1 -1
- package/dist/async-value.js +2 -2
- package/dist/async-value.js.map +1 -1
- package/dist/async.d.ts.map +1 -1
- package/dist/async.js +2 -2
- package/dist/async.js.map +1 -1
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +11 -12
- package/dist/cache.js.map +1 -1
- package/dist/combinable.js +5 -5
- package/dist/combinable.js.map +1 -1
- package/dist/comparator.js +8 -8
- package/dist/comparator.js.map +1 -1
- package/dist/data-size.d.ts +2 -1
- package/dist/data-size.d.ts.map +1 -1
- package/dist/data-size.js +3 -3
- package/dist/data-size.js.map +1 -1
- package/dist/either.js +5 -5
- package/dist/either.js.map +1 -1
- package/dist/equalitor.d.ts.map +1 -1
- package/dist/equalitor.js +2 -2
- package/dist/equalitor.js.map +1 -1
- package/dist/error/error-cause.d.ts.map +1 -1
- package/dist/error/error-cause.js +14 -14
- package/dist/error/error-cause.js.map +1 -1
- package/dist/error/error-code.js +2 -2
- package/dist/error/error-code.js.map +1 -1
- package/dist/error/error-event.d.ts +3 -2
- package/dist/error/error-event.d.ts.map +1 -1
- package/dist/error/error-event.js +28 -28
- package/dist/error/error-event.js.map +1 -1
- package/dist/error/error-type.d.ts +2 -1
- package/dist/error/error-type.d.ts.map +1 -1
- package/dist/error/error-type.js +2 -2
- package/dist/error/error-type.js.map +1 -1
- package/dist/error/error.js +5 -5
- package/dist/error/error.js.map +1 -1
- package/dist/expression/array-expression.js +3 -3
- package/dist/expression/array-expression.js.map +1 -1
- package/dist/expression/core-expression.d.ts.map +1 -1
- package/dist/expression/core-expression.js +19 -19
- package/dist/expression/core-expression.js.map +1 -1
- package/dist/expression/expression-evaluator.js +2 -2
- package/dist/expression/expression-evaluator.js.map +1 -1
- package/dist/expression/expression-mapper.js +4 -4
- package/dist/expression/expression-mapper.js.map +1 -1
- package/dist/expression/internal.js +3 -3
- package/dist/expression/internal.js.map +1 -1
- package/dist/expression/numeric-expression.js +13 -13
- package/dist/expression/numeric-expression.js.map +1 -1
- package/dist/expression/string-expression.js +4 -4
- package/dist/expression/string-expression.js.map +1 -1
- package/dist/expression.d.ts +17 -1
- package/dist/expression.d.ts.map +1 -1
- package/dist/expression.js.map +1 -1
- package/dist/glob.d.ts +3 -3
- package/dist/glob.d.ts.map +1 -1
- package/dist/glob.js +11 -12
- package/dist/glob.js.map +1 -1
- package/dist/global-variable.d.ts.map +1 -1
- package/dist/global-variable.js +5 -5
- package/dist/global-variable.js.map +1 -1
- package/dist/hex-code.d.ts +3 -3
- package/dist/hex-code.d.ts.map +1 -1
- package/dist/hex-code.js +11 -10
- package/dist/hex-code.js.map +1 -1
- package/dist/index.d.ts +311 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/intl/country-code.d.ts +3 -3
- package/dist/intl/country-code.d.ts.map +1 -1
- package/dist/intl/country-code.js +9 -10
- package/dist/intl/country-code.js.map +1 -1
- package/dist/intl/country-subdivision-code.d.ts +3 -3
- package/dist/intl/country-subdivision-code.d.ts.map +1 -1
- package/dist/intl/country-subdivision-code.js +13 -11
- package/dist/intl/country-subdivision-code.js.map +1 -1
- package/dist/intl/currency-code.d.ts +3 -3
- package/dist/intl/currency-code.d.ts.map +1 -1
- package/dist/intl/currency-code.js +9 -10
- package/dist/intl/currency-code.js.map +1 -1
- package/dist/intl/language-code.d.ts +3 -3
- package/dist/intl/language-code.d.ts.map +1 -1
- package/dist/intl/language-code.js +9 -10
- package/dist/intl/language-code.js.map +1 -1
- package/dist/intl/locale.d.ts +3 -3
- package/dist/intl/locale.d.ts.map +1 -1
- package/dist/intl/locale.js +18 -19
- package/dist/intl/locale.js.map +1 -1
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +2 -2
- package/dist/json.js.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +12 -12
- package/dist/logger.js.map +1 -1
- package/dist/map.d.ts +306 -0
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +8 -8
- package/dist/map.js.map +1 -1
- package/dist/mime-type.d.ts +3 -3
- package/dist/mime-type.d.ts.map +1 -1
- package/dist/mime-type.js +9 -10
- package/dist/mime-type.js.map +1 -1
- package/dist/misc.js +4 -4
- package/dist/misc.js.map +1 -1
- package/dist/monetary-amount.d.ts +3 -2
- package/dist/monetary-amount.d.ts.map +1 -1
- package/dist/monetary-amount.js +16 -16
- package/dist/monetary-amount.js.map +1 -1
- package/dist/net/content-type.d.ts +2 -1
- package/dist/net/content-type.d.ts.map +1 -1
- package/dist/net/content-type.js +2 -2
- package/dist/net/content-type.js.map +1 -1
- package/dist/net/domain-name.d.ts +3 -3
- package/dist/net/domain-name.d.ts.map +1 -1
- package/dist/net/domain-name.js +10 -11
- package/dist/net/domain-name.js.map +1 -1
- package/dist/net/http-method.d.ts.map +1 -1
- package/dist/net/http-method.js +9 -9
- package/dist/net/http-method.js.map +1 -1
- package/dist/net/ipv4-address.d.ts +3 -3
- package/dist/net/ipv4-address.d.ts.map +1 -1
- package/dist/net/ipv4-address.js +10 -11
- package/dist/net/ipv4-address.js.map +1 -1
- package/dist/net/ipv6-address.d.ts +3 -3
- package/dist/net/ipv6-address.d.ts.map +1 -1
- package/dist/net/ipv6-address.js +10 -11
- package/dist/net/ipv6-address.js.map +1 -1
- package/dist/net/uri-host-name.d.ts +3 -3
- package/dist/net/uri-host-name.d.ts.map +1 -1
- package/dist/net/uri-host-name.js +15 -16
- package/dist/net/uri-host-name.js.map +1 -1
- package/dist/net/uri.d.ts +1 -2
- package/dist/net/uri.d.ts.map +1 -1
- package/dist/net/uri.js +5 -3
- package/dist/net/uri.js.map +1 -1
- package/dist/net/url.d.ts.map +1 -1
- package/dist/net/url.js +6 -7
- package/dist/net/url.js.map +1 -1
- package/dist/object/object-path.d.ts.map +1 -1
- package/dist/object/object-path.js +23 -28
- package/dist/object/object-path.js.map +1 -1
- package/dist/object/type-path.js +19 -19
- package/dist/object/type-path.js.map +1 -1
- package/dist/patch.js +4 -4
- package/dist/patch.js.map +1 -1
- package/dist/promise.js +2 -2
- package/dist/promise.js.map +1 -1
- package/dist/property.d.ts.map +1 -1
- package/dist/property.js +7 -7
- package/dist/property.js.map +1 -1
- package/dist/proxy.js +2 -2
- package/dist/proxy.js.map +1 -1
- package/dist/range.js +2 -2
- package/dist/range.js.map +1 -1
- package/dist/reference.d.ts +2 -1
- package/dist/reference.d.ts.map +1 -1
- package/dist/reference.js +13 -13
- package/dist/reference.js.map +1 -1
- package/dist/resource-key.js +2 -2
- package/dist/resource-key.js.map +1 -1
- package/dist/result.js +5 -5
- package/dist/result.js.map +1 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +12 -12
- package/dist/retry.js.map +1 -1
- package/dist/rich-text.js +2 -2
- package/dist/rich-text.js.map +1 -1
- package/dist/signature.d.ts.map +1 -1
- package/dist/signature.js +9 -9
- package/dist/signature.js.map +1 -1
- package/dist/sql/sql-expression-parser.js +2 -2
- package/dist/sql/sql-expression-parser.js.map +1 -1
- package/dist/sql.d.ts +5 -1
- package/dist/sql.d.ts.map +1 -1
- package/dist/sql.js.map +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +9 -9
- package/dist/store.js.map +1 -1
- package/dist/string.js +4 -4
- package/dist/string.js.map +1 -1
- package/dist/tag.d.ts.map +1 -1
- package/dist/tag.js +10 -10
- package/dist/tag.js.map +1 -1
- package/dist/temporal/clock.d.ts +13 -13
- package/dist/temporal/clock.d.ts.map +1 -1
- package/dist/temporal/clock.js +10 -10
- package/dist/temporal/clock.js.map +1 -1
- package/dist/temporal/duration.d.ts +15 -9
- package/dist/temporal/duration.d.ts.map +1 -1
- package/dist/temporal/duration.js +30 -31
- package/dist/temporal/duration.js.map +1 -1
- package/dist/temporal/instant.d.ts +18 -15
- package/dist/temporal/instant.d.ts.map +1 -1
- package/dist/temporal/instant.js +42 -43
- package/dist/temporal/instant.js.map +1 -1
- package/dist/temporal/plain-date-time.d.ts +16 -13
- package/dist/temporal/plain-date-time.d.ts.map +1 -1
- package/dist/temporal/plain-date-time.js +36 -38
- package/dist/temporal/plain-date-time.js.map +1 -1
- package/dist/temporal/plain-date.d.ts +16 -13
- package/dist/temporal/plain-date.d.ts.map +1 -1
- package/dist/temporal/plain-date.js +35 -37
- package/dist/temporal/plain-date.js.map +1 -1
- package/dist/temporal/plain-month-day.d.ts +37 -0
- package/dist/temporal/plain-month-day.d.ts.map +1 -0
- package/dist/temporal/plain-month-day.js +84 -0
- package/dist/temporal/plain-month-day.js.map +1 -0
- package/dist/temporal/plain-time.d.ts +19 -17
- package/dist/temporal/plain-time.d.ts.map +1 -1
- package/dist/temporal/plain-time.js +43 -42
- package/dist/temporal/plain-time.js.map +1 -1
- package/dist/temporal/plain-year-month.d.ts +57 -0
- package/dist/temporal/plain-year-month.d.ts.map +1 -0
- package/dist/temporal/plain-year-month.js +109 -0
- package/dist/temporal/plain-year-month.js.map +1 -0
- package/dist/temporal/time-zone-id.d.ts +5 -4
- package/dist/temporal/time-zone-id.d.ts.map +1 -1
- package/dist/temporal/time-zone-id.js +11 -11
- package/dist/temporal/time-zone-id.js.map +1 -1
- package/dist/temporal/time-zone-offset.d.ts +12 -11
- package/dist/temporal/time-zone-offset.d.ts.map +1 -1
- package/dist/temporal/time-zone-offset.js +42 -50
- package/dist/temporal/time-zone-offset.js.map +1 -1
- package/dist/temporal/zoned-date-time.d.ts +16 -13
- package/dist/temporal/zoned-date-time.d.ts.map +1 -1
- package/dist/temporal/zoned-date-time.js +35 -36
- package/dist/temporal/zoned-date-time.js.map +1 -1
- package/dist/uuid/ulid.d.ts +3 -3
- package/dist/uuid/ulid.d.ts.map +1 -1
- package/dist/uuid/ulid.js +9 -10
- package/dist/uuid/ulid.js.map +1 -1
- package/dist/uuid/uuid-v4.d.ts +3 -3
- package/dist/uuid/uuid-v4.d.ts.map +1 -1
- package/dist/uuid/uuid-v4.js +13 -14
- package/dist/uuid/uuid-v4.js.map +1 -1
- package/dist/uuid/uuid-v7.d.ts +1 -2
- package/dist/uuid/uuid-v7.d.ts.map +1 -1
- package/dist/uuid/uuid-v7.js +1 -2
- package/dist/uuid/uuid-v7.js.map +1 -1
- package/dist/zod-util.d.ts +4 -3
- package/dist/zod-util.d.ts.map +1 -1
- package/dist/zod-util.js +21 -11
- package/dist/zod-util.js.map +1 -1
- package/package.json +6 -4
package/dist/map.d.ts
CHANGED
|
@@ -1,20 +1,326 @@
|
|
|
1
1
|
import { Entry } from '@bessemer/cornerstone/entry';
|
|
2
2
|
import { Dictionary } from '@bessemer/cornerstone/types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Map from a dictionary object (plain object with string keys).
|
|
5
|
+
* Converts an object's key-value pairs into a Map structure.
|
|
6
|
+
*
|
|
7
|
+
* **Example**
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
11
|
+
*
|
|
12
|
+
* const user = { name: "Alice", age: "30", role: "admin" }
|
|
13
|
+
* const userMap = Maps.from(user)
|
|
14
|
+
* console.log(userMap.get("name")) // "Alice"
|
|
15
|
+
* console.log(userMap.size) // 3
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @category constructors
|
|
19
|
+
*/
|
|
3
20
|
export declare const from: <ValueType>(record: Dictionary<ValueType>) => Map<string, ValueType>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a Map from an array of key-value pair entries.
|
|
23
|
+
* Each entry is a tuple of [key, value] that will be added to the Map.
|
|
24
|
+
*
|
|
25
|
+
* **Example**
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
29
|
+
*
|
|
30
|
+
* const entries: Array<[string, number]> = [["a", 1], ["b", 2], ["c", 3]]
|
|
31
|
+
* const map = Maps.fromEntries(entries)
|
|
32
|
+
* console.log(map.get("b")) // 2
|
|
33
|
+
* console.log(map.size) // 3
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @category constructors
|
|
37
|
+
*/
|
|
4
38
|
export declare const fromEntries: <KeyType extends string | number | symbol, ValueType>(entries: Array<Entry<KeyType, ValueType>>) => Map<KeyType, ValueType>;
|
|
39
|
+
/**
|
|
40
|
+
* Groups elements of an iterable by a key extracted using a mapper function.
|
|
41
|
+
* Returns a Map where each key maps to an array of all elements that share that key.
|
|
42
|
+
*
|
|
43
|
+
* **Example**
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
47
|
+
*
|
|
48
|
+
* const users = [
|
|
49
|
+
* { name: "Alice", role: "admin" },
|
|
50
|
+
* { name: "Bob", role: "user" },
|
|
51
|
+
* { name: "Charlie", role: "admin" }
|
|
52
|
+
* ]
|
|
53
|
+
*
|
|
54
|
+
* const byRole = Maps.groupBy(users, (user) => user.role)
|
|
55
|
+
* console.log(byRole.get("admin")) // [{ name: "Alice", role: "admin" }, { name: "Charlie", role: "admin" }]
|
|
56
|
+
* console.log(byRole.get("user")) // [{ name: "Bob", role: "user" }]
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @category transformations
|
|
60
|
+
*/
|
|
5
61
|
export declare const groupBy: <CollectionType, KeyType>(iterable: Iterable<CollectionType>, mapper: (it: CollectionType) => KeyType) => Map<KeyType, Array<CollectionType>>;
|
|
62
|
+
/**
|
|
63
|
+
* Fuses two maps together by using values from the first map as keys to lookup
|
|
64
|
+
* values in the second map. The resulting map has the same keys as the target map,
|
|
65
|
+
* but with values resolved through the valuesMap.
|
|
66
|
+
*
|
|
67
|
+
* **Example**
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
71
|
+
*
|
|
72
|
+
* const userRoles = new Map([["user1", "roleA"], ["user2", "roleB"]])
|
|
73
|
+
* const rolePermissions = new Map([["roleA", "read"], ["roleB", "write"]])
|
|
74
|
+
*
|
|
75
|
+
* const userPermissions = Maps.fuse(userRoles, rolePermissions)
|
|
76
|
+
* console.log(userPermissions.get("user1")) // "read"
|
|
77
|
+
* console.log(userPermissions.get("user2")) // "write"
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @category transformations
|
|
81
|
+
*/
|
|
6
82
|
export declare const fuse: <KeyType, FuseType, ValueType>(target: Map<KeyType, FuseType>, valuesMap: Map<FuseType, ValueType>) => Map<KeyType, ValueType>;
|
|
83
|
+
/**
|
|
84
|
+
* Transforms all keys in a map using a mapper function while preserving the values.
|
|
85
|
+
* Returns a new map with transformed keys and the same values.
|
|
86
|
+
*
|
|
87
|
+
* **Example**
|
|
88
|
+
*
|
|
89
|
+
* ```ts
|
|
90
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
91
|
+
*
|
|
92
|
+
* const map = new Map([[1, "one"], [2, "two"], [3, "three"]])
|
|
93
|
+
* const stringKeyMap = Maps.mapKeys(map, (key) => `num_${key}`)
|
|
94
|
+
* console.log(stringKeyMap.get("num_1")) // "one"
|
|
95
|
+
* console.log(stringKeyMap.get("num_2")) // "two"
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @category transformations
|
|
99
|
+
*/
|
|
7
100
|
export declare const mapKeys: <KeyType, ValueType, NewKeyType>(target: Map<KeyType, ValueType>, mapper: (key: KeyType) => NewKeyType) => Map<NewKeyType, ValueType>;
|
|
101
|
+
/**
|
|
102
|
+
* Transforms all values in a map using a mapper function while preserving the keys.
|
|
103
|
+
* Returns a new map with the same keys and transformed values.
|
|
104
|
+
*
|
|
105
|
+
* **Example**
|
|
106
|
+
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
109
|
+
*
|
|
110
|
+
* const prices = new Map([["apple", 1.5], ["banana", 0.8], ["orange", 1.2]])
|
|
111
|
+
* const doubled = Maps.mapValues(prices, (price) => price * 2)
|
|
112
|
+
* console.log(doubled.get("apple")) // 3.0
|
|
113
|
+
* console.log(doubled.get("banana")) // 1.6
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @category transformations
|
|
117
|
+
*/
|
|
8
118
|
export declare const mapValues: <KeyType, ValueType, NewValueType>(target: Map<KeyType, ValueType>, mapper: (value: ValueType) => NewValueType) => Map<KeyType, NewValueType>;
|
|
119
|
+
/**
|
|
120
|
+
* Transforms both keys and values in a map using a mapper function.
|
|
121
|
+
* Returns a new map with transformed entries. Throws an error if the mapper
|
|
122
|
+
* produces duplicate keys.
|
|
123
|
+
*
|
|
124
|
+
* **Example**
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
128
|
+
*
|
|
129
|
+
* const map = new Map([[1, "a"], [2, "b"], [3, "c"]])
|
|
130
|
+
* const transformed = Maps.map(map, ([key, value]) => [key * 10, value.toUpperCase()])
|
|
131
|
+
* console.log(transformed.get(10)) // "A"
|
|
132
|
+
* console.log(transformed.get(20)) // "B"
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @category transformations
|
|
136
|
+
*/
|
|
9
137
|
export declare const map: <KeyType, ValueType, NewKeyType, NewValueType>(target: Map<KeyType, ValueType>, mapper: (entry: Entry<KeyType, ValueType>) => Entry<NewKeyType, NewValueType>) => Map<NewKeyType, NewValueType>;
|
|
138
|
+
/**
|
|
139
|
+
* Creates a map by extracting keys from collection items using a mapper function.
|
|
140
|
+
* Each item becomes a value in the map, keyed by the result of the mapper.
|
|
141
|
+
* Throws an error if the mapper produces duplicate keys.
|
|
142
|
+
*
|
|
143
|
+
* **Example**
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
147
|
+
*
|
|
148
|
+
* const users = [
|
|
149
|
+
* { id: 1, name: "Alice" },
|
|
150
|
+
* { id: 2, name: "Bob" },
|
|
151
|
+
* { id: 3, name: "Charlie" }
|
|
152
|
+
* ]
|
|
153
|
+
*
|
|
154
|
+
* const usersById = Maps.collectKeys(users, (user) => user.id)
|
|
155
|
+
* console.log(usersById.get(1)) // { id: 1, name: "Alice" }
|
|
156
|
+
* console.log(usersById.get(2)) // { id: 2, name: "Bob" }
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
159
|
+
* @category constructors
|
|
160
|
+
*/
|
|
10
161
|
export declare const collectKeys: <CollectionType, KeyType>(iterable: Iterable<CollectionType>, mapper: (it: CollectionType) => KeyType) => Map<KeyType, CollectionType>;
|
|
162
|
+
/**
|
|
163
|
+
* Creates a map by extracting values from collection items using a mapper function.
|
|
164
|
+
* Each item becomes a key in the map, with the mapped value as its value.
|
|
165
|
+
* Throws an error if there are duplicate items in the collection.
|
|
166
|
+
*
|
|
167
|
+
* **Example**
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
171
|
+
*
|
|
172
|
+
* const userIds = [1, 2, 3]
|
|
173
|
+
* const userNames = Maps.collectValues(userIds, (id) => `User${id}`)
|
|
174
|
+
* console.log(userNames.get(1)) // "User1"
|
|
175
|
+
* console.log(userNames.get(2)) // "User2"
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @category constructors
|
|
179
|
+
*/
|
|
11
180
|
export declare const collectValues: <CollectionType, ValueType>(iterable: Iterable<CollectionType>, mapper: (it: CollectionType) => ValueType) => Map<CollectionType, ValueType>;
|
|
181
|
+
/**
|
|
182
|
+
* Collects items from an iterable into a Map by transforming each item into a key-value entry.
|
|
183
|
+
* Optionally accepts a reducer function to handle duplicate keys by combining their values.
|
|
184
|
+
* Without a reducer, throws an error on duplicate keys.
|
|
185
|
+
*
|
|
186
|
+
* **Example**
|
|
187
|
+
*
|
|
188
|
+
* ```ts
|
|
189
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
190
|
+
*
|
|
191
|
+
* const items = ["apple", "banana", "apricot"]
|
|
192
|
+
* const byFirstLetter = Maps.collect(
|
|
193
|
+
* items,
|
|
194
|
+
* (item) => [item[0], item]
|
|
195
|
+
* )
|
|
196
|
+
* // throws error due to duplicate key 'a'
|
|
197
|
+
*
|
|
198
|
+
* const withReducer = Maps.collect(
|
|
199
|
+
* items,
|
|
200
|
+
* (item) => [item[0], [item]],
|
|
201
|
+
* (key, first, second) => [...first, ...second]
|
|
202
|
+
* )
|
|
203
|
+
* console.log(withReducer.get("a")) // ["apple", "apricot"]
|
|
204
|
+
* console.log(withReducer.get("b")) // ["banana"]
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @category constructors
|
|
208
|
+
*/
|
|
12
209
|
export declare function collect<CollectionType, KeyType, ValueType>(iterable: Iterable<CollectionType>, mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>): Map<KeyType, ValueType>;
|
|
13
210
|
export declare function collect<CollectionType, KeyType, ValueType>(iterable: Iterable<CollectionType>, mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>, reducer: (key: KeyType, first: ValueType, second: ValueType) => ValueType): Map<KeyType, ValueType>;
|
|
211
|
+
/**
|
|
212
|
+
* Creates a new map with additional entries appended. Throws an error if any
|
|
213
|
+
* of the new entries have keys that already exist in the map.
|
|
214
|
+
*
|
|
215
|
+
* **Example**
|
|
216
|
+
*
|
|
217
|
+
* ```ts
|
|
218
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
219
|
+
*
|
|
220
|
+
* const original = new Map([["a", 1], ["b", 2]])
|
|
221
|
+
* const extended = Maps.append(original, ["c", 3], ["d", 4])
|
|
222
|
+
* console.log(extended.get("c")) // 3
|
|
223
|
+
* console.log(extended.size) // 4
|
|
224
|
+
* console.log(original.size) // 2 (original unchanged)
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
227
|
+
* @category mutations
|
|
228
|
+
*/
|
|
14
229
|
export declare const append: <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Entry<KeyType, ValueType>>) => Map<KeyType, ValueType>;
|
|
230
|
+
/**
|
|
231
|
+
* Mutates a map by appending entries in place. Throws an error if any
|
|
232
|
+
* of the new entries have keys that already exist in the map.
|
|
233
|
+
*
|
|
234
|
+
* **Example**
|
|
235
|
+
*
|
|
236
|
+
* ```ts
|
|
237
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
238
|
+
*
|
|
239
|
+
* const map = new Map([["a", 1], ["b", 2]])
|
|
240
|
+
* Maps.appendInto(map, ["c", 3], ["d", 4])
|
|
241
|
+
* console.log(map.get("c")) // 3
|
|
242
|
+
* console.log(map.size) // 4
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @category mutations
|
|
246
|
+
*/
|
|
15
247
|
export declare const appendInto: <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Entry<KeyType, ValueType>>) => void;
|
|
248
|
+
/**
|
|
249
|
+
* Creates a new map by concatenating multiple maps together. Throws an error
|
|
250
|
+
* if any duplicate keys are encountered across the maps.
|
|
251
|
+
*
|
|
252
|
+
* **Example**
|
|
253
|
+
*
|
|
254
|
+
* ```ts
|
|
255
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
256
|
+
*
|
|
257
|
+
* const map1 = new Map([["a", 1], ["b", 2]])
|
|
258
|
+
* const map2 = new Map([["c", 3]])
|
|
259
|
+
* const map3 = new Map([["d", 4]])
|
|
260
|
+
*
|
|
261
|
+
* const combined = Maps.concatenate(map1, map2, map3)
|
|
262
|
+
* console.log(combined.size) // 4
|
|
263
|
+
* console.log(combined.get("c")) // 3
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @category mutations
|
|
267
|
+
*/
|
|
16
268
|
export declare const concatenate: <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Map<KeyType, ValueType>>) => Map<KeyType, ValueType>;
|
|
269
|
+
/**
|
|
270
|
+
* Mutates a map by concatenating other maps into it in place. Throws an error
|
|
271
|
+
* if any duplicate keys are encountered.
|
|
272
|
+
*
|
|
273
|
+
* **Example**
|
|
274
|
+
*
|
|
275
|
+
* ```ts
|
|
276
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
277
|
+
*
|
|
278
|
+
* const map1 = new Map([["a", 1], ["b", 2]])
|
|
279
|
+
* const map2 = new Map([["c", 3]])
|
|
280
|
+
*
|
|
281
|
+
* Maps.concatenateInto(map1, map2)
|
|
282
|
+
* console.log(map1.size) // 3
|
|
283
|
+
* console.log(map1.get("c")) // 3
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @category mutations
|
|
287
|
+
*/
|
|
17
288
|
export declare const concatenateInto: <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Map<KeyType, ValueType>>) => void;
|
|
289
|
+
/**
|
|
290
|
+
* Creates a new map containing only entries that satisfy the predicate function.
|
|
291
|
+
* Returns a filtered copy of the original map.
|
|
292
|
+
*
|
|
293
|
+
* **Example**
|
|
294
|
+
*
|
|
295
|
+
* ```ts
|
|
296
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
297
|
+
*
|
|
298
|
+
* const prices = new Map([["apple", 1.5], ["banana", 0.5], ["orange", 2.0]])
|
|
299
|
+
* const expensive = Maps.filter(prices, ([_, price]) => price > 1.0)
|
|
300
|
+
* console.log(expensive.size) // 2
|
|
301
|
+
* console.log(expensive.has("banana")) // false
|
|
302
|
+
* console.log(expensive.get("apple")) // 1.5
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @category filtering
|
|
306
|
+
*/
|
|
18
307
|
export declare const filter: <KeyType, ValueType>(map: Map<KeyType, ValueType>, predicate: (entry: Entry<KeyType, ValueType>) => boolean) => Map<KeyType, ValueType>;
|
|
308
|
+
/**
|
|
309
|
+
* Mutates a map by removing entries that don't satisfy the predicate function.
|
|
310
|
+
* Filters the map in place.
|
|
311
|
+
*
|
|
312
|
+
* **Example**
|
|
313
|
+
*
|
|
314
|
+
* ```ts
|
|
315
|
+
* import { Maps } from "@bessemer/cornerstone"
|
|
316
|
+
*
|
|
317
|
+
* const prices = new Map([["apple", 1.5], ["banana", 0.5], ["orange", 2.0]])
|
|
318
|
+
* Maps.filterFrom(prices, ([_, price]) => price > 1.0)
|
|
319
|
+
* console.log(prices.size) // 2
|
|
320
|
+
* console.log(prices.has("banana")) // false
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @category filtering
|
|
324
|
+
*/
|
|
19
325
|
export declare const filterFrom: <KeyType, ValueType>(map: Map<KeyType, ValueType>, predicate: (entry: Entry<KeyType, ValueType>) => boolean) => void;
|
|
20
326
|
//# sourceMappingURL=map.d.ts.map
|
package/dist/map.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAA;AAInD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD,eAAO,MAAM,IAAI,GAAI,SAAS,EAAE,QAAQ,UAAU,CAAC,SAAS,CAAC,KAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAEpF,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,SAAS,EAC7E,SAAS,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,KACxC,GAAG,CAAC,OAAO,EAAE,SAAS,CAExB,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,cAAc,EAAE,OAAO,EAC7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E,KAAK,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,KAAK,OAAO,KAAG,IAMvI,CAAA"}
|
package/dist/map.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/map.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as Arrays from "@bessemer/cornerstone/array";
|
|
3
|
+
import * as Assertions from "@bessemer/cornerstone/assertion";
|
|
4
4
|
import { Objects } from "@bessemer/cornerstone/index";
|
|
5
5
|
var from = (record) => {
|
|
6
6
|
return fromEntries(Object.entries(record));
|
|
@@ -12,13 +12,13 @@ var groupBy = (iterable, mapper) => {
|
|
|
12
12
|
return collect(
|
|
13
13
|
iterable,
|
|
14
14
|
(it) => [mapper(it), [it]],
|
|
15
|
-
(_, first, second) =>
|
|
15
|
+
(_, first, second) => Arrays.concatenate(first, second)
|
|
16
16
|
);
|
|
17
17
|
};
|
|
18
18
|
var fuse = (target, valuesMap) => {
|
|
19
19
|
return mapValues(target, (value) => {
|
|
20
20
|
const newValue = valuesMap.get(value);
|
|
21
|
-
assertPresent(newValue, () => `Maps.fuse - Encountered missing linkage: ${value}`);
|
|
21
|
+
Assertions.assertPresent(newValue, () => `Maps.fuse - Encountered missing linkage: ${value}`);
|
|
22
22
|
return newValue;
|
|
23
23
|
});
|
|
24
24
|
};
|
|
@@ -75,11 +75,11 @@ var append = (map2, ...values) => {
|
|
|
75
75
|
};
|
|
76
76
|
var appendInto = (map2, ...values) => {
|
|
77
77
|
for (const [key, value] of values) {
|
|
78
|
-
assert(!map2.has(key), () => `Maps.append - Encountered illegal duplicate key: ${key}`);
|
|
78
|
+
Assertions.assert(!map2.has(key), () => `Maps.append - Encountered illegal duplicate key: ${key}`);
|
|
79
79
|
map2.set(key, value);
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
-
var
|
|
82
|
+
var concatenate2 = (map2, ...values) => {
|
|
83
83
|
const result = new Map(map2);
|
|
84
84
|
concatenateInto(result, ...values);
|
|
85
85
|
return result;
|
|
@@ -87,7 +87,7 @@ var concatenate = (map2, ...values) => {
|
|
|
87
87
|
var concatenateInto = (map2, ...values) => {
|
|
88
88
|
for (const otherMap of values) {
|
|
89
89
|
for (const [key, value] of otherMap) {
|
|
90
|
-
assert(!map2.has(key), () => `Maps.concatenate - Encountered illegal duplicate key: ${key}`);
|
|
90
|
+
Assertions.assert(!map2.has(key), () => `Maps.concatenate - Encountered illegal duplicate key: ${key}`);
|
|
91
91
|
map2.set(key, value);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -110,7 +110,7 @@ export {
|
|
|
110
110
|
collect,
|
|
111
111
|
collectKeys,
|
|
112
112
|
collectValues,
|
|
113
|
-
concatenate,
|
|
113
|
+
concatenate2 as concatenate,
|
|
114
114
|
concatenateInto,
|
|
115
115
|
filter,
|
|
116
116
|
filterFrom,
|
package/dist/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/map.ts"],"sourcesContent":["import { Entry } from '@bessemer/cornerstone/entry'\nimport { concatenate as arrayConcatenate } from '@bessemer/cornerstone/array'\nimport { assert, assertPresent } from '@bessemer/cornerstone/assertion'\nimport { Objects } from '@bessemer/cornerstone/index'\nimport { Dictionary } from '@bessemer/cornerstone/types'\n\nexport const from = <ValueType>(record: Dictionary<ValueType>): Map<string, ValueType> => {\n return fromEntries(Object.entries(record))\n}\n\nexport const fromEntries = <KeyType extends string | number | symbol, ValueType>(\n entries: Array<Entry<KeyType, ValueType>>\n): Map<KeyType, ValueType> => {\n return collect(entries, (it) => it)\n}\n\nexport const groupBy = <CollectionType, KeyType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => KeyType\n): Map<KeyType, Array<CollectionType>> => {\n return collect(\n iterable,\n (it) => [mapper(it), [it]],\n (_, first, second) => arrayConcatenate(first, second)\n )\n}\n\nexport const fuse = <KeyType, FuseType, ValueType>(target: Map<KeyType, FuseType>, valuesMap: Map<FuseType, ValueType>): Map<KeyType, ValueType> => {\n return mapValues(target, (value) => {\n const newValue = valuesMap.get(value)\n assertPresent(newValue, () => `Maps.fuse - Encountered missing linkage: ${value}`)\n return newValue\n })\n}\n\nexport const mapKeys = <KeyType, ValueType, NewKeyType>(\n target: Map<KeyType, ValueType>,\n mapper: (key: KeyType) => NewKeyType\n): Map<NewKeyType, ValueType> => {\n return map(target, ([key, value]) => [mapper(key), value])\n}\n\nexport const mapValues = <KeyType, ValueType, NewValueType>(\n target: Map<KeyType, ValueType>,\n mapper: (value: ValueType) => NewValueType\n): Map<KeyType, NewValueType> => {\n return map(target, ([key, value]) => [key, mapper(value)])\n}\n\nexport const map = <KeyType, ValueType, NewKeyType, NewValueType>(\n target: Map<KeyType, ValueType>,\n mapper: (entry: Entry<KeyType, ValueType>) => Entry<NewKeyType, NewValueType>\n): Map<NewKeyType, NewValueType> => {\n return collect(target.entries(), mapper, (key) => {\n throw new Error(`Maps.transform - Encountered illegal duplicate collection value: ${key}`)\n })\n}\n\nexport const collectKeys = <CollectionType, KeyType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => KeyType\n): Map<KeyType, CollectionType> => {\n return collect(\n iterable,\n (it) => [mapper(it), it],\n (key) => {\n throw new Error(`Maps.collectKeys - Encountered illegal duplicate collection value: ${key}`)\n }\n )\n}\n\nexport const collectValues = <CollectionType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => ValueType\n): Map<CollectionType, ValueType> => {\n return collect(\n iterable,\n (it) => [it, mapper(it)],\n (key) => {\n throw new Error(`Maps.mapValues - Encountered illegal duplicate collection value: ${key}`)\n }\n )\n}\n\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>\n): Map<KeyType, ValueType>\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>,\n reducer: (key: KeyType, first: ValueType, second: ValueType) => ValueType\n): Map<KeyType, ValueType>\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>,\n reducer?: (key: KeyType, first: ValueType, second: ValueType) => ValueType\n): Map<KeyType, ValueType> {\n const result = new Map<KeyType, ValueType>()\n\n for (const item of iterable) {\n const [key, value] = mapEntry(item)\n\n if (result.has(key)) {\n if (Objects.isNil(reducer)) {\n throw new Error(`Maps.collect - Encountered illegal duplicate collection key: ${key}`)\n }\n\n const existingValue = result.get(key)!\n const reducedValue = reducer(key, existingValue, value)\n result.set(key, reducedValue)\n } else {\n result.set(key, value)\n }\n }\n\n return result\n}\n\nexport const append = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Entry<KeyType, ValueType>>): Map<KeyType, ValueType> => {\n const result = new Map(map.entries())\n appendInto(result, ...values)\n return result\n}\n\nexport const appendInto = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Entry<KeyType, ValueType>>): void => {\n for (const [key, value] of values) {\n assert(!map.has(key), () => `Maps.append - Encountered illegal duplicate key: ${key}`)\n map.set(key, value)\n }\n}\n\nexport const concatenate = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Map<KeyType, ValueType>>): Map<KeyType, ValueType> => {\n const result = new Map(map)\n concatenateInto(result, ...values)\n return result\n}\n\nexport const concatenateInto = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Map<KeyType, ValueType>>): void => {\n for (const otherMap of values) {\n for (const [key, value] of otherMap) {\n assert(!map.has(key), () => `Maps.concatenate - Encountered illegal duplicate key: ${key}`)\n map.set(key, value)\n }\n }\n}\n\nexport const filter = <KeyType, ValueType>(\n map: Map<KeyType, ValueType>,\n predicate: (entry: Entry<KeyType, ValueType>) => boolean\n): Map<KeyType, ValueType> => {\n const result = new Map(map)\n filterFrom(result, predicate)\n return result\n}\n\nexport const filterFrom = <KeyType, ValueType>(map: Map<KeyType, ValueType>, predicate: (entry: Entry<KeyType, ValueType>) => boolean): void => {\n for (const entry of map) {\n if (!predicate(entry)) {\n map.delete(entry[0])\n }\n }\n}\n"],"mappings":";AACA,SAAS,eAAe,wBAAwB;AAChD,SAAS,QAAQ,qBAAqB;AACtC,SAAS,eAAe;AAGjB,IAAM,OAAO,CAAY,WAA0D;AACxF,SAAO,YAAY,OAAO,QAAQ,MAAM,CAAC;AAC3C;AAEO,IAAM,cAAc,CACzB,YAC4B;AAC5B,SAAO,QAAQ,SAAS,CAAC,OAAO,EAAE;AACpC;AAEO,IAAM,UAAU,CACrB,UACA,WACwC;AACxC,SAAO;AAAA,IACL;AAAA,IACA,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;AAAA,IACzB,CAAC,GAAG,OAAO,WAAW,iBAAiB,OAAO,MAAM;AAAA,EACtD;AACF;AAEO,IAAM,OAAO,CAA+B,QAAgC,cAAiE;AAClJ,SAAO,UAAU,QAAQ,CAAC,UAAU;AAClC,UAAM,WAAW,UAAU,IAAI,KAAK;AACpC,kBAAc,UAAU,MAAM,4CAA4C,KAAK,EAAE;AACjF,WAAO;AAAA,EACT,CAAC;AACH;AAEO,IAAM,UAAU,CACrB,QACA,WAC+B;AAC/B,SAAO,IAAI,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,OAAO,GAAG,GAAG,KAAK,CAAC;AAC3D;AAEO,IAAM,YAAY,CACvB,QACA,WAC+B;AAC/B,SAAO,IAAI,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,OAAO,KAAK,CAAC,CAAC;AAC3D;AAEO,IAAM,MAAM,CACjB,QACA,WACkC;AAClC,SAAO,QAAQ,OAAO,QAAQ,GAAG,QAAQ,CAAC,QAAQ;AAChD,UAAM,IAAI,MAAM,oEAAoE,GAAG,EAAE;AAAA,EAC3F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AK;AAAA,EACpB;AACF;AAEO,IAAM,cAAc,CAAqBA,SAAiC,WAAoE;AACnJ,QAAM,SAAS,IAAI,IAAIA,IAAG;AAC1B,kBAAgB,QAAQ,GAAG,MAAM;AACjC,SAAO;AACT;AAEO,IAAM,kBAAkB,CAAqBA,SAAiC,WAAiD;AACpI,aAAW,YAAY,QAAQ;AAC7B,eAAW,CAAC,KAAK,KAAK,KAAK,UAAU;AACnC,aAAO,CAACA,KAAI,IAAI,GAAG,GAAG,MAAM,yDAAyD,GAAG,EAAE;AAC1F,MAAAA,KAAI,IAAI,KAAK,KAAK;AAAA,IACpB;AAAA,EACF;AACF;AAEO,IAAM,SAAS,CACpBA,MACA,cAC4B;AAC5B,QAAM,SAAS,IAAI,IAAIA,IAAG;AAC1B,aAAW,QAAQ,SAAS;AAC5B,SAAO;AACT;AAEO,IAAM,aAAa,CAAqBA,MAA8B,cAAmE;AAC9I,aAAW,SAASA,MAAK;AACvB,QAAI,CAAC,UAAU,KAAK,GAAG;AACrB,MAAAA,KAAI,OAAO,MAAM,CAAC,CAAC;AAAA,IACrB;AAAA,EACF;AACF;","names":["map"]}
|
|
1
|
+
{"version":3,"sources":["../src/map.ts"],"sourcesContent":["import { Entry } from '@bessemer/cornerstone/entry'\nimport * as Arrays from '@bessemer/cornerstone/array'\nimport * as Assertions from '@bessemer/cornerstone/assertion'\nimport { Objects } from '@bessemer/cornerstone/index'\nimport { Dictionary } from '@bessemer/cornerstone/types'\n\n/**\n * Creates a Map from a dictionary object (plain object with string keys).\n * Converts an object's key-value pairs into a Map structure.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const user = { name: \"Alice\", age: \"30\", role: \"admin\" }\n * const userMap = Maps.from(user)\n * console.log(userMap.get(\"name\")) // \"Alice\"\n * console.log(userMap.size) // 3\n * ```\n *\n * @category constructors\n */\nexport const from = <ValueType>(record: Dictionary<ValueType>): Map<string, ValueType> => {\n return fromEntries(Object.entries(record))\n}\n\n/**\n * Creates a Map from an array of key-value pair entries.\n * Each entry is a tuple of [key, value] that will be added to the Map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const entries: Array<[string, number]> = [[\"a\", 1], [\"b\", 2], [\"c\", 3]]\n * const map = Maps.fromEntries(entries)\n * console.log(map.get(\"b\")) // 2\n * console.log(map.size) // 3\n * ```\n *\n * @category constructors\n */\nexport const fromEntries = <KeyType extends string | number | symbol, ValueType>(\n entries: Array<Entry<KeyType, ValueType>>\n): Map<KeyType, ValueType> => {\n return collect(entries, (it) => it)\n}\n\n/**\n * Groups elements of an iterable by a key extracted using a mapper function.\n * Returns a Map where each key maps to an array of all elements that share that key.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const users = [\n * { name: \"Alice\", role: \"admin\" },\n * { name: \"Bob\", role: \"user\" },\n * { name: \"Charlie\", role: \"admin\" }\n * ]\n *\n * const byRole = Maps.groupBy(users, (user) => user.role)\n * console.log(byRole.get(\"admin\")) // [{ name: \"Alice\", role: \"admin\" }, { name: \"Charlie\", role: \"admin\" }]\n * console.log(byRole.get(\"user\")) // [{ name: \"Bob\", role: \"user\" }]\n * ```\n *\n * @category transformations\n */\nexport const groupBy = <CollectionType, KeyType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => KeyType\n): Map<KeyType, Array<CollectionType>> => {\n return collect(\n iterable,\n (it) => [mapper(it), [it]],\n (_, first, second) => Arrays.concatenate(first, second)\n )\n}\n\n/**\n * Fuses two maps together by using values from the first map as keys to lookup\n * values in the second map. The resulting map has the same keys as the target map,\n * but with values resolved through the valuesMap.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const userRoles = new Map([[\"user1\", \"roleA\"], [\"user2\", \"roleB\"]])\n * const rolePermissions = new Map([[\"roleA\", \"read\"], [\"roleB\", \"write\"]])\n *\n * const userPermissions = Maps.fuse(userRoles, rolePermissions)\n * console.log(userPermissions.get(\"user1\")) // \"read\"\n * console.log(userPermissions.get(\"user2\")) // \"write\"\n * ```\n *\n * @category transformations\n */\nexport const fuse = <KeyType, FuseType, ValueType>(target: Map<KeyType, FuseType>, valuesMap: Map<FuseType, ValueType>): Map<KeyType, ValueType> => {\n return mapValues(target, (value) => {\n const newValue = valuesMap.get(value)\n Assertions.assertPresent(newValue, () => `Maps.fuse - Encountered missing linkage: ${value}`)\n return newValue\n })\n}\n\n/**\n * Transforms all keys in a map using a mapper function while preserving the values.\n * Returns a new map with transformed keys and the same values.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map = new Map([[1, \"one\"], [2, \"two\"], [3, \"three\"]])\n * const stringKeyMap = Maps.mapKeys(map, (key) => `num_${key}`)\n * console.log(stringKeyMap.get(\"num_1\")) // \"one\"\n * console.log(stringKeyMap.get(\"num_2\")) // \"two\"\n * ```\n *\n * @category transformations\n */\nexport const mapKeys = <KeyType, ValueType, NewKeyType>(\n target: Map<KeyType, ValueType>,\n mapper: (key: KeyType) => NewKeyType\n): Map<NewKeyType, ValueType> => {\n return map(target, ([key, value]) => [mapper(key), value])\n}\n\n/**\n * Transforms all values in a map using a mapper function while preserving the keys.\n * Returns a new map with the same keys and transformed values.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const prices = new Map([[\"apple\", 1.5], [\"banana\", 0.8], [\"orange\", 1.2]])\n * const doubled = Maps.mapValues(prices, (price) => price * 2)\n * console.log(doubled.get(\"apple\")) // 3.0\n * console.log(doubled.get(\"banana\")) // 1.6\n * ```\n *\n * @category transformations\n */\nexport const mapValues = <KeyType, ValueType, NewValueType>(\n target: Map<KeyType, ValueType>,\n mapper: (value: ValueType) => NewValueType\n): Map<KeyType, NewValueType> => {\n return map(target, ([key, value]) => [key, mapper(value)])\n}\n\n/**\n * Transforms both keys and values in a map using a mapper function.\n * Returns a new map with transformed entries. Throws an error if the mapper\n * produces duplicate keys.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map = new Map([[1, \"a\"], [2, \"b\"], [3, \"c\"]])\n * const transformed = Maps.map(map, ([key, value]) => [key * 10, value.toUpperCase()])\n * console.log(transformed.get(10)) // \"A\"\n * console.log(transformed.get(20)) // \"B\"\n * ```\n *\n * @category transformations\n */\nexport const map = <KeyType, ValueType, NewKeyType, NewValueType>(\n target: Map<KeyType, ValueType>,\n mapper: (entry: Entry<KeyType, ValueType>) => Entry<NewKeyType, NewValueType>\n): Map<NewKeyType, NewValueType> => {\n return collect(target.entries(), mapper, (key) => {\n throw new Error(`Maps.transform - Encountered illegal duplicate collection value: ${key}`)\n })\n}\n\n/**\n * Creates a map by extracting keys from collection items using a mapper function.\n * Each item becomes a value in the map, keyed by the result of the mapper.\n * Throws an error if the mapper produces duplicate keys.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const users = [\n * { id: 1, name: \"Alice\" },\n * { id: 2, name: \"Bob\" },\n * { id: 3, name: \"Charlie\" }\n * ]\n *\n * const usersById = Maps.collectKeys(users, (user) => user.id)\n * console.log(usersById.get(1)) // { id: 1, name: \"Alice\" }\n * console.log(usersById.get(2)) // { id: 2, name: \"Bob\" }\n * ```\n *\n * @category constructors\n */\nexport const collectKeys = <CollectionType, KeyType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => KeyType\n): Map<KeyType, CollectionType> => {\n return collect(\n iterable,\n (it) => [mapper(it), it],\n (key) => {\n throw new Error(`Maps.collectKeys - Encountered illegal duplicate collection value: ${key}`)\n }\n )\n}\n\n/**\n * Creates a map by extracting values from collection items using a mapper function.\n * Each item becomes a key in the map, with the mapped value as its value.\n * Throws an error if there are duplicate items in the collection.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const userIds = [1, 2, 3]\n * const userNames = Maps.collectValues(userIds, (id) => `User${id}`)\n * console.log(userNames.get(1)) // \"User1\"\n * console.log(userNames.get(2)) // \"User2\"\n * ```\n *\n * @category constructors\n */\nexport const collectValues = <CollectionType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => ValueType\n): Map<CollectionType, ValueType> => {\n return collect(\n iterable,\n (it) => [it, mapper(it)],\n (key) => {\n throw new Error(`Maps.mapValues - Encountered illegal duplicate collection value: ${key}`)\n }\n )\n}\n\n/**\n * Collects items from an iterable into a Map by transforming each item into a key-value entry.\n * Optionally accepts a reducer function to handle duplicate keys by combining their values.\n * Without a reducer, throws an error on duplicate keys.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const items = [\"apple\", \"banana\", \"apricot\"]\n * const byFirstLetter = Maps.collect(\n * items,\n * (item) => [item[0], item]\n * )\n * // throws error due to duplicate key 'a'\n *\n * const withReducer = Maps.collect(\n * items,\n * (item) => [item[0], [item]],\n * (key, first, second) => [...first, ...second]\n * )\n * console.log(withReducer.get(\"a\")) // [\"apple\", \"apricot\"]\n * console.log(withReducer.get(\"b\")) // [\"banana\"]\n * ```\n *\n * @category constructors\n */\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>\n): Map<KeyType, ValueType>\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>,\n reducer: (key: KeyType, first: ValueType, second: ValueType) => ValueType\n): Map<KeyType, ValueType>\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>,\n reducer?: (key: KeyType, first: ValueType, second: ValueType) => ValueType\n): Map<KeyType, ValueType> {\n const result = new Map<KeyType, ValueType>()\n\n for (const item of iterable) {\n const [key, value] = mapEntry(item)\n\n if (result.has(key)) {\n if (Objects.isNil(reducer)) {\n throw new Error(`Maps.collect - Encountered illegal duplicate collection key: ${key}`)\n }\n\n const existingValue = result.get(key)!\n const reducedValue = reducer(key, existingValue, value)\n result.set(key, reducedValue)\n } else {\n result.set(key, value)\n }\n }\n\n return result\n}\n\n/**\n * Creates a new map with additional entries appended. Throws an error if any\n * of the new entries have keys that already exist in the map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const original = new Map([[\"a\", 1], [\"b\", 2]])\n * const extended = Maps.append(original, [\"c\", 3], [\"d\", 4])\n * console.log(extended.get(\"c\")) // 3\n * console.log(extended.size) // 4\n * console.log(original.size) // 2 (original unchanged)\n * ```\n *\n * @category mutations\n */\nexport const append = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Entry<KeyType, ValueType>>): Map<KeyType, ValueType> => {\n const result = new Map(map.entries())\n appendInto(result, ...values)\n return result\n}\n\n/**\n * Mutates a map by appending entries in place. Throws an error if any\n * of the new entries have keys that already exist in the map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map = new Map([[\"a\", 1], [\"b\", 2]])\n * Maps.appendInto(map, [\"c\", 3], [\"d\", 4])\n * console.log(map.get(\"c\")) // 3\n * console.log(map.size) // 4\n * ```\n *\n * @category mutations\n */\nexport const appendInto = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Entry<KeyType, ValueType>>): void => {\n for (const [key, value] of values) {\n Assertions.assert(!map.has(key), () => `Maps.append - Encountered illegal duplicate key: ${key}`)\n map.set(key, value)\n }\n}\n\n/**\n * Creates a new map by concatenating multiple maps together. Throws an error\n * if any duplicate keys are encountered across the maps.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map1 = new Map([[\"a\", 1], [\"b\", 2]])\n * const map2 = new Map([[\"c\", 3]])\n * const map3 = new Map([[\"d\", 4]])\n *\n * const combined = Maps.concatenate(map1, map2, map3)\n * console.log(combined.size) // 4\n * console.log(combined.get(\"c\")) // 3\n * ```\n *\n * @category mutations\n */\nexport const concatenate = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Map<KeyType, ValueType>>): Map<KeyType, ValueType> => {\n const result = new Map(map)\n concatenateInto(result, ...values)\n return result\n}\n\n/**\n * Mutates a map by concatenating other maps into it in place. Throws an error\n * if any duplicate keys are encountered.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map1 = new Map([[\"a\", 1], [\"b\", 2]])\n * const map2 = new Map([[\"c\", 3]])\n *\n * Maps.concatenateInto(map1, map2)\n * console.log(map1.size) // 3\n * console.log(map1.get(\"c\")) // 3\n * ```\n *\n * @category mutations\n */\nexport const concatenateInto = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Map<KeyType, ValueType>>): void => {\n for (const otherMap of values) {\n for (const [key, value] of otherMap) {\n Assertions.assert(!map.has(key), () => `Maps.concatenate - Encountered illegal duplicate key: ${key}`)\n map.set(key, value)\n }\n }\n}\n\n/**\n * Creates a new map containing only entries that satisfy the predicate function.\n * Returns a filtered copy of the original map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const prices = new Map([[\"apple\", 1.5], [\"banana\", 0.5], [\"orange\", 2.0]])\n * const expensive = Maps.filter(prices, ([_, price]) => price > 1.0)\n * console.log(expensive.size) // 2\n * console.log(expensive.has(\"banana\")) // false\n * console.log(expensive.get(\"apple\")) // 1.5\n * ```\n *\n * @category filtering\n */\nexport const filter = <KeyType, ValueType>(\n map: Map<KeyType, ValueType>,\n predicate: (entry: Entry<KeyType, ValueType>) => boolean\n): Map<KeyType, ValueType> => {\n const result = new Map(map)\n filterFrom(result, predicate)\n return result\n}\n\n/**\n * Mutates a map by removing entries that don't satisfy the predicate function.\n * Filters the map in place.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const prices = new Map([[\"apple\", 1.5], [\"banana\", 0.5], [\"orange\", 2.0]])\n * Maps.filterFrom(prices, ([_, price]) => price > 1.0)\n * console.log(prices.size) // 2\n * console.log(prices.has(\"banana\")) // false\n * ```\n *\n * @category filtering\n */\nexport const filterFrom = <KeyType, ValueType>(map: Map<KeyType, ValueType>, predicate: (entry: Entry<KeyType, ValueType>) => boolean): void => {\n for (const entry of map) {\n if (!predicate(entry)) {\n map.delete(entry[0])\n }\n }\n}\n"],"mappings":";AACA,YAAY,YAAY;AACxB,YAAY,gBAAgB;AAC5B,SAAS,eAAe;AAoBjB,IAAM,OAAO,CAAY,WAA0D;AACxF,SAAO,YAAY,OAAO,QAAQ,MAAM,CAAC;AAC3C;AAmBO,IAAM,cAAc,CACzB,YAC4B;AAC5B,SAAO,QAAQ,SAAS,CAAC,OAAO,EAAE;AACpC;AAwBO,IAAM,UAAU,CACrB,UACA,WACwC;AACxC,SAAO;AAAA,IACL;AAAA,IACA,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;AAAA,IACzB,CAAC,GAAG,OAAO,WAAkB,mBAAY,OAAO,MAAM;AAAA,EACxD;AACF;AAsBO,IAAM,OAAO,CAA+B,QAAgC,cAAiE;AAClJ,SAAO,UAAU,QAAQ,CAAC,UAAU;AAClC,UAAM,WAAW,UAAU,IAAI,KAAK;AACpC,IAAW,yBAAc,UAAU,MAAM,4CAA4C,KAAK,EAAE;AAC5F,WAAO;AAAA,EACT,CAAC;AACH;AAmBO,IAAM,UAAU,CACrB,QACA,WAC+B;AAC/B,SAAO,IAAI,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,OAAO,GAAG,GAAG,KAAK,CAAC;AAC3D;AAmBO,IAAM,YAAY,CACvB,QACA,WAC+B;AAC/B,SAAO,IAAI,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,OAAO,KAAK,CAAC,CAAC;AAC3D;AAoBO,IAAM,M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jI,aAAW,CAAC,KAAK,KAAK,KAAK,QAAQ;AACjC,IAAW,kBAAO,CAACA,KAAI,IAAI,GAAG,GAAG,MAAM,oDAAoD,GAAG,EAAE;AAChG,IAAAA,KAAI,IAAI,KAAK,KAAK;AAAA,EACpB;AACF;AAsBO,IAAMC,eAAc,CAAqBD,SAAiC,WAAoE;AACnJ,QAAM,SAAS,IAAI,IAAIA,IAAG;AAC1B,kBAAgB,QAAQ,GAAG,MAAM;AACjC,SAAO;AACT;AAqBO,IAAM,kBAAkB,CAAqBA,SAAiC,WAAiD;AACpI,aAAW,YAAY,QAAQ;AAC7B,eAAW,CAAC,KAAK,KAAK,KAAK,UAAU;AACnC,MAAW,kBAAO,CAACA,KAAI,IAAI,GAAG,GAAG,MAAM,yDAAyD,GAAG,EAAE;AACrG,MAAAA,KAAI,IAAI,KAAK,KAAK;AAAA,IACpB;AAAA,EACF;AACF;AAoBO,IAAM,SAAS,CACpBA,MACA,cAC4B;AAC5B,QAAM,SAAS,IAAI,IAAIA,IAAG;AAC1B,aAAW,QAAQ,SAAS;AAC5B,SAAO;AACT;AAmBO,IAAM,aAAa,CAAqBA,MAA8B,cAAmE;AAC9I,aAAW,SAASA,MAAK;AACvB,QAAI,CAAC,UAAU,KAAK,GAAG;AACrB,MAAAA,KAAI,OAAO,MAAM,CAAC,CAAC;AAAA,IACrB;AAAA,EACF;AACF;","names":["map","concatenate"]}
|
package/dist/mime-type.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { NominalType } from '@bessemer/cornerstone/types';
|
|
2
|
-
import Zod from 'zod';
|
|
3
2
|
import { Result } from '@bessemer/cornerstone/result';
|
|
3
|
+
import * as ResourceKeys from '@bessemer/cornerstone/resource-key';
|
|
4
4
|
import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
|
|
5
|
-
export declare const Namespace:
|
|
5
|
+
export declare const Namespace: ResourceKeys.ResourceNamespace<"mime-type">;
|
|
6
6
|
export type MimeLiteral = NominalType<string, typeof Namespace>;
|
|
7
7
|
export declare const parseString: (initialValue: string) => Result<MimeLiteral, ErrorEvent>;
|
|
8
8
|
export declare const from: (value: string) => MimeLiteral;
|
|
9
|
-
export declare const Schema:
|
|
9
|
+
export declare const Schema: import("zod").ZodPipe<import("zod").ZodType<MimeLiteral, MimeLiteral, import("zod/v4/core").$ZodTypeInternals<MimeLiteral, MimeLiteral>>, import("zod").ZodTransform<MimeLiteral, MimeLiteral>>;
|
|
10
10
|
export declare const Jpeg: MimeLiteral;
|
|
11
11
|
export declare const Png: MimeLiteral;
|
|
12
12
|
export declare const Gif: MimeLiteral;
|
package/dist/mime-type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mime-type.d.ts","sourceRoot":"","sources":["../src/mime-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"mime-type.d.ts","sourceRoot":"","sources":["../src/mime-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAAO,KAAK,YAAY,MAAM,oCAAoC,CAAA;AAElE,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAA;AAGpE,eAAO,MAAM,SAAS,6CAA4C,CAAA;AAClE,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAE/D,eAAO,MAAM,WAAW,GAAI,cAAc,MAAM,KAAG,MAAM,CAAC,WAAW,EAAE,UAAU,CAQhF,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,WAEpC,CAAA;AAED,eAAO,MAAM,MAAM,iMAIjB,CAAA;AAGF,eAAO,MAAM,IAAI,EAAmB,WAAW,CAAA;AAC/C,eAAO,MAAM,GAAG,EAAkB,WAAW,CA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AG,EAA0B,WAAW,CAAA;AACrD,eAAO,MAAM,MAAM,EAA6B,WAAW,CAAA;AAC3D,eAAO,MAAM,gBAAgB,eAA2B,CAAA;AAGxD,eAAO,MAAM,QAAQ,EAA4B,WAAW,CAAA;AAC5D,eAAO,MAAM,OAAO,EAA0C,WAAW,CAAA;AACzE,eAAO,MAAM,UAAU,EAA+B,WAAW,CAAA;AACjE,eAAO,MAAM,MAAM,EAAiC,WAAW,CAAA"}
|
package/dist/mime-type.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
// src/mime-type.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
var Namespace = createNamespace("mime-type");
|
|
2
|
+
import * as Results from "@bessemer/cornerstone/result";
|
|
3
|
+
import * as ResourceKeys from "@bessemer/cornerstone/resource-key";
|
|
4
|
+
import * as ErrorEvents from "@bessemer/cornerstone/error/error-event";
|
|
5
|
+
import * as ZodUtil from "@bessemer/cornerstone/zod-util";
|
|
6
|
+
var Namespace = ResourceKeys.createNamespace("mime-type");
|
|
8
7
|
var parseString = (initialValue) => {
|
|
9
8
|
const value = initialValue.trim().toLowerCase();
|
|
10
9
|
if (!/^[\w-]+\/[\w.+-]+$/.test(value)) {
|
|
11
|
-
return failure(invalidValue(value, { namespace: Namespace, message: `Invalid MIME type format.` }));
|
|
10
|
+
return Results.failure(ErrorEvents.invalidValue(value, { namespace: Namespace, message: `Invalid MIME type format.` }));
|
|
12
11
|
}
|
|
13
|
-
return success(value);
|
|
12
|
+
return Results.success(value);
|
|
14
13
|
};
|
|
15
14
|
var from = (value) => {
|
|
16
|
-
return unpackResult(parseString(value));
|
|
15
|
+
return ErrorEvents.unpackResult(parseString(value));
|
|
17
16
|
};
|
|
18
|
-
var Schema = structuredTransform(
|
|
17
|
+
var Schema = ZodUtil.structuredTransform(ZodUtil.string(), parseString).meta({
|
|
19
18
|
type: "string",
|
|
20
19
|
format: Namespace,
|
|
21
20
|
pattern: "^[\\w-]+\\/[\\w.+-]+$"
|
package/dist/mime-type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mime-type.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport
|
|
1
|
+
{"version":3,"sources":["../src/mime-type.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { Result } from '@bessemer/cornerstone/result'\nimport * as ResourceKeys from '@bessemer/cornerstone/resource-key'\nimport * as ErrorEvents from '@bessemer/cornerstone/error/error-event'\nimport { ErrorEvent } from '@bessemer/cornerstone/error/error-event'\nimport * as ZodUtil from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = ResourceKeys.createNamespace('mime-type')\nexport type MimeLiteral = NominalType<string, typeof Namespace>\n\nexport const parseString = (initialValue: string): Result<MimeLiteral, ErrorEvent> => {\n const value = initialValue.trim().toLowerCase()\n\n if (!/^[\\w-]+\\/[\\w.+-]+$/.test(value)) {\n return Results.failure(ErrorEvents.invalidValue(value, { namespace: Namespace, message: `Invalid MIME type format.` }))\n }\n\n return Results.success(value as MimeLiteral)\n}\n\nexport const from = (value: string): MimeLiteral => {\n return ErrorEvents.unpackResult(parseString(value))\n}\n\nexport const Schema = ZodUtil.structuredTransform<MimeLiteral>(ZodUtil.string(), parseString).meta({\n type: 'string',\n format: Namespace,\n pattern: '^[\\\\w-]+\\\\/[\\\\w.+-]+$',\n})\n\n// Images\nexport const Jpeg = 'image/jpeg' as MimeLiteral\nexport const Png = 'image/png' as MimeLiteral\nexport const Gif = 'image/gif' as MimeLiteral\nexport const Webp = 'image/webp' as MimeLiteral\nexport const Svg = 'image/svg+xml' as MimeLiteral\nexport const Ico = 'image/x-icon' as MimeLiteral\nexport const Avif = 'image/avif' as MimeLiteral\nexport const ImageTypes = [Jpeg, Png, Gif, Webp, Svg, Ico, Avif]\n\n// Video\nexport const Mp4 = 'video/mp4' as MimeLiteral\nexport const Webm = 'video/webm' as MimeLiteral\nexport const OggVideo = 'video/ogg' as MimeLiteral\nexport const VideoTypes = [Mp4, Webm, OggVideo]\n\n// Audio\nexport const Mp3 = 'audio/mpeg' as MimeLiteral\nexport const OggAudio = 'audio/ogg' as MimeLiteral\nexport const Wav = 'audio/wav' as MimeLiteral\nexport const AudioTypes = [Mp3, OggAudio, Wav]\n\n// Documents\nexport const Pdf = 'application/pdf' as MimeLiteral\nexport const Json = 'application/json' as MimeLiteral\nexport const Csv = 'text/csv' as MimeLiteral\nexport const Text = 'text/plain' as MimeLiteral\nexport const Html = 'text/html' as MimeLiteral\nexport const Xml = 'application/xml' as MimeLiteral\nexport const DocumentTypes = [Pdf, Json, Csv, Text, Html, Xml]\n\n// Fonts\nexport const Woff = 'font/woff' as MimeLiteral\nexport const Woff2 = 'font/woff2' as MimeLiteral\nexport const Ttf = 'font/ttf' as MimeLiteral\nexport const Otf = 'font/otf' as MimeLiteral\nexport const FontTypes = [Woff, Woff2, Ttf, Otf]\n\n// Compression\nexport const Zip = 'application/zip' as MimeLiteral\nexport const Gzip = 'application/gzip' as MimeLiteral\nexport const Tar = 'application/x-tar' as MimeLiteral\nexport const Brotli = 'application/x-brotli' as MimeLiteral\nexport const CompressionTypes = [Zip, Gzip, Tar, Brotli]\n\n// Misc\nexport const FormData = 'multipart/form-data' as MimeLiteral\nexport const FormUrl = 'application/x-www-form-urlencoded' as MimeLiteral\nexport const Javascript = 'application/javascript' as MimeLiteral\nexport const Binary = 'application/octet-stream' as MimeLiteral\n"],"mappings":";AACA,YAAY,aAAa;AAEzB,YAAY,kBAAkB;AAC9B,YAAY,iBAAiB;AAE7B,YAAY,aAAa;AAElB,IAAM,YAAyB,6BAAgB,WAAW;AAG1D,IAAM,cAAc,CAAC,iBAA0D;AACpF,QAAM,QAAQ,aAAa,KAAK,EAAE,YAAY;AAE9C,MAAI,CAAC,qBAAqB,KAAK,KAAK,GAAG;AACrC,WAAe,gBAAoB,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
|
// src/misc.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as Objects from "@bessemer/cornerstone/object";
|
|
3
|
+
import * as Assertions from "@bessemer/cornerstone/assertion";
|
|
4
4
|
var doUntilConsistent = (supplier, equals) => {
|
|
5
5
|
let done = false;
|
|
6
6
|
let previousValue = null;
|
|
7
7
|
let attempts = 0;
|
|
8
8
|
do {
|
|
9
|
-
assert(attempts < 10);
|
|
9
|
+
Assertions.assert(attempts < 10);
|
|
10
10
|
const currentValue = supplier(previousValue);
|
|
11
|
-
if (isPresent(previousValue) && equals(previousValue, currentValue)) {
|
|
11
|
+
if (Objects.isPresent(previousValue) && equals(previousValue, currentValue)) {
|
|
12
12
|
done = true;
|
|
13
13
|
}
|
|
14
14
|
previousValue = currentValue;
|
package/dist/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/misc.ts"],"sourcesContent":["import { Equalitor } from '@bessemer/cornerstone/equalitor'\nimport
|
|
1
|
+
{"version":3,"sources":["../src/misc.ts"],"sourcesContent":["import { Equalitor } from '@bessemer/cornerstone/equalitor'\nimport * as Objects from '@bessemer/cornerstone/object'\nimport * as Assertions from '@bessemer/cornerstone/assertion'\n\nexport const doUntilConsistent = <T>(supplier: (previous: T | null) => T, equals: Equalitor<T>): T => {\n let done = false\n let previousValue: T | null = null\n let attempts = 0\n do {\n Assertions.assert(attempts < 10)\n\n const currentValue = supplier(previousValue)\n\n if (Objects.isPresent(previousValue) && equals(previousValue, currentValue)) {\n done = true\n }\n\n previousValue = currentValue\n attempts++\n } while (!done)\n\n return previousValue\n}\n"],"mappings":";AACA,YAAY,aAAa;AACzB,YAAY,gBAAgB;AAErB,IAAM,oBAAoB,CAAI,UAAqC,WAA4B;AACpG,MAAI,OAAO;AACX,MAAI,gBAA0B;AAC9B,MAAI,WAAW;AACf,KAAG;AACD,IAAW,kBAAO,WAAW,EAAE;AAE/B,UAAM,eAAe,SAAS,aAAa;AAE3C,QAAY,kBAAU,aAAa,KAAK,OAAO,eAAe,YAAY,GAAG;AAC3E,aAAO;AAAA,IACT;AAEA,oBAAgB;AAChB;AAAA,EACF,SAAS,CAAC;AAEV,SAAO;AACT;","names":[]}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { CurrencyCode } from '@bessemer/cornerstone/intl/currency-code';
|
|
2
2
|
import Zod from 'zod';
|
|
3
3
|
import { Comparator } from '@bessemer/cornerstone/comparator';
|
|
4
|
+
import * as Equalitors from '@bessemer/cornerstone/equalitor';
|
|
4
5
|
export type MonetaryAmount = {
|
|
5
6
|
amount: number;
|
|
6
7
|
currency: CurrencyCode;
|
|
7
8
|
};
|
|
8
9
|
export declare const Schema: Zod.ZodObject<{
|
|
9
10
|
amount: Zod.ZodNumber;
|
|
10
|
-
currency: Zod.ZodPipe<Zod.
|
|
11
|
+
currency: Zod.ZodPipe<Zod.ZodType<CurrencyCode, CurrencyCode, Zod.core.$ZodTypeInternals<CurrencyCode, CurrencyCode>>, Zod.ZodTransform<CurrencyCode, CurrencyCode>>;
|
|
11
12
|
}, Zod.core.$strip>;
|
|
12
13
|
export declare const CompareBy: Comparator<MonetaryAmount>;
|
|
13
|
-
export declare const EqualBy:
|
|
14
|
+
export declare const EqualBy: Equalitors.Equalitor<MonetaryAmount>;
|
|
14
15
|
export declare const of: (amount: number, currency: CurrencyCode) => MonetaryAmount;
|
|
15
16
|
export declare const zero: (currency: CurrencyCode) => MonetaryAmount;
|
|
16
17
|
export declare const apply: <T>(first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => T) => T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monetary-amount.d.ts","sourceRoot":"","sources":["../src/monetary-amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"monetary-amount.d.ts","sourceRoot":"","sources":["../src/monetary-amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MA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