yummies 3.0.38 → 3.0.40

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/async.d.ts CHANGED
@@ -23,4 +23,6 @@ export declare const waitAsync: (ms?: number) => Promise<unknown>;
23
23
  * @returns void
24
24
  */
25
25
  export declare const endlessRAF: (quitFunction: () => boolean | void, asMicrotask?: boolean) => void;
26
+ export declare function setAbortableTimeout(callback: VoidFunction, delayInMs?: number, signal?: AbortSignal): void;
27
+ export declare function setAbortableInterval(callback: VoidFunction, delayInMs?: number, signal?: AbortSignal): void;
26
28
  //# sourceMappingURL=async.d.ts.map
package/async.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,KAAK,UAAU,MAAM,qBACmB,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,mCAC6B,CAAC;AAEpD;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,iBACP,MAAM,OAAO,GAAG,IAAI,gBACpB,OAAO,SAYtB,CAAC"}
1
+ {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,KAAK,UAAU,MAAM,qBACmB,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,mCAC6B,CAAC;AAEpD;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,iBACP,MAAM,OAAO,GAAG,IAAI,gBACpB,OAAO,SAYtB,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,YAAY,EACtB,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,QAkBrB;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,YAAY,EACtB,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,QAkBrB"}
package/async.js CHANGED
@@ -34,3 +34,33 @@ export const endlessRAF = (quitFunction, asMicrotask) => {
34
34
  raf();
35
35
  }
36
36
  };
37
+ export function setAbortableTimeout(callback, delayInMs, signal) {
38
+ let internalTimer = null;
39
+ const handleAbort = () => {
40
+ if (internalTimer == null) {
41
+ return;
42
+ }
43
+ clearTimeout(internalTimer);
44
+ internalTimer = null;
45
+ };
46
+ signal?.addEventListener('abort', handleAbort, { once: true });
47
+ internalTimer = setTimeout(() => {
48
+ signal?.removeEventListener('abort', handleAbort);
49
+ callback();
50
+ }, delayInMs);
51
+ }
52
+ export function setAbortableInterval(callback, delayInMs, signal) {
53
+ let timer = null;
54
+ const handleAbort = () => {
55
+ if (timer == null) {
56
+ return;
57
+ }
58
+ clearInterval(timer);
59
+ timer = null;
60
+ };
61
+ signal?.addEventListener('abort', handleAbort, { once: true });
62
+ timer = setInterval(() => {
63
+ signal?.removeEventListener('abort', handleAbort);
64
+ callback();
65
+ }, delayInMs);
66
+ }
package/media.d.ts CHANGED
@@ -9,4 +9,12 @@ export declare const imageToBlob: (imageElement: HTMLImageElement, mimeType?: st
9
9
  */
10
10
  export declare const renderImage: (urlOrBlob: Blob | string) => Promise<HTMLImageElement>;
11
11
  export declare const rotateImage: (image: HTMLImageElement, angle: number) => Promise<HTMLImageElement>;
12
+ interface DecodedDataUrl {
13
+ mimeType?: string;
14
+ data?: string;
15
+ }
16
+ export declare function decodeDataUrl(url: string): DecodedDataUrl;
17
+ export declare const isHttpUrl: (url: string) => boolean;
18
+ export declare const isBase64Image: (str: string) => boolean;
19
+ export {};
12
20
  //# sourceMappingURL=media.d.ts.map
package/media.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAGA,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAOxD;AAED,eAAO,MAAM,SAAS,cAAe,MAAM,GAAG,IAAI,WACsB,CAAC;AAEzE,eAAO,MAAM,UAAU,SAAU,IAAI,SAEpC,CAAC;AAEF,eAAO,MAAM,WAAW,iBACR,gBAAgB,aACpB,MAAM,SAyBjB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,cAAe,IAAI,GAAG,MAAM,8BAMhD,CAAC;AAwCL,eAAO,MAAM,WAAW,UAAW,gBAAgB,SAAS,MAAM,8BAajE,CAAC"}
1
+ {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAGA,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAOxD;AAED,eAAO,MAAM,SAAS,cAAe,MAAM,GAAG,IAAI,WACsB,CAAC;AAEzE,eAAO,MAAM,UAAU,SAAU,IAAI,SAEpC,CAAC;AAEF,eAAO,MAAM,WAAW,iBACR,gBAAgB,aACpB,MAAM,SAyBjB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,cAAe,IAAI,GAAG,MAAM,8BAMhD,CAAC;AAwCL,eAAO,MAAM,WAAW,UAAW,gBAAgB,SAAS,MAAM,8BAajE,CAAC;AAEF,UAAU,cAAc;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAKD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAQzD;AAED,eAAO,MAAM,SAAS,QAAS,MAAM,KAAG,OAEvC,CAAC;AAEF,eAAO,MAAM,aAAa,QAAS,MAAM,KAAG,OAG3C,CAAC"}
package/media.js CHANGED
@@ -89,3 +89,21 @@ export const rotateImage = (image, angle) => {
89
89
  cropImageFromCanvas(context);
90
90
  return renderImage(canvas.toDataURL('image/png'));
91
91
  };
92
+ /*
93
+ * Returning object which contains base64 data and mime type of passed data url string.
94
+ * */
95
+ export function decodeDataUrl(url) {
96
+ const regex = /^data:(.*);base64,\s?(.*)$/;
97
+ const matches = new RegExp(regex).exec(url);
98
+ return {
99
+ mimeType: matches?.[1],
100
+ data: matches?.[2],
101
+ };
102
+ }
103
+ export const isHttpUrl = (url) => {
104
+ return url.startsWith('https://') || url.startsWith('http://');
105
+ };
106
+ export const isBase64Image = (str) => {
107
+ const { mimeType, data } = decodeDataUrl(str);
108
+ return !!(data && mimeType?.startsWith('image/'));
109
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yummies",
3
- "version": "3.0.38",
3
+ "version": "3.0.40",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",
@@ -143,6 +143,11 @@
143
143
  "default": "./price.js",
144
144
  "types": "./price.d.ts"
145
145
  },
146
+ "./random": {
147
+ "import": "./random.js",
148
+ "default": "./random.js",
149
+ "types": "./random.d.ts"
150
+ },
146
151
  "./sound": {
147
152
  "import": "./sound.js",
148
153
  "default": "./sound.js",
package/random.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export declare const getRandomFloat: <T extends number = number>(min?: number, max?: number) => T;
2
+ export declare const getRandomInt: <T extends number = number>(min?: number, max?: number) => T;
3
+ export declare const getRandomChoice: <T>(arr: T[]) => T;
4
+ export declare const getRandomSizeArray: (min?: number, max?: number) => unknown[];
5
+ export declare const getRandomBool: () => boolean;
6
+ export declare const getMajorRandomBool: () => boolean;
7
+ export declare const getMinorRandomBool: () => boolean;
8
+ export declare const getFrequencyValue: (frequency: number) => boolean;
9
+ //# sourceMappingURL=random.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,0CAG5C,CAA6C,CAAC;AAEjD,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,0CAA8B,CACH,CAAC;AAEzE,eAAO,MAAM,eAAe,GAAI,CAAC,OAAO,CAAC,EAAE,KAAG,CACR,CAAC;AAEvC,eAAO,MAAM,kBAAkB,2CAC4B,CAAC;AAE5D,eAAO,MAAM,aAAa,eAAiC,CAAC;AAE5D,eAAO,MAAM,kBAAkB,eAE9B,CAAC;AAEF,eAAO,MAAM,kBAAkB,eAE9B,CAAC;AAEF,eAAO,MAAM,iBAAiB,cAAe,MAAM,YAElD,CAAC"}
package/random.js ADDED
@@ -0,0 +1,15 @@
1
+ /* eslint-disable sonarjs/pseudo-random */
2
+ export const getRandomFloat = (min = 0, max = 1) => (Math.random() * (max - min) + min);
3
+ export const getRandomInt = (min = 0, max = 1) => min === max ? min : Math.round(getRandomFloat(min, max));
4
+ export const getRandomChoice = (arr) => arr[getRandomInt(0, arr.length - 1)];
5
+ export const getRandomSizeArray = (min = 0, max = 10) => Array.from({ length: getRandomInt(min, max) }).fill(null);
6
+ export const getRandomBool = () => getRandomInt(0, 1) === 1;
7
+ export const getMajorRandomBool = () => {
8
+ return getRandomInt(0, 10) <= 6;
9
+ };
10
+ export const getMinorRandomBool = () => {
11
+ return !getMajorRandomBool();
12
+ };
13
+ export const getFrequencyValue = (frequency) => {
14
+ return Math.random() < frequency;
15
+ };