yummies 7.10.0 → 7.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/async.cjs +162 -48
  2. package/async.cjs.map +1 -1
  3. package/async.d.ts +112 -13
  4. package/async.js +163 -54
  5. package/async.js.map +1 -1
  6. package/chunk-CVq3Gv4J.cjs +50 -0
  7. package/chunk-YKewjYmz.js +37 -0
  8. package/common.cjs +48 -8
  9. package/common.cjs.map +1 -1
  10. package/common.d.ts +35 -2
  11. package/common.js +49 -11
  12. package/common.js.map +1 -1
  13. package/complex.cjs +275 -104
  14. package/complex.cjs.map +1 -1
  15. package/complex.d.ts +133 -13
  16. package/complex.js +275 -109
  17. package/complex.js.map +1 -1
  18. package/cookie.cjs +17 -7
  19. package/cookie.cjs.map +1 -1
  20. package/cookie.d.ts +8 -0
  21. package/cookie.js +18 -9
  22. package/cookie.js.map +1 -1
  23. package/css.cjs +147 -39
  24. package/css.cjs.map +1 -1
  25. package/css.d.ts +98 -6
  26. package/css.js +143 -41
  27. package/css.js.map +1 -1
  28. package/data.cjs +90 -55
  29. package/data.cjs.map +1 -1
  30. package/data.d.ts +32 -0
  31. package/data.js +91 -61
  32. package/data.js.map +1 -1
  33. package/date-time.cjs +578 -412
  34. package/date-time.cjs.map +1 -1
  35. package/date-time.d.ts +88 -0
  36. package/date-time.js +575 -421
  37. package/date-time.js.map +1 -1
  38. package/device.cjs +48 -23
  39. package/device.cjs.map +1 -1
  40. package/device.d.ts +32 -0
  41. package/device.js +49 -31
  42. package/device.js.map +1 -1
  43. package/encodings.cjs +275 -266
  44. package/encodings.cjs.map +1 -1
  45. package/encodings.d.ts +8 -0
  46. package/encodings.js +276 -268
  47. package/encodings.js.map +1 -1
  48. package/errors.cjs +20 -18
  49. package/errors.cjs.map +1 -1
  50. package/errors.js +19 -19
  51. package/errors.js.map +1 -1
  52. package/file.cjs +42 -24
  53. package/file.cjs.map +1 -1
  54. package/file.d.ts +16 -0
  55. package/file.js +43 -27
  56. package/file.js.map +1 -1
  57. package/format.cjs +125 -83
  58. package/format.cjs.map +1 -1
  59. package/format.d.ts +89 -4
  60. package/format.js +118 -82
  61. package/format.js.map +1 -1
  62. package/html.cjs +226 -137
  63. package/html.cjs.map +1 -1
  64. package/html.d.ts +67 -3
  65. package/html.js +223 -150
  66. package/html.js.map +1 -1
  67. package/id.cjs +74 -17
  68. package/id.cjs.map +1 -1
  69. package/id.d.ts +10 -10
  70. package/id.js +73 -24
  71. package/id.js.map +1 -1
  72. package/imports.cjs +41 -29
  73. package/imports.cjs.map +1 -1
  74. package/imports.d.ts +13 -4
  75. package/imports.js +40 -31
  76. package/imports.js.map +1 -1
  77. package/math.cjs +32 -6
  78. package/math.cjs.map +1 -1
  79. package/math.d.ts +17 -1
  80. package/math.js +33 -10
  81. package/math.js.map +1 -1
  82. package/media.cjs +275 -84
  83. package/media.cjs.map +1 -1
  84. package/media.d.ts +188 -2
  85. package/media.js +274 -93
  86. package/media.js.map +1 -1
  87. package/mobx.cjs +353 -193
  88. package/mobx.cjs.map +1 -1
  89. package/mobx.d.ts +172 -6
  90. package/mobx.js +351 -200
  91. package/mobx.js.map +1 -1
  92. package/ms.cjs +21 -10
  93. package/ms.cjs.map +1 -1
  94. package/ms.d.ts +1 -1
  95. package/ms.js +22 -13
  96. package/ms.js.map +1 -1
  97. package/number.cjs +13 -7
  98. package/number.cjs.map +1 -1
  99. package/number.js +14 -9
  100. package/number.js.map +1 -1
  101. package/package.json +13 -5
  102. package/parser.cjs +117 -64
  103. package/parser.cjs.map +1 -1
  104. package/parser.d.ts +63 -0
  105. package/parser.js +111 -64
  106. package/parser.js.map +1 -1
  107. package/price.cjs +24 -18
  108. package/price.cjs.map +1 -1
  109. package/price.d.ts +8 -0
  110. package/price.js +25 -20
  111. package/price.js.map +1 -1
  112. package/random.cjs +79 -13
  113. package/random.cjs.map +1 -1
  114. package/random.d.ts +64 -0
  115. package/random.js +80 -22
  116. package/random.js.map +1 -1
  117. package/react.cjs +673 -214
  118. package/react.cjs.map +1 -1
  119. package/react.d.ts +428 -9
  120. package/react.js +674 -239
  121. package/react.js.map +1 -1
  122. package/sound.cjs +14 -9
  123. package/sound.cjs.map +1 -1
  124. package/sound.d.ts +1 -1
  125. package/sound.js +15 -11
  126. package/sound.js.map +1 -1
  127. package/storage.cjs +49 -50
  128. package/storage.cjs.map +1 -1
  129. package/storage.d.ts +15 -6
  130. package/storage.js +50 -53
  131. package/storage.js.map +1 -1
  132. package/text.cjs +51 -34
  133. package/text.cjs.map +1 -1
  134. package/text.d.ts +5 -5
  135. package/text.js +52 -37
  136. package/text.js.map +1 -1
  137. package/type-guard.cjs +292 -72
  138. package/type-guard.cjs.map +1 -1
  139. package/type-guard.d.ts +199 -42
  140. package/type-guard.js +288 -73
  141. package/type-guard.js.map +1 -1
  142. package/types.cjs +0 -2
  143. package/types.global.cjs +0 -2
  144. package/types.global.js +0 -2
  145. package/types.js +0 -2
  146. package/vibrate.cjs +31 -6
  147. package/vibrate.cjs.map +1 -1
  148. package/vibrate.d.ts +23 -1
  149. package/vibrate.js +32 -8
  150. package/vibrate.js.map +1 -1
  151. package/types.cjs.map +0 -1
  152. package/types.global.cjs.map +0 -1
  153. package/types.global.js.map +0 -1
  154. package/types.js.map +0 -1
package/complex.js CHANGED
@@ -1,115 +1,281 @@
1
- const createCounter = (processValue, initial = 0) => {
2
- const update = (counter) => {
3
- fn.value = processValue?.(counter) ?? counter;
4
- return fn.value;
5
- };
6
- const increment = () => update(++fn.counter);
7
- const decrement = () => update(--fn.counter);
8
- const fn = increment;
9
- fn.increment = increment;
10
- fn.decrement = decrement;
11
- fn.reset = () => {
12
- fn.counter = initial;
13
- fn.value = processValue?.(initial) ?? initial;
14
- };
15
- fn.reset();
16
- return fn;
1
+ //#region src/complex/counter.ts
2
+ /**
3
+ * Creates a callable counter object with increment, decrement and reset helpers.
4
+ *
5
+ * The returned function increments the internal numeric counter when called and
6
+ * exposes both the raw counter value and an optionally transformed `value`.
7
+ *
8
+ * @template TValue Public value type returned by the counter.
9
+ * @param processValue Optional mapper that transforms the numeric counter value.
10
+ * @param initial Initial numeric counter value.
11
+ * @returns Callable counter with state and control methods.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const counter = createCounter();
16
+ * counter.increment(); // 1
17
+ * ```
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const idCounter = createCounter((value) => `id-${value}`, 10);
22
+ * idCounter(); // 'id-11'
23
+ * ```
24
+ */
25
+ var createCounter = (processValue, initial = 0) => {
26
+ const update = (counter) => {
27
+ fn.value = processValue?.(counter) ?? counter;
28
+ return fn.value;
29
+ };
30
+ const increment = () => update(++fn.counter);
31
+ const decrement = () => update(--fn.counter);
32
+ const fn = increment;
33
+ fn.increment = increment;
34
+ fn.decrement = decrement;
35
+ fn.reset = () => {
36
+ fn.counter = initial;
37
+ fn.value = processValue?.(initial) ?? initial;
38
+ };
39
+ fn.reset();
40
+ return fn;
17
41
  };
18
- const createGlobalPoint = (accessSymbol) => {
19
- if (accessSymbol == null) {
20
- let storedValue;
21
- return {
22
- get: () => storedValue,
23
- unset: () => {
24
- storedValue = void 0;
25
- },
26
- set: (value) => {
27
- storedValue = value;
28
- return value;
29
- }
30
- };
31
- }
32
- const _globalThis = globalThis;
33
- return {
34
- get: () => _globalThis[accessSymbol],
35
- unset: () => {
36
- delete _globalThis[accessSymbol];
37
- },
38
- set: (value) => {
39
- _globalThis[accessSymbol] = value;
40
- return value;
41
- }
42
- };
42
+ //#endregion
43
+ //#region src/complex/global-point.ts
44
+ /**
45
+ * Creates a simple storage point that can live either in `globalThis` under a
46
+ * provided key or in a local closure when no key is given.
47
+ *
48
+ * @template TValue Stored value type.
49
+ * @param accessSymbol Optional global property name used for storage.
50
+ * @returns Getter/setter API for the stored value.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const point = createGlobalPoint<number>();
55
+ * point.set(10);
56
+ * ```
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const point = createGlobalPoint<string>('__token__');
61
+ * point.get();
62
+ * ```
63
+ */
64
+ var createGlobalPoint = (accessSymbol) => {
65
+ if (accessSymbol == null) {
66
+ let storedValue;
67
+ return {
68
+ get: () => storedValue,
69
+ unset: () => {
70
+ storedValue = void 0;
71
+ },
72
+ set: (value) => {
73
+ storedValue = value;
74
+ return value;
75
+ }
76
+ };
77
+ }
78
+ const _globalThis = globalThis;
79
+ return {
80
+ get: () => _globalThis[accessSymbol],
81
+ unset: () => {
82
+ delete _globalThis[accessSymbol];
83
+ },
84
+ set: (value) => {
85
+ _globalThis[accessSymbol] = value;
86
+ return value;
87
+ }
88
+ };
43
89
  };
44
- const createGlobalConfig = (defaultValue, accessSymbol) => {
45
- const globalPoint = createGlobalPoint(accessSymbol);
46
- return globalPoint.get() || globalPoint.set(defaultValue);
90
+ //#endregion
91
+ //#region src/complex/global-config.ts
92
+ /**
93
+ * Creates or reuses a globally accessible config object.
94
+ *
95
+ * The config is stored in a global point identified by `accessSymbol`, or in a
96
+ * local closure when no symbol is provided.
97
+ *
98
+ * @template T Config object type.
99
+ * @param defaultValue Default value used when no config has been created yet.
100
+ * @param accessSymbol Optional global key used to store the config.
101
+ * @returns Existing or newly initialized global config object.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * const config = createGlobalConfig({ locale: 'en' }, '__app_config__');
106
+ * ```
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const config = createGlobalConfig({ debug: false });
111
+ * config.debug;
112
+ * ```
113
+ */
114
+ var createGlobalConfig = (defaultValue, accessSymbol) => {
115
+ const globalPoint = createGlobalPoint(accessSymbol);
116
+ return globalPoint.get() || globalPoint.set(defaultValue);
47
117
  };
48
- const createGlobalDynamicConfig = (processFn, accessSymbol) => {
49
- const globalPoint = createGlobalPoint(accessSymbol);
50
- const getValue = () => {
51
- return globalPoint.get() ?? globalPoint.set(processFn(null, null));
52
- };
53
- return {
54
- get: getValue,
55
- set: globalPoint.set,
56
- unset: globalPoint.unset,
57
- update: (value) => {
58
- const currentValue = getValue();
59
- Object.assign(currentValue, processFn(value, currentValue));
60
- }
61
- };
118
+ /**
119
+ * Creates a mutable global config manager whose value is produced and updated
120
+ * through a custom processor function.
121
+ *
122
+ * @template T Config object type.
123
+ * @param processFn Function that builds the next config state from a partial change and current value.
124
+ * @param accessSymbol Optional global key used to store the config.
125
+ * @returns API for reading, replacing, resetting and partially updating the config.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const config = createGlobalDynamicConfig(
130
+ * (change, current) => ({ theme: 'light', ...current, ...change }),
131
+ * '__theme__',
132
+ * );
133
+ * ```
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const config = createGlobalDynamicConfig((change, current) => ({ ...current, ...change }));
138
+ * config.update({ locale: 'ru' });
139
+ * ```
140
+ */
141
+ var createGlobalDynamicConfig = (processFn, accessSymbol) => {
142
+ const globalPoint = createGlobalPoint(accessSymbol);
143
+ const getValue = () => {
144
+ return globalPoint.get() ?? globalPoint.set(processFn(null, null));
145
+ };
146
+ return {
147
+ get: getValue,
148
+ set: globalPoint.set,
149
+ unset: globalPoint.unset,
150
+ update: (value) => {
151
+ const currentValue = getValue();
152
+ Object.assign(currentValue, processFn(value, currentValue));
153
+ }
154
+ };
62
155
  };
63
- class ModulesFactory {
64
- /**
65
- * Создает новый экземпляр `ModulesFactory`.
66
- *
67
- * @param config - Объект конфигурации для фабрики, включающий функцию фабрики и необязательные зависимости.
68
- */
69
- constructor(config) {
70
- this.config = config;
71
- }
72
- /**
73
- * Создает экземпляр указанного класса, внедряя необходимые зависимости.
74
- *
75
- * @template TInstance - Тип создаваемого экземпляра.
76
- * @template TDeps - Тип зависимостей, необходимых для экземпляра.
77
- *
78
- * @param Constructor - Конструктор класса для создаваемого экземпляра.
79
- * @param args - Необязательные дополнительные зависимости для объединения с предопределенными зависимостями.
80
- *
81
- * @returns Экземпляр указанного класса с внедренными зависимостями.
82
- */
83
- create(Constructor, ...args) {
84
- return this.config.factory(Constructor, {
85
- ...this.config.deps,
86
- ...args[0]
87
- });
88
- }
89
- }
90
- const createPubSub = () => {
91
- const pubSub = ((...args) => {
92
- pubSub.lastPub = args;
93
- pubSub.subs.forEach((sub) => {
94
- sub(...args);
95
- });
96
- });
97
- pubSub.lastPub = void 0;
98
- pubSub.subs = [];
99
- pubSub.unsub = (sub) => {
100
- pubSub.subs = pubSub.subs.filter((it) => it !== sub);
101
- };
102
- pubSub.sub = (sub) => {
103
- pubSub.subs.push(sub);
104
- return () => pubSub.unsub(sub);
105
- };
106
- return pubSub;
156
+ //#endregion
157
+ //#region src/complex/modules-factory.ts
158
+ /**
159
+ * Universal factory for creating class instances with predefined and per-call
160
+ * dependencies.
161
+ *
162
+ * Works with classes whose constructor accepts a single dependency object.
163
+ *
164
+ * @template TPredefinedDeps Dependency shape that is always injected by the factory.
165
+ *
166
+ * @example
167
+ * ```
168
+ * const factory = new ModulesFactory({
169
+ * factory: (MyClass, deps) => new MyClass(deps),
170
+ * deps: { someDependency: new Dependency() }
171
+ * });
172
+ *
173
+ * const instance = factory.create(MyClass, { extraDependency: new ExtraDependency() });
174
+ * ```
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * const factory = new ModulesFactory({
179
+ * factory: (Module, deps) => new Module(deps),
180
+ * });
181
+ * ```
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * const service = factory.create(UserService, { api });
186
+ * ```
187
+ */
188
+ var ModulesFactory = class {
189
+ /**
190
+ * Creates a new module factory.
191
+ *
192
+ * @param config Factory strategy and predefined dependencies.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * const factory = new ModulesFactory({
197
+ * factory: (Module, deps) => new Module(deps),
198
+ * });
199
+ * ```
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * const factory = new ModulesFactory({
204
+ * factory: (Module, deps) => new Module(deps),
205
+ * deps: { api },
206
+ * });
207
+ * ```
208
+ */
209
+ constructor(config) {
210
+ this.config = config;
211
+ }
212
+ /**
213
+ * Creates an instance of the provided class by merging predefined and
214
+ * per-call dependencies.
215
+ *
216
+ * @template TInstance Instance type produced by the constructor.
217
+ * @template TDeps Full dependency object expected by the constructor.
218
+ * @param Constructor Class constructor receiving a single dependency object.
219
+ * @param args Additional dependencies merged over predefined ones.
220
+ * @returns Created class instance.
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * const service = factory.create(UserService, { logger });
225
+ * ```
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * const store = factory.create(UserStore);
230
+ * ```
231
+ */
232
+ create(Constructor, ...args) {
233
+ return this.config.factory(Constructor, {
234
+ ...this.config.deps,
235
+ ...args[0]
236
+ });
237
+ }
107
238
  };
108
- export {
109
- ModulesFactory,
110
- createCounter,
111
- createGlobalConfig,
112
- createGlobalDynamicConfig,
113
- createPubSub
239
+ //#endregion
240
+ //#region src/complex/pub-sub.ts
241
+ /**
242
+ * Creates a simple publish-subscribe dispatcher that stores the last published
243
+ * arguments and allows subscription management.
244
+ *
245
+ * @template PubArgs Argument tuple delivered to subscribers.
246
+ * @returns Callable publisher with subscribe and unsubscribe helpers.
247
+ *
248
+ * @example
249
+ * ```ts
250
+ * const pub = createPubSub<[string]>();
251
+ * pub('ready');
252
+ * ```
253
+ *
254
+ * @example
255
+ * ```ts
256
+ * const pub = createPubSub<[number]>();
257
+ * const unsub = pub.sub((value) => console.log(value));
258
+ * ```
259
+ */
260
+ var createPubSub = () => {
261
+ const pubSub = ((...args) => {
262
+ pubSub.lastPub = args;
263
+ pubSub.subs.forEach((sub) => {
264
+ sub(...args);
265
+ });
266
+ });
267
+ pubSub.lastPub = void 0;
268
+ pubSub.subs = [];
269
+ pubSub.unsub = (sub) => {
270
+ pubSub.subs = pubSub.subs.filter((it) => it !== sub);
271
+ };
272
+ pubSub.sub = (sub) => {
273
+ pubSub.subs.push(sub);
274
+ return () => pubSub.unsub(sub);
275
+ };
276
+ return pubSub;
114
277
  };
115
- //# sourceMappingURL=complex.js.map
278
+ //#endregion
279
+ export { ModulesFactory, createCounter, createGlobalConfig, createGlobalDynamicConfig, createPubSub };
280
+
281
+ //# sourceMappingURL=complex.js.map
package/complex.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"complex.js","sources":["../src/complex/counter.ts","../src/complex/global-point.ts","../src/complex/global-config.ts","../src/complex/modules-factory.ts","../src/complex/pub-sub.ts"],"sourcesContent":["export interface Counter<TValue = number> {\n (): TValue;\n counter: number;\n value: TValue;\n increment(): TValue;\n decrement(): TValue;\n reset(): void;\n}\n\n/**\n * @deprecated use {`Counter`}. Will be removed in next major release\n */\nexport interface CounterFn<TValue = number> extends Counter<TValue> {}\n\nexport const createCounter = <TValue = number>(\n processValue?: (value: number) => TValue,\n initial: number = 0,\n): Counter<TValue> => {\n const update = (counter: number) => {\n fn.value = processValue?.(counter) ?? (counter as TValue);\n return fn.value;\n };\n\n const increment = () => update(++fn.counter);\n const decrement = () => update(--fn.counter);\n\n const fn: Counter<TValue> = increment as any;\n\n fn.increment = increment;\n fn.decrement = decrement;\n\n fn.reset = () => {\n fn.counter = initial;\n fn.value = processValue?.(initial) ?? (initial as TValue);\n };\n\n fn.reset();\n\n return fn as Counter<TValue>;\n};\n","import type { AnyObject } from 'yummies/types';\n\nexport interface GlobalPoint<TValue> {\n get(): TValue;\n set(value: TValue): TValue;\n unset(): void;\n}\n\nexport const createGlobalPoint = <TValue>(\n accessSymbol?: keyof any,\n): GlobalPoint<TValue> => {\n if (accessSymbol == null) {\n let storedValue: TValue | undefined;\n\n return {\n get: (): TValue => storedValue!,\n unset: () => {\n storedValue = undefined;\n },\n set: (value: TValue): TValue => {\n storedValue = value;\n return value;\n },\n };\n }\n\n const _globalThis = globalThis as AnyObject;\n\n return {\n get: (): TValue => _globalThis[accessSymbol],\n unset: () => {\n delete _globalThis[accessSymbol];\n },\n set: (value: TValue): TValue => {\n _globalThis[accessSymbol] = value;\n return value;\n },\n };\n};\n","import type { AnyObject, Maybe } from 'yummies/types';\nimport { createGlobalPoint } from './global-point.js';\n\n/**\n * Создает глобальный конфиг, который может быть доступен в любой точке в коде\n */\nexport const createGlobalConfig = <T extends AnyObject>(\n defaultValue: T,\n accessSymbol?: keyof any,\n): T => {\n const globalPoint = createGlobalPoint<T>(accessSymbol);\n return globalPoint.get() || globalPoint.set(defaultValue);\n};\n\nexport interface GlobalDynamicConfig<TValue extends AnyObject> {\n get(): TValue;\n set(value: TValue): TValue;\n unset(): void;\n update(value: Partial<TValue>): void;\n}\n\nexport const createGlobalDynamicConfig = <T extends AnyObject>(\n processFn: (change: Maybe<Partial<T>>, current: Maybe<T>) => T,\n accessSymbol?: keyof any,\n): GlobalDynamicConfig<T> => {\n const globalPoint = createGlobalPoint<T>(accessSymbol);\n\n const getValue = () => {\n return globalPoint.get() ?? globalPoint.set(processFn(null, null))!;\n };\n\n return {\n get: getValue,\n set: globalPoint.set,\n unset: globalPoint.unset,\n update: (value: Partial<T>) => {\n const currentValue = getValue();\n Object.assign(currentValue, processFn(value, currentValue));\n },\n };\n};\n","import type { AnyObject, Class, EmptyObject, IsPartial } from 'yummies/types';\n\ntype ModuleLoaderConfig<TPredefinedDeps extends AnyObject = EmptyObject> = {\n factory<TInstance, TDeps extends TPredefinedDeps>(\n moduleClass: Class<TInstance, [TDeps]>,\n deps: TDeps,\n ): TInstance;\n} & (TPredefinedDeps extends EmptyObject\n ? { deps?: TPredefinedDeps }\n : { deps: TPredefinedDeps });\n\n/**\n * Класс `ModulesFactory` является универсальной фабрикой для создания экземпляров указанного класса с зависимостями.\n * Он использует объект конфигурации для определения того, как эти экземпляры создаются.\n *\n * Важное примечание - эта сущность работает только с классами конструктор которых имеет один параметр\n *\n * @template TPredefinedDeps - Тип, расширяющий `AnyObject`, представляющий предопределенные зависимости, которые использует фабрика.\n *\n * @example\n * ```\n * const factory = new ModulesFactory({\n * factory: (MyClass, deps) => new MyClass(deps),\n * deps: { someDependency: new Dependency() }\n * });\n *\n * const instance = factory.create(MyClass, { extraDependency: new ExtraDependency() });\n * ```\n */\nexport class ModulesFactory<TPredefinedDeps extends AnyObject = EmptyObject> {\n /**\n * Создает новый экземпляр `ModulesFactory`.\n *\n * @param config - Объект конфигурации для фабрики, включающий функцию фабрики и необязательные зависимости.\n */\n constructor(private config: ModuleLoaderConfig<TPredefinedDeps>) {}\n\n /**\n * Создает экземпляр указанного класса, внедряя необходимые зависимости.\n *\n * @template TInstance - Тип создаваемого экземпляра.\n * @template TDeps - Тип зависимостей, необходимых для экземпляра.\n *\n * @param Constructor - Конструктор класса для создаваемого экземпляра.\n * @param args - Необязательные дополнительные зависимости для объединения с предопределенными зависимостями.\n *\n * @returns Экземпляр указанного класса с внедренными зависимостями.\n */\n create<TInstance, TDeps extends TPredefinedDeps = TPredefinedDeps>(\n Constructor: Class<TInstance, [TDeps]>,\n ...args: IsPartial<Omit<TDeps, keyof TPredefinedDeps>> extends true\n ? [extraDeps?: Omit<TDeps, keyof TPredefinedDeps>]\n : [extraDeps: Omit<TDeps, keyof TPredefinedDeps>]\n ) {\n return this.config.factory(Constructor, {\n ...this.config.deps!,\n ...args[0],\n } as any);\n }\n}\n","export type SubFn<PubArgs extends any[] = any[]> = (...args: PubArgs) => void;\n\n/**\n * The Publish-Subscribe pattern, which allows objects to interact with each other\n * through an event system. Subscribers can subscribe to events and receive notifications\n * when these events occur. The last published data can be accessed through the `data` property.\n */\nexport interface PubSub<PubArgs extends any[] = any[]> {\n (...args: PubArgs): void;\n\n /**\n * Last published arguments\n */\n lastPub: PubArgs | undefined;\n\n /**\n * An array of subscriber functions (sub) that will be called\n * when an event is published. Each subscriber must match the type SubFn,\n * taking the arguments that will be passed to it when the publisher calls pub.\n */\n subs: SubFn<PubArgs>[];\n\n /**\n * A function to unsubscribe from events. When a subscriber function (sub) is passed,\n * it will be removed from the `subs` array, and will no longer receive notifications.\n */\n unsub(sub: SubFn<PubArgs>): void;\n /**\n * A function to subscribe to events. When a subscriber function (sub) is passed,\n * it will be added to the `subs` array, and will receive notifications when the publisher calls pub.\n * Returns a function that can be used to unsubscribe from events.\n */\n sub(sub: SubFn<PubArgs>): VoidFunction;\n}\n\nexport const createPubSub = <PubArgs extends any[] = any[]>() => {\n const pubSub = ((...args: PubArgs) => {\n pubSub.lastPub = args;\n pubSub.subs.forEach((sub) => {\n sub(...args);\n });\n }) as PubSub<PubArgs>;\n pubSub.lastPub = undefined;\n\n pubSub.subs = [];\n\n pubSub.unsub = (sub: SubFn<PubArgs>) => {\n pubSub.subs = pubSub.subs.filter((it) => it !== sub);\n };\n pubSub.sub = (sub: SubFn<PubArgs>) => {\n pubSub.subs.push(sub);\n return () => pubSub.unsub(sub);\n };\n\n return pubSub;\n};\n"],"names":[],"mappings":"AAcO,MAAM,gBAAgB,CAC3B,cACA,UAAkB,MACE;AACpB,QAAM,SAAS,CAAC,YAAoB;AAClC,OAAG,QAAQ,eAAe,OAAO,KAAM;AACvC,WAAO,GAAG;AAAA,EACZ;AAEA,QAAM,YAAY,MAAM,OAAO,EAAE,GAAG,OAAO;AAC3C,QAAM,YAAY,MAAM,OAAO,EAAE,GAAG,OAAO;AAE3C,QAAM,KAAsB;AAE5B,KAAG,YAAY;AACf,KAAG,YAAY;AAEf,KAAG,QAAQ,MAAM;AACf,OAAG,UAAU;AACb,OAAG,QAAQ,eAAe,OAAO,KAAM;AAAA,EACzC;AAEA,KAAG,MAAA;AAEH,SAAO;AACT;AC/BO,MAAM,oBAAoB,CAC/B,iBACwB;AACxB,MAAI,gBAAgB,MAAM;AACxB,QAAI;AAEJ,WAAO;AAAA,MACL,KAAK,MAAc;AAAA,MACnB,OAAO,MAAM;AACX,sBAAc;AAAA,MAChB;AAAA,MACA,KAAK,CAAC,UAA0B;AAC9B,sBAAc;AACd,eAAO;AAAA,MACT;AAAA,IAAA;AAAA,EAEJ;AAEA,QAAM,cAAc;AAEpB,SAAO;AAAA,IACL,KAAK,MAAc,YAAY,YAAY;AAAA,IAC3C,OAAO,MAAM;AACX,aAAO,YAAY,YAAY;AAAA,IACjC;AAAA,IACA,KAAK,CAAC,UAA0B;AAC9B,kBAAY,YAAY,IAAI;AAC5B,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;AChCO,MAAM,qBAAqB,CAChC,cACA,iBACM;AACN,QAAM,cAAc,kBAAqB,YAAY;AACrD,SAAO,YAAY,IAAA,KAAS,YAAY,IAAI,YAAY;AAC1D;AASO,MAAM,4BAA4B,CACvC,WACA,iBAC2B;AAC3B,QAAM,cAAc,kBAAqB,YAAY;AAErD,QAAM,WAAW,MAAM;AACrB,WAAO,YAAY,SAAS,YAAY,IAAI,UAAU,MAAM,IAAI,CAAC;AAAA,EACnE;AAEA,SAAO;AAAA,IACL,KAAK;AAAA,IACL,KAAK,YAAY;AAAA,IACjB,OAAO,YAAY;AAAA,IACnB,QAAQ,CAAC,UAAsB;AAC7B,YAAM,eAAe,SAAA;AACrB,aAAO,OAAO,cAAc,UAAU,OAAO,YAAY,CAAC;AAAA,IAC5D;AAAA,EAAA;AAEJ;ACXO,MAAM,eAAgE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3E,YAAoB,QAA6C;AAA7C,SAAA,SAAA;AAAA,EAA8C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAalE,OACE,gBACG,MAGH;AACA,WAAO,KAAK,OAAO,QAAQ,aAAa;AAAA,MACtC,GAAG,KAAK,OAAO;AAAA,MACf,GAAG,KAAK,CAAC;AAAA,IAAA,CACH;AAAA,EACV;AACF;ACxBO,MAAM,eAAe,MAAqC;AAC/D,QAAM,UAAU,IAAI,SAAkB;AACpC,WAAO,UAAU;AACjB,WAAO,KAAK,QAAQ,CAAC,QAAQ;AAC3B,UAAI,GAAG,IAAI;AAAA,IACb,CAAC;AAAA,EACH;AACA,SAAO,UAAU;AAEjB,SAAO,OAAO,CAAA;AAEd,SAAO,QAAQ,CAAC,QAAwB;AACtC,WAAO,OAAO,OAAO,KAAK,OAAO,CAAC,OAAO,OAAO,GAAG;AAAA,EACrD;AACA,SAAO,MAAM,CAAC,QAAwB;AACpC,WAAO,KAAK,KAAK,GAAG;AACpB,WAAO,MAAM,OAAO,MAAM,GAAG;AAAA,EAC/B;AAEA,SAAO;AACT;"}
1
+ {"version":3,"file":"complex.js","names":[],"sources":["../src/complex/counter.ts","../src/complex/global-point.ts","../src/complex/global-config.ts","../src/complex/modules-factory.ts","../src/complex/pub-sub.ts"],"sourcesContent":["export interface Counter<TValue = number> {\n (): TValue;\n counter: number;\n value: TValue;\n increment(): TValue;\n decrement(): TValue;\n reset(): void;\n}\n\n/**\n * @deprecated use {`Counter`}. Will be removed in next major release\n */\nexport interface CounterFn<TValue = number> extends Counter<TValue> {}\n\n/**\n * Creates a callable counter object with increment, decrement and reset helpers.\n *\n * The returned function increments the internal numeric counter when called and\n * exposes both the raw counter value and an optionally transformed `value`.\n *\n * @template TValue Public value type returned by the counter.\n * @param processValue Optional mapper that transforms the numeric counter value.\n * @param initial Initial numeric counter value.\n * @returns Callable counter with state and control methods.\n *\n * @example\n * ```ts\n * const counter = createCounter();\n * counter.increment(); // 1\n * ```\n *\n * @example\n * ```ts\n * const idCounter = createCounter((value) => `id-${value}`, 10);\n * idCounter(); // 'id-11'\n * ```\n */\nexport const createCounter = <TValue = number>(\n processValue?: (value: number) => TValue,\n initial: number = 0,\n): Counter<TValue> => {\n const update = (counter: number) => {\n fn.value = processValue?.(counter) ?? (counter as TValue);\n return fn.value;\n };\n\n const increment = () => update(++fn.counter);\n const decrement = () => update(--fn.counter);\n\n const fn: Counter<TValue> = increment as any;\n\n fn.increment = increment;\n fn.decrement = decrement;\n\n fn.reset = () => {\n fn.counter = initial;\n fn.value = processValue?.(initial) ?? (initial as TValue);\n };\n\n fn.reset();\n\n return fn as Counter<TValue>;\n};\n","import type { AnyObject } from 'yummies/types';\n\nexport interface GlobalPoint<TValue> {\n get(): TValue;\n set(value: TValue): TValue;\n unset(): void;\n}\n\n/**\n * Creates a simple storage point that can live either in `globalThis` under a\n * provided key or in a local closure when no key is given.\n *\n * @template TValue Stored value type.\n * @param accessSymbol Optional global property name used for storage.\n * @returns Getter/setter API for the stored value.\n *\n * @example\n * ```ts\n * const point = createGlobalPoint<number>();\n * point.set(10);\n * ```\n *\n * @example\n * ```ts\n * const point = createGlobalPoint<string>('__token__');\n * point.get();\n * ```\n */\nexport const createGlobalPoint = <TValue>(\n accessSymbol?: keyof any,\n): GlobalPoint<TValue> => {\n if (accessSymbol == null) {\n let storedValue: TValue | undefined;\n\n return {\n get: (): TValue => storedValue!,\n unset: () => {\n storedValue = undefined;\n },\n set: (value: TValue): TValue => {\n storedValue = value;\n return value;\n },\n };\n }\n\n const _globalThis = globalThis as AnyObject;\n\n return {\n get: (): TValue => _globalThis[accessSymbol],\n unset: () => {\n delete _globalThis[accessSymbol];\n },\n set: (value: TValue): TValue => {\n _globalThis[accessSymbol] = value;\n return value;\n },\n };\n};\n","import type { AnyObject, Maybe } from 'yummies/types';\nimport { createGlobalPoint } from './global-point.js';\n\n/**\n * Creates or reuses a globally accessible config object.\n *\n * The config is stored in a global point identified by `accessSymbol`, or in a\n * local closure when no symbol is provided.\n *\n * @template T Config object type.\n * @param defaultValue Default value used when no config has been created yet.\n * @param accessSymbol Optional global key used to store the config.\n * @returns Existing or newly initialized global config object.\n *\n * @example\n * ```ts\n * const config = createGlobalConfig({ locale: 'en' }, '__app_config__');\n * ```\n *\n * @example\n * ```ts\n * const config = createGlobalConfig({ debug: false });\n * config.debug;\n * ```\n */\nexport const createGlobalConfig = <T extends AnyObject>(\n defaultValue: T,\n accessSymbol?: keyof any,\n): T => {\n const globalPoint = createGlobalPoint<T>(accessSymbol);\n return globalPoint.get() || globalPoint.set(defaultValue);\n};\n\nexport interface GlobalDynamicConfig<TValue extends AnyObject> {\n get(): TValue;\n set(value: TValue): TValue;\n unset(): void;\n update(value: Partial<TValue>): void;\n}\n\n/**\n * Creates a mutable global config manager whose value is produced and updated\n * through a custom processor function.\n *\n * @template T Config object type.\n * @param processFn Function that builds the next config state from a partial change and current value.\n * @param accessSymbol Optional global key used to store the config.\n * @returns API for reading, replacing, resetting and partially updating the config.\n *\n * @example\n * ```ts\n * const config = createGlobalDynamicConfig(\n * (change, current) => ({ theme: 'light', ...current, ...change }),\n * '__theme__',\n * );\n * ```\n *\n * @example\n * ```ts\n * const config = createGlobalDynamicConfig((change, current) => ({ ...current, ...change }));\n * config.update({ locale: 'ru' });\n * ```\n */\nexport const createGlobalDynamicConfig = <T extends AnyObject>(\n processFn: (change: Maybe<Partial<T>>, current: Maybe<T>) => T,\n accessSymbol?: keyof any,\n): GlobalDynamicConfig<T> => {\n const globalPoint = createGlobalPoint<T>(accessSymbol);\n\n const getValue = () => {\n return globalPoint.get() ?? globalPoint.set(processFn(null, null))!;\n };\n\n return {\n get: getValue,\n set: globalPoint.set,\n unset: globalPoint.unset,\n update: (value: Partial<T>) => {\n const currentValue = getValue();\n Object.assign(currentValue, processFn(value, currentValue));\n },\n };\n};\n","import type { AnyObject, Class, EmptyObject, IsPartial } from 'yummies/types';\n\ntype ModuleLoaderConfig<TPredefinedDeps extends AnyObject = EmptyObject> = {\n factory<TInstance, TDeps extends TPredefinedDeps>(\n moduleClass: Class<TInstance, [TDeps]>,\n deps: TDeps,\n ): TInstance;\n} & (TPredefinedDeps extends EmptyObject\n ? { deps?: TPredefinedDeps }\n : { deps: TPredefinedDeps });\n\n/**\n * Universal factory for creating class instances with predefined and per-call\n * dependencies.\n *\n * Works with classes whose constructor accepts a single dependency object.\n *\n * @template TPredefinedDeps Dependency shape that is always injected by the factory.\n *\n * @example\n * ```\n * const factory = new ModulesFactory({\n * factory: (MyClass, deps) => new MyClass(deps),\n * deps: { someDependency: new Dependency() }\n * });\n *\n * const instance = factory.create(MyClass, { extraDependency: new ExtraDependency() });\n * ```\n *\n * @example\n * ```ts\n * const factory = new ModulesFactory({\n * factory: (Module, deps) => new Module(deps),\n * });\n * ```\n *\n * @example\n * ```ts\n * const service = factory.create(UserService, { api });\n * ```\n */\nexport class ModulesFactory<TPredefinedDeps extends AnyObject = EmptyObject> {\n /**\n * Creates a new module factory.\n *\n * @param config Factory strategy and predefined dependencies.\n *\n * @example\n * ```ts\n * const factory = new ModulesFactory({\n * factory: (Module, deps) => new Module(deps),\n * });\n * ```\n *\n * @example\n * ```ts\n * const factory = new ModulesFactory({\n * factory: (Module, deps) => new Module(deps),\n * deps: { api },\n * });\n * ```\n */\n constructor(private config: ModuleLoaderConfig<TPredefinedDeps>) {}\n\n /**\n * Creates an instance of the provided class by merging predefined and\n * per-call dependencies.\n *\n * @template TInstance Instance type produced by the constructor.\n * @template TDeps Full dependency object expected by the constructor.\n * @param Constructor Class constructor receiving a single dependency object.\n * @param args Additional dependencies merged over predefined ones.\n * @returns Created class instance.\n *\n * @example\n * ```ts\n * const service = factory.create(UserService, { logger });\n * ```\n *\n * @example\n * ```ts\n * const store = factory.create(UserStore);\n * ```\n */\n create<TInstance, TDeps extends TPredefinedDeps = TPredefinedDeps>(\n Constructor: Class<TInstance, [TDeps]>,\n ...args: IsPartial<Omit<TDeps, keyof TPredefinedDeps>> extends true\n ? [extraDeps?: Omit<TDeps, keyof TPredefinedDeps>]\n : [extraDeps: Omit<TDeps, keyof TPredefinedDeps>]\n ) {\n return this.config.factory(Constructor, {\n ...this.config.deps!,\n ...args[0],\n } as any);\n }\n}\n","export type SubFn<PubArgs extends any[] = any[]> = (...args: PubArgs) => void;\n\n/**\n * The Publish-Subscribe pattern, which allows objects to interact with each other\n * through an event system. Subscribers can subscribe to events and receive notifications\n * when these events occur. The last published data can be accessed through the `data` property.\n */\nexport interface PubSub<PubArgs extends any[] = any[]> {\n (...args: PubArgs): void;\n\n /**\n * Last published arguments\n */\n lastPub: PubArgs | undefined;\n\n /**\n * An array of subscriber functions (sub) that will be called\n * when an event is published. Each subscriber must match the type SubFn,\n * taking the arguments that will be passed to it when the publisher calls pub.\n */\n subs: SubFn<PubArgs>[];\n\n /**\n * A function to unsubscribe from events. When a subscriber function (sub) is passed,\n * it will be removed from the `subs` array, and will no longer receive notifications.\n */\n unsub(sub: SubFn<PubArgs>): void;\n /**\n * A function to subscribe to events. When a subscriber function (sub) is passed,\n * it will be added to the `subs` array, and will receive notifications when the publisher calls pub.\n * Returns a function that can be used to unsubscribe from events.\n */\n sub(sub: SubFn<PubArgs>): VoidFunction;\n}\n\n/**\n * Creates a simple publish-subscribe dispatcher that stores the last published\n * arguments and allows subscription management.\n *\n * @template PubArgs Argument tuple delivered to subscribers.\n * @returns Callable publisher with subscribe and unsubscribe helpers.\n *\n * @example\n * ```ts\n * const pub = createPubSub<[string]>();\n * pub('ready');\n * ```\n *\n * @example\n * ```ts\n * const pub = createPubSub<[number]>();\n * const unsub = pub.sub((value) => console.log(value));\n * ```\n */\nexport const createPubSub = <PubArgs extends any[] = any[]>() => {\n const pubSub = ((...args: PubArgs) => {\n pubSub.lastPub = args;\n pubSub.subs.forEach((sub) => {\n sub(...args);\n });\n }) as PubSub<PubArgs>;\n pubSub.lastPub = undefined;\n\n pubSub.subs = [];\n\n pubSub.unsub = (sub: SubFn<PubArgs>) => {\n pubSub.subs = pubSub.subs.filter((it) => it !== sub);\n };\n pubSub.sub = (sub: SubFn<PubArgs>) => {\n pubSub.subs.push(sub);\n return () => pubSub.unsub(sub);\n };\n\n return pubSub;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,iBACX,cACA,UAAkB,MACE;CACpB,MAAM,UAAU,YAAoB;AAClC,KAAG,QAAQ,eAAe,QAAQ,IAAK;AACvC,SAAO,GAAG;;CAGZ,MAAM,kBAAkB,OAAO,EAAE,GAAG,QAAQ;CAC5C,MAAM,kBAAkB,OAAO,EAAE,GAAG,QAAQ;CAE5C,MAAM,KAAsB;AAE5B,IAAG,YAAY;AACf,IAAG,YAAY;AAEf,IAAG,cAAc;AACf,KAAG,UAAU;AACb,KAAG,QAAQ,eAAe,QAAQ,IAAK;;AAGzC,IAAG,OAAO;AAEV,QAAO;;;;;;;;;;;;;;;;;;;;;;;;ACjCT,IAAa,qBACX,iBACwB;AACxB,KAAI,gBAAgB,MAAM;EACxB,IAAI;AAEJ,SAAO;GACL,WAAmB;GACnB,aAAa;AACX,kBAAc,KAAA;;GAEhB,MAAM,UAA0B;AAC9B,kBAAc;AACd,WAAO;;GAEV;;CAGH,MAAM,cAAc;AAEpB,QAAO;EACL,WAAmB,YAAY;EAC/B,aAAa;AACX,UAAO,YAAY;;EAErB,MAAM,UAA0B;AAC9B,eAAY,gBAAgB;AAC5B,UAAO;;EAEV;;;;;;;;;;;;;;;;;;;;;;;;;;AChCH,IAAa,sBACX,cACA,iBACM;CACN,MAAM,cAAc,kBAAqB,aAAa;AACtD,QAAO,YAAY,KAAK,IAAI,YAAY,IAAI,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;AAiC3D,IAAa,6BACX,WACA,iBAC2B;CAC3B,MAAM,cAAc,kBAAqB,aAAa;CAEtD,MAAM,iBAAiB;AACrB,SAAO,YAAY,KAAK,IAAI,YAAY,IAAI,UAAU,MAAM,KAAK,CAAC;;AAGpE,QAAO;EACL,KAAK;EACL,KAAK,YAAY;EACjB,OAAO,YAAY;EACnB,SAAS,UAAsB;GAC7B,MAAM,eAAe,UAAU;AAC/B,UAAO,OAAO,cAAc,UAAU,OAAO,aAAa,CAAC;;EAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACxCH,IAAa,iBAAb,MAA6E;;;;;;;;;;;;;;;;;;;;;CAqB3E,YAAY,QAAqD;AAA7C,OAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;CAsBpB,OACE,aACA,GAAG,MAGH;AACA,SAAO,KAAK,OAAO,QAAQ,aAAa;GACtC,GAAG,KAAK,OAAO;GACf,GAAG,KAAK;GACT,CAAQ;;;;;;;;;;;;;;;;;;;;;;;;ACvCb,IAAa,qBAAoD;CAC/D,MAAM,WAAW,GAAG,SAAkB;AACpC,SAAO,UAAU;AACjB,SAAO,KAAK,SAAS,QAAQ;AAC3B,OAAI,GAAG,KAAK;IACZ;;AAEJ,QAAO,UAAU,KAAA;AAEjB,QAAO,OAAO,EAAE;AAEhB,QAAO,SAAS,QAAwB;AACtC,SAAO,OAAO,OAAO,KAAK,QAAQ,OAAO,OAAO,IAAI;;AAEtD,QAAO,OAAO,QAAwB;AACpC,SAAO,KAAK,KAAK,IAAI;AACrB,eAAa,OAAO,MAAM,IAAI;;AAGhC,QAAO"}
package/cookie.cjs CHANGED
@@ -1,10 +1,20 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const parseCookie = (cookiesString = document.cookie) => {
4
- return cookiesString.split(";").map((cookieString) => cookieString.trim().split("=")).reduce((acc, current) => {
5
- acc[current[0]] = current[1];
6
- return acc;
7
- }, {});
2
+ //#region src/cookie.ts
3
+ /**
4
+ * Parses a cookie string into an object with cookie names as keys.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * parseCookie('theme=dark; token=abc');
9
+ * ```
10
+ */
11
+ var parseCookie = (cookiesString = document.cookie) => {
12
+ return cookiesString.split(";").map((cookieString) => cookieString.trim().split("=")).reduce((acc, current) => {
13
+ acc[current[0]] = current[1];
14
+ return acc;
15
+ }, {});
8
16
  };
17
+ //#endregion
9
18
  exports.parseCookie = parseCookie;
10
- //# sourceMappingURL=cookie.cjs.map
19
+
20
+ //# sourceMappingURL=cookie.cjs.map
package/cookie.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cookie.cjs","sources":["../src/cookie.ts"],"sourcesContent":["import type { AnyObject } from 'yummies/types';\n\nexport const parseCookie = (cookiesString = document.cookie) => {\n return cookiesString\n .split(';')\n .map((cookieString) => cookieString.trim().split('='))\n .reduce<AnyObject>((acc, current) => {\n acc[current[0]] = current[1];\n return acc;\n }, {});\n};\n"],"names":[],"mappings":";;AAEO,MAAM,cAAc,CAAC,gBAAgB,SAAS,WAAW;AAC9D,SAAO,cACJ,MAAM,GAAG,EACT,IAAI,CAAC,iBAAiB,aAAa,KAAA,EAAO,MAAM,GAAG,CAAC,EACpD,OAAkB,CAAC,KAAK,YAAY;AACnC,QAAI,QAAQ,CAAC,CAAC,IAAI,QAAQ,CAAC;AAC3B,WAAO;AAAA,EACT,GAAG,CAAA,CAAE;AACT;;"}
1
+ {"version":3,"file":"cookie.cjs","names":[],"sources":["../src/cookie.ts"],"sourcesContent":["import type { AnyObject } from 'yummies/types';\n\n/**\n * Parses a cookie string into an object with cookie names as keys.\n *\n * @example\n * ```ts\n * parseCookie('theme=dark; token=abc');\n * ```\n */\nexport const parseCookie = (cookiesString = document.cookie) => {\n return cookiesString\n .split(';')\n .map((cookieString) => cookieString.trim().split('='))\n .reduce<AnyObject>((acc, current) => {\n acc[current[0]] = current[1];\n return acc;\n }, {});\n};\n"],"mappings":";;;;;;;;;;AAUA,IAAa,eAAe,gBAAgB,SAAS,WAAW;AAC9D,QAAO,cACJ,MAAM,IAAI,CACV,KAAK,iBAAiB,aAAa,MAAM,CAAC,MAAM,IAAI,CAAC,CACrD,QAAmB,KAAK,YAAY;AACnC,MAAI,QAAQ,MAAM,QAAQ;AAC1B,SAAO;IACN,EAAE,CAAC"}
package/cookie.d.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  import { AnyObject } from 'yummies/types';
2
2
 
3
+ /**
4
+ * Parses a cookie string into an object with cookie names as keys.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * parseCookie('theme=dark; token=abc');
9
+ * ```
10
+ */
3
11
  declare const parseCookie: (cookiesString?: string) => AnyObject;
4
12
 
5
13
  export { parseCookie };
package/cookie.js CHANGED
@@ -1,10 +1,19 @@
1
- const parseCookie = (cookiesString = document.cookie) => {
2
- return cookiesString.split(";").map((cookieString) => cookieString.trim().split("=")).reduce((acc, current) => {
3
- acc[current[0]] = current[1];
4
- return acc;
5
- }, {});
1
+ //#region src/cookie.ts
2
+ /**
3
+ * Parses a cookie string into an object with cookie names as keys.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * parseCookie('theme=dark; token=abc');
8
+ * ```
9
+ */
10
+ var parseCookie = (cookiesString = document.cookie) => {
11
+ return cookiesString.split(";").map((cookieString) => cookieString.trim().split("=")).reduce((acc, current) => {
12
+ acc[current[0]] = current[1];
13
+ return acc;
14
+ }, {});
6
15
  };
7
- export {
8
- parseCookie
9
- };
10
- //# sourceMappingURL=cookie.js.map
16
+ //#endregion
17
+ export { parseCookie };
18
+
19
+ //# sourceMappingURL=cookie.js.map
package/cookie.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cookie.js","sources":["../src/cookie.ts"],"sourcesContent":["import type { AnyObject } from 'yummies/types';\n\nexport const parseCookie = (cookiesString = document.cookie) => {\n return cookiesString\n .split(';')\n .map((cookieString) => cookieString.trim().split('='))\n .reduce<AnyObject>((acc, current) => {\n acc[current[0]] = current[1];\n return acc;\n }, {});\n};\n"],"names":[],"mappings":"AAEO,MAAM,cAAc,CAAC,gBAAgB,SAAS,WAAW;AAC9D,SAAO,cACJ,MAAM,GAAG,EACT,IAAI,CAAC,iBAAiB,aAAa,KAAA,EAAO,MAAM,GAAG,CAAC,EACpD,OAAkB,CAAC,KAAK,YAAY;AACnC,QAAI,QAAQ,CAAC,CAAC,IAAI,QAAQ,CAAC;AAC3B,WAAO;AAAA,EACT,GAAG,CAAA,CAAE;AACT;"}
1
+ {"version":3,"file":"cookie.js","names":[],"sources":["../src/cookie.ts"],"sourcesContent":["import type { AnyObject } from 'yummies/types';\n\n/**\n * Parses a cookie string into an object with cookie names as keys.\n *\n * @example\n * ```ts\n * parseCookie('theme=dark; token=abc');\n * ```\n */\nexport const parseCookie = (cookiesString = document.cookie) => {\n return cookiesString\n .split(';')\n .map((cookieString) => cookieString.trim().split('='))\n .reduce<AnyObject>((acc, current) => {\n acc[current[0]] = current[1];\n return acc;\n }, {});\n};\n"],"mappings":";;;;;;;;;AAUA,IAAa,eAAe,gBAAgB,SAAS,WAAW;AAC9D,QAAO,cACJ,MAAM,IAAI,CACV,KAAK,iBAAiB,aAAa,MAAM,CAAC,MAAM,IAAI,CAAC,CACrD,QAAmB,KAAK,YAAY;AACnC,MAAI,QAAQ,MAAM,QAAQ;AAC1B,SAAO;IACN,EAAE,CAAC"}