yummies 3.0.11 → 3.0.12
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/README.md +24 -24
- package/complex/modules-factory.d.ts +1 -1
- package/complex/modules-factory.d.ts.map +1 -1
- package/complex/modules-factory.js +2 -6
- package/cookie.d.ts +1 -1
- package/cookie.d.ts.map +1 -1
- package/date-time.d.ts +1 -1
- package/date-time.d.ts.map +1 -1
- package/date-time.js +4 -4
- package/html.d.ts +1 -1
- package/html.d.ts.map +1 -1
- package/html.js +4 -4
- package/imports.js +1 -1
- package/math.d.ts +1 -1
- package/math.d.ts.map +1 -1
- package/math.js +1 -1
- package/media.js +1 -1
- package/package.json +1 -1
- package/price.js +1 -1
- package/storage.d.ts +1 -1
- package/storage.js +8 -8
- package/type-guard.d.ts +1 -1
- package/type-guard.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -15,66 +15,66 @@
|
|
|
15
15
|
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/yummies
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
Yummies -
|
|
18
|
+
Yummies - a set of various utilities for JavaScript projects with open source code, designed to simplify the execution of common tasks and increase performance. This project provides developers with powerful and easy-to-use functions that can be easily integrated into any JavaScript code.
|
|
19
19
|
|
|
20
20
|
## [yummies/async](src/async.ts)
|
|
21
|
-
|
|
21
|
+
Utilities for working with asynchronous code
|
|
22
22
|
|
|
23
23
|
## [yummies/cookie](src/cookie.ts)
|
|
24
|
-
|
|
24
|
+
Utilities for working with cookies
|
|
25
25
|
|
|
26
26
|
## [yummies/css](src/css.ts)
|
|
27
|
-
|
|
27
|
+
Utilities for working with CSS
|
|
28
28
|
|
|
29
29
|
## [yummies/date-time](src/date-time.ts)
|
|
30
|
-
|
|
30
|
+
Utilities for working with dates and times (based on dayjs)
|
|
31
31
|
|
|
32
32
|
## [yummies/device](src/device.ts)
|
|
33
|
-
|
|
33
|
+
Utilities for working with devices
|
|
34
34
|
|
|
35
35
|
## [yummies/html](src/html.ts)
|
|
36
|
-
|
|
36
|
+
Utilities for working with HTML
|
|
37
37
|
|
|
38
38
|
## [yummies/id](src/id.ts)
|
|
39
|
-
|
|
39
|
+
Utilities for working with identifiers
|
|
40
40
|
|
|
41
41
|
## [yummies/imports](src/imports.ts)
|
|
42
|
-
|
|
42
|
+
Utilities for working with module imports
|
|
43
43
|
|
|
44
44
|
## [yummies/math](src/math.ts)
|
|
45
|
-
|
|
45
|
+
Utilities for working with devices
|
|
46
46
|
|
|
47
47
|
## [yummies/media](src/media.ts)
|
|
48
|
-
|
|
48
|
+
Utilities for working with media (image, canvas and blob)
|
|
49
49
|
|
|
50
50
|
## [yummies/ms](src/ms.ts)
|
|
51
|
-
|
|
51
|
+
Utilities for working with milliseconds
|
|
52
52
|
|
|
53
53
|
## [yummies/price](src/price.ts)
|
|
54
|
-
|
|
54
|
+
Utilities for working with monetary values (formatting)
|
|
55
55
|
|
|
56
56
|
## [yummies/sound](src/sound.ts)
|
|
57
|
-
|
|
57
|
+
Utilities for working with sound
|
|
58
58
|
|
|
59
59
|
## [yummies/storage](src/storage.ts)
|
|
60
|
-
|
|
60
|
+
Utilities for working with storage (localStorage, sessionStorage)
|
|
61
61
|
|
|
62
62
|
## [yummies/text](src/text.ts)
|
|
63
|
-
|
|
63
|
+
Utilities for working with text
|
|
64
64
|
|
|
65
65
|
## [yummies/type-guard](src/type-guard.ts)
|
|
66
|
-
|
|
66
|
+
Utility for type checks
|
|
67
67
|
|
|
68
68
|
## [yummies/vibrate](src/vibrate.ts)
|
|
69
|
-
|
|
69
|
+
Utilities for working with vibrate api
|
|
70
70
|
|
|
71
71
|
## [yummies/utility-types](src/utils/types.ts)
|
|
72
|
-
TypeScript
|
|
73
|
-
|
|
72
|
+
TypeScript utility types that simplify writing TypeScript code.
|
|
73
|
+
They can be imported globally using the `d.ts` file, embedding it in the environment
|
|
74
74
|
```ts
|
|
75
75
|
import 'yummies/utility-types';
|
|
76
76
|
```
|
|
77
|
-
|
|
77
|
+
Or specified in `tsconfig.json` in the `"types"` field
|
|
78
78
|
```json
|
|
79
79
|
{
|
|
80
80
|
"compilerOptions": {
|
|
@@ -87,8 +87,8 @@ import 'yummies/utility-types';
|
|
|
87
87
|
...
|
|
88
88
|
}
|
|
89
89
|
```
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
Alternatively, you can use the "library" approach, where you need exported types.
|
|
91
|
+
For this, you can use the `yummies/utils/types` import.
|
|
92
92
|
|
|
93
93
|
```ts
|
|
94
94
|
import { AnyObject } from 'yummies/utils/types';
|
|
@@ -97,4 +97,4 @@ import { AnyObject } from 'yummies/utils/types';
|
|
|
97
97
|
|
|
98
98
|
## [yummies/complex](src/complex/index.ts)
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
Additional set of complex utilities
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AllPropertiesOptional, AnyObject, Class, EmptyObject } from '../utils/types';
|
|
1
|
+
import { AllPropertiesOptional, AnyObject, Class, EmptyObject } from '../utils/types.js';
|
|
2
2
|
type ModuleLoaderConfig<TPredefinedDeps extends AnyObject = EmptyObject> = {
|
|
3
3
|
factory<TInstance, TDeps extends TPredefinedDeps>(moduleClass: Class<TInstance, [TDeps]>, deps: TDeps): TInstance;
|
|
4
4
|
} & (TPredefinedDeps extends EmptyObject ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modules-factory.d.ts","sourceRoot":"","sources":["../../src/complex/modules-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,KAAK,EACL,WAAW,EACZ,MAAM,
|
|
1
|
+
{"version":3,"file":"modules-factory.d.ts","sourceRoot":"","sources":["../../src/complex/modules-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,KAAK,EACL,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B,KAAK,kBAAkB,CAAC,eAAe,SAAS,SAAS,GAAG,WAAW,IAAI;IACzE,OAAO,CAAC,SAAS,EAAE,KAAK,SAAS,eAAe,EAC9C,WAAW,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,EACtC,IAAI,EAAE,KAAK,GACV,SAAS,CAAC;CAEd,GAAG,CAAC,eAAe,SAAS,WAAW,GACpC;IAAE,IAAI,CAAC,EAAE,eAAe,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,CAAC,CAAC;AAE/B;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAc,CAAC,eAAe,SAAS,SAAS,GAAG,WAAW;IAM7D,OAAO,CAAC,MAAM;IAL1B;;;;OAIG;gBACiB,MAAM,EAAE,kBAAkB,CAAC,eAAe,CAAC;IAE/D;;;;;;;;;;OAUG;IACH,MAAM,CAAC,SAAS,EAAE,KAAK,SAAS,eAAe,GAAG,eAAe,EAC/D,WAAW,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,EACtC,GAAG,IAAI,EAAE,qBAAqB,CAC5B,IAAI,CAAC,KAAK,EAAE,MAAM,eAAe,CAAC,CACnC,SAAS,IAAI,GACV,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,eAAe,CAAC,CAAC,GAChD,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,eAAe,CAAC,CAAC;CAOtD"}
|
|
@@ -17,18 +17,14 @@
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
export class ModulesFactory {
|
|
20
|
+
config;
|
|
20
21
|
/**
|
|
21
22
|
* Создает новый экземпляр `ModulesFactory`.
|
|
22
23
|
*
|
|
23
24
|
* @param config - Объект конфигурации для фабрики, включающий функцию фабрики и необязательные зависимости.
|
|
24
25
|
*/
|
|
25
26
|
constructor(config) {
|
|
26
|
-
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true,
|
|
30
|
-
value: config
|
|
31
|
-
});
|
|
27
|
+
this.config = config;
|
|
32
28
|
}
|
|
33
29
|
/**
|
|
34
30
|
* Создает экземпляр указанного класса, внедряя необходимые зависимости.
|
package/cookie.d.ts
CHANGED
package/cookie.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../src/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../src/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,eAAO,MAAM,WAAW,uCAUvB,CAAC"}
|
package/date-time.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dayjs } from 'dayjs';
|
|
2
|
-
import { Maybe } from './utils/types';
|
|
2
|
+
import { Maybe } from './utils/types.js';
|
|
3
3
|
import 'dayjs/locale/ru';
|
|
4
4
|
export declare const formatDate: (value: Maybe<string | number | Dayjs>, settings?: Maybe<{
|
|
5
5
|
format?: "human" | "full" | "short" | "day" | "day-only" | "date" | "month" | "spent-time" | "time" | "time-short";
|
package/date-time.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-time.d.ts","sourceRoot":"","sources":["../src/date-time.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAKrC,OAAO,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"date-time.d.ts","sourceRoot":"","sources":["../src/date-time.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAKrC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,iBAAiB,CAAC;AAwBzB,eAAO,MAAM,UAAU,UACd,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,aAC1B,KAAK,CAAC;IACf,MAAM,CAAC,EACH,OAAO,GACP,MAAM,GACN,OAAO,GACP,KAAK,GACL,UAAU,GACV,MAAM,GACN,OAAO,GACP,YAAY,GACZ,MAAM,GACN,YAAY,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC,WA6CH,CAAC;AAEF,eAAO,MAAM,YAAY,aAAc,MAAM;;;;CAQ5C,CAAC"}
|
package/date-time.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import duration from 'dayjs/plugin/duration';
|
|
3
3
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
4
|
-
import { typeGuard } from './type-guard';
|
|
4
|
+
import { typeGuard } from './type-guard.js';
|
|
5
5
|
import 'dayjs/locale/ru';
|
|
6
6
|
dayjs.extend(relativeTime);
|
|
7
7
|
dayjs.extend(duration);
|
|
@@ -22,9 +22,9 @@ const toLibFormat = function (value, asTime) {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
export const formatDate = function (value, settings) {
|
|
25
|
-
const dateFormat = settings
|
|
26
|
-
const datePattern = settings
|
|
27
|
-
const asTime = settings
|
|
25
|
+
const dateFormat = settings?.format;
|
|
26
|
+
const datePattern = settings?.pattern;
|
|
27
|
+
const asTime = settings?.asTime;
|
|
28
28
|
value = toLibFormat(value, asTime);
|
|
29
29
|
if (typeGuard.isUndefined(value)) {
|
|
30
30
|
return NO_VALUE;
|
package/html.d.ts
CHANGED
package/html.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA,OAAe,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAIjD,OAAO,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA,OAAe,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAIjD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,WAAY,MAAM,KAAG,MAAM,GAAG,IAa1D,CAAC;AAEF,eAAO,MAAM,mBAAmB,cACnB,MAAM,GAAG,IAAI,aACb,MAAM,SAgBlB,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAI7C;AAED,eAAO,MAAM,gBAAgB,YAAa,WAAW,GAAG,IAAI,WAU3D,CAAC;AAEF,eAAO,MAAM,SAAS,MAAO,KAAK,YAKjC,CAAC;AAEF,eAAO,MAAM,wBAAwB,SAAU,WAAW,SAgBzD,CAAC;AA0DF,eAAO,MAAM,YAAY,SACjB,KAAK,CAAC,MAAM,CAAC,WACV,OAAO,CAAC,eAAe,CAAC,WAMlC,CAAC;AAEF,eAAO,MAAM,qBAAqB,YACvB,WAAW,GAAG,IAAI,UACnB,KAAK,CAAC,WAAW,CAAC,YAe3B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,OAChC,YAAY,WACP;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,+BAMhC,CAAC"}
|
package/html.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import insane from 'insane';
|
|
2
2
|
import { clamp } from 'lodash-es';
|
|
3
|
-
import { blobToUrl } from './media';
|
|
3
|
+
import { blobToUrl } from './media.js';
|
|
4
4
|
/**
|
|
5
5
|
* Вытаскивает RGB из любого цвета
|
|
6
6
|
*
|
|
@@ -22,7 +22,7 @@ export const downloadUsingAnchor = (urlOrBlob, fileName) => {
|
|
|
22
22
|
const url = blobToUrl(urlOrBlob);
|
|
23
23
|
const a = document.createElement('a');
|
|
24
24
|
a.href = url;
|
|
25
|
-
a.download = fileName
|
|
25
|
+
a.download = fileName ?? 'file';
|
|
26
26
|
a.target = '_blank';
|
|
27
27
|
document.body.append(a);
|
|
28
28
|
a.click();
|
|
@@ -118,7 +118,7 @@ const sanitizeDefaults = {
|
|
|
118
118
|
transformText: undefined,
|
|
119
119
|
};
|
|
120
120
|
export const sanitizeHtml = (html, config) => {
|
|
121
|
-
return insane(html
|
|
121
|
+
return insane(html ?? '', {
|
|
122
122
|
...sanitizeDefaults,
|
|
123
123
|
...config,
|
|
124
124
|
});
|
|
@@ -146,7 +146,7 @@ export const checkElementHasParent = (element, parent) => {
|
|
|
146
146
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition | MDN: Document.startViewTransition}
|
|
147
147
|
*/
|
|
148
148
|
export const startViewTransitionSafety = (fn, params) => {
|
|
149
|
-
if (document.startViewTransition && !
|
|
149
|
+
if (document.startViewTransition && !params?.disabled) {
|
|
150
150
|
return document.startViewTransition(fn);
|
|
151
151
|
}
|
|
152
152
|
fn();
|
package/imports.js
CHANGED
package/math.d.ts
CHANGED
package/math.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAEnC;AACD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAEnC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,UAAW,KAAK,CAAC,MAAM,CAAC,QAAQ,KAAK,CAAC,MAAM,CAAC,WAEpE,CAAC"}
|
package/math.js
CHANGED
|
@@ -13,5 +13,5 @@ export function radToDeg(rad) {
|
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export const percentFrom = (value, from) => {
|
|
16
|
-
return ((value
|
|
16
|
+
return ((value ?? 0) / (from ?? 0)) * 100 || 0;
|
|
17
17
|
};
|
package/media.js
CHANGED
package/package.json
CHANGED
package/price.js
CHANGED
|
@@ -13,5 +13,5 @@ export const formatPrice = (price, locale, currency, { withoutSymbol, customSymb
|
|
|
13
13
|
if (withoutSymbol) {
|
|
14
14
|
return priceWithoutCurrency;
|
|
15
15
|
}
|
|
16
|
-
return `${priceWithoutCurrency} ${customSymbol
|
|
16
|
+
return `${priceWithoutCurrency} ${customSymbol ?? (currency === 'RUB' ? 'р' : currencySymbol)}`.replace(/\s{2,}/, ' ');
|
|
17
17
|
};
|
package/storage.d.ts
CHANGED
package/storage.js
CHANGED
|
@@ -11,7 +11,7 @@ const parseStorageValue = (value) => {
|
|
|
11
11
|
const parsed = JSON.parse(value);
|
|
12
12
|
return parsed;
|
|
13
13
|
}
|
|
14
|
-
catch
|
|
14
|
+
catch {
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
17
|
};
|
|
@@ -24,20 +24,20 @@ const formatValueToStorage = (value) => {
|
|
|
24
24
|
export function createStorage(storageConfig) {
|
|
25
25
|
return {
|
|
26
26
|
set: (cfg) => {
|
|
27
|
-
var _a, _b;
|
|
28
27
|
const config = cfg;
|
|
29
|
-
const storageType = (
|
|
30
|
-
const storagePrefix = (
|
|
28
|
+
const storageType = (config.type ?? storageConfig.type);
|
|
29
|
+
const storagePrefix = (config.prefix ?? storageConfig.prefix);
|
|
31
30
|
const storage = storages[storageType];
|
|
32
31
|
storage.setItem(createStorageKey(storagePrefix, config.key, config.namespace), formatValueToStorage(config.value));
|
|
33
32
|
},
|
|
34
33
|
get: (cfg) => {
|
|
35
|
-
var _a, _b, _c, _d;
|
|
36
34
|
const config = cfg;
|
|
37
|
-
const storageType = (
|
|
38
|
-
const storagePrefix = (
|
|
35
|
+
const storageType = (config.type ?? storageConfig.type);
|
|
36
|
+
const storagePrefix = (config.prefix ?? storageConfig.prefix);
|
|
39
37
|
const storage = storages[storageType];
|
|
40
|
-
return (
|
|
38
|
+
return (parseStorageValue(storage.getItem(createStorageKey(storagePrefix, config.key, config.namespace))) ??
|
|
39
|
+
config.fallback ??
|
|
40
|
+
null);
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
43
|
}
|
package/type-guard.d.ts
CHANGED
package/type-guard.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guard.d.ts","sourceRoot":"","sources":["../src/type-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"type-guard.d.ts","sourceRoot":"","sources":["../src/type-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA4C1D,eAAO,MAAM,SAAS;oBALZ,OAAO,KAAG,KAAK,QAAK;yBAApB,OAAO,KAAG,KAAK,aAAK;sBAApB,OAAO,KAAG,KAAK,aAAK;qBAApB,OAAO,KAAG,KAAK,aAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;uBAApB,OAAO,KAAG,KAAK,WAAK;wBAApB,OAAO,KAAG,KAAK,eAAK;sBAApB,OAAO,KAAG,KAAK,WAAK;uBAApB,OAAO,KAAG,KAAK,eAAK;mBAApB,OAAO,KAAG,KAAK,UAAK;wBAApB,OAAO,KAAG,KAAK,UAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;gBAGX,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,KAAG,KAAK,IAAI,CAAC;CAiB7D,CAAC"}
|