@wener/utils 1.1.1 → 1.1.3

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 (182) hide show
  1. package/dist/cjs/index.js +2 -0
  2. package/dist/cjs/index.js.map +1 -0
  3. package/dist/cjs/server.js +2 -0
  4. package/dist/cjs/server.js.map +1 -0
  5. package/dist/esm/index.js +2 -0
  6. package/dist/esm/index.js.map +1 -0
  7. package/dist/esm/server.js +2 -0
  8. package/dist/esm/server.js.map +1 -0
  9. package/dist/system/index.js +2 -0
  10. package/dist/system/index.js.map +1 -0
  11. package/dist/system/server.js +2 -0
  12. package/dist/system/server.js.map +1 -0
  13. package/index.ts +1 -0
  14. package/lib/{esm/arrays → arrays}/MaybeArray.js +3 -6
  15. package/lib/arrays/MaybeArray.js.map +1 -0
  16. package/lib/{esm/asyncs → asyncs}/AsyncInterval.js +4 -5
  17. package/lib/asyncs/AsyncInterval.js.map +1 -0
  18. package/lib/asyncs/LazyPromise.js +27 -0
  19. package/lib/asyncs/LazyPromise.js.map +1 -0
  20. package/lib/{esm/asyncs → asyncs}/isPromise.js +3 -3
  21. package/lib/asyncs/isPromise.js.map +1 -0
  22. package/lib/{esm/asyncs → asyncs}/sleep.js +3 -3
  23. package/lib/asyncs/sleep.js.map +1 -0
  24. package/lib/{esm/asyncs → asyncs}/timeout.js +13 -11
  25. package/lib/asyncs/timeout.js.map +1 -0
  26. package/lib/{esm/browsers → browsers}/copy.js +7 -8
  27. package/lib/browsers/copy.js.map +1 -0
  28. package/lib/{esm/browsers → browsers}/download.js +3 -3
  29. package/lib/browsers/download.js.map +1 -0
  30. package/lib/{esm/browsers → browsers}/getFileFromDataTransfer.js +8 -6
  31. package/lib/browsers/getFileFromDataTransfer.js.map +1 -0
  32. package/lib/{esm/browsers → browsers}/loaders.js +24 -9
  33. package/lib/browsers/loaders.js.map +1 -0
  34. package/lib/crypto/hashing.js +24 -0
  35. package/lib/crypto/hashing.js.map +1 -0
  36. package/lib/crypto/hex.js +6 -0
  37. package/lib/crypto/hex.js.map +1 -0
  38. package/lib/crypto/randomUUID.js +13 -0
  39. package/lib/crypto/randomUUID.js.map +1 -0
  40. package/lib/{esm/formats → formats}/formatBytes.js +3 -3
  41. package/lib/formats/formatBytes.js.map +1 -0
  42. package/lib/index.js +27 -0
  43. package/lib/index.js.map +1 -0
  44. package/lib/{esm/io → io}/isBuffer.js +3 -3
  45. package/lib/io/isBuffer.js.map +1 -0
  46. package/lib/{esm/isomorphics → isomorphics}/getGlobalThis.js +3 -3
  47. package/lib/isomorphics/getGlobalThis.js.map +1 -0
  48. package/lib/{esm/maths → maths}/random.js +3 -3
  49. package/lib/maths/random.js.map +1 -0
  50. package/lib/modules/parseModuleId.js +31 -0
  51. package/lib/modules/parseModuleId.js.map +1 -0
  52. package/lib/server/polyfill.js +8 -0
  53. package/lib/server/polyfill.js.map +1 -0
  54. package/lib/server.js +2 -0
  55. package/lib/server.js.map +1 -0
  56. package/lib/{esm/shim → shim}/urljoin.js +3 -3
  57. package/lib/shim/urljoin.js.map +1 -0
  58. package/lib/{esm/strings → strings}/camelCase.js +3 -4
  59. package/lib/strings/camelCase.js.map +1 -0
  60. package/lib/{esm/strings → strings}/templates.js +3 -3
  61. package/lib/strings/templates.js.map +1 -0
  62. package/lib/validations/dequal.js +95 -0
  63. package/lib/validations/dequal.js.map +1 -0
  64. package/lib/{esm/validations → validations}/isClass.js +3 -3
  65. package/lib/validations/isClass.js.map +1 -0
  66. package/lib/{esm/validations → validations}/isDefined.js +3 -3
  67. package/lib/validations/isDefined.js.map +1 -0
  68. package/lib/{esm/validations → validations}/isEmptyObject.js +3 -3
  69. package/lib/validations/isEmptyObject.js.map +1 -0
  70. package/lib/validations/shallow.js +21 -0
  71. package/lib/validations/shallow.js.map +1 -0
  72. package/package.json +62 -47
  73. package/server.ts +1 -0
  74. package/src/arrays/MaybeArray.ts +8 -4
  75. package/src/browsers/copy.ts +7 -3
  76. package/src/browsers/download.ts +7 -0
  77. package/src/browsers/loaders.ts +32 -7
  78. package/src/crypto/hashing.test.ts +26 -0
  79. package/src/crypto/hashing.ts +27 -0
  80. package/src/crypto/hex.ts +5 -0
  81. package/src/crypto/randomUUID.ts +13 -0
  82. package/src/index.ts +46 -7
  83. package/src/modules/parseModuleId.test.ts +68 -0
  84. package/src/modules/parseModuleId.ts +46 -0
  85. package/src/server/polyfill.ts +5 -0
  86. package/src/server.ts +1 -0
  87. package/src/shim/urljoin.test.ts +3 -2
  88. package/src/types.d.ts +7 -0
  89. package/src/validations/dequal.test.ts +17 -0
  90. package/src/validations/dequal.ts +105 -0
  91. package/src/validations/shallow.ts +26 -0
  92. package/tsconfig.json +5 -9
  93. package/jest.config.js +0 -18
  94. package/jest.setup.js +0 -1
  95. package/lib/cjs/arrays/MaybeArray.js +0 -52
  96. package/lib/cjs/arrays/index.js +0 -17
  97. package/lib/cjs/asyncs/AsyncInterval.js +0 -35
  98. package/lib/cjs/asyncs/LazyPromise.js +0 -43
  99. package/lib/cjs/asyncs/MaybePromise.js +0 -15
  100. package/lib/cjs/asyncs/generatorOfStream.js +0 -35
  101. package/lib/cjs/asyncs/index.js +0 -23
  102. package/lib/cjs/asyncs/isPromise.js +0 -25
  103. package/lib/cjs/asyncs/promiseOfCallback.js +0 -37
  104. package/lib/cjs/asyncs/sleep.js +0 -23
  105. package/lib/cjs/asyncs/timeout.js +0 -44
  106. package/lib/cjs/browsers/copy.js +0 -71
  107. package/lib/cjs/browsers/download.js +0 -47
  108. package/lib/cjs/browsers/getFileFromDataTransfer.js +0 -48
  109. package/lib/cjs/browsers/index.js +0 -20
  110. package/lib/cjs/browsers/loaders.js +0 -54
  111. package/lib/cjs/formats/formatBytes.js +0 -36
  112. package/lib/cjs/index.js +0 -35
  113. package/lib/cjs/io/index.js +0 -17
  114. package/lib/cjs/io/isBuffer.js +0 -25
  115. package/lib/cjs/isomorphics/getGlobalThis.js +0 -33
  116. package/lib/cjs/maths/index.js +0 -17
  117. package/lib/cjs/maths/random.js +0 -36
  118. package/lib/cjs/shim/urljoin.js +0 -70
  119. package/lib/cjs/shim/urljoin.test.js +0 -4
  120. package/lib/cjs/strings/camelCase.js +0 -76
  121. package/lib/cjs/strings/index.js +0 -18
  122. package/lib/cjs/strings/templates.js +0 -27
  123. package/lib/cjs/validations/asserts.js +0 -29
  124. package/lib/cjs/validations/index.js +0 -20
  125. package/lib/cjs/validations/isClass.js +0 -25
  126. package/lib/cjs/validations/isDefined.js +0 -25
  127. package/lib/cjs/validations/isEmptyObject.js +0 -28
  128. package/lib/esm/arrays/MaybeArray.d.ts +0 -5
  129. package/lib/esm/arrays/index.d.ts +0 -1
  130. package/lib/esm/arrays/index.js +0 -1
  131. package/lib/esm/asyncs/AsyncInterval.d.ts +0 -3
  132. package/lib/esm/asyncs/LazyPromise.d.ts +0 -5
  133. package/lib/esm/asyncs/LazyPromise.js +0 -24
  134. package/lib/esm/asyncs/MaybePromise.d.ts +0 -1
  135. package/lib/esm/asyncs/MaybePromise.js +0 -0
  136. package/lib/esm/asyncs/generatorOfStream.d.ts +0 -1
  137. package/lib/esm/asyncs/generatorOfStream.js +0 -16
  138. package/lib/esm/asyncs/index.d.ts +0 -7
  139. package/lib/esm/asyncs/index.js +0 -7
  140. package/lib/esm/asyncs/isPromise.d.ts +0 -1
  141. package/lib/esm/asyncs/promiseOfCallback.d.ts +0 -1
  142. package/lib/esm/asyncs/promiseOfCallback.js +0 -18
  143. package/lib/esm/asyncs/sleep.d.ts +0 -1
  144. package/lib/esm/asyncs/timeout.d.ts +0 -4
  145. package/lib/esm/browsers/copy.d.ts +0 -1
  146. package/lib/esm/browsers/download.d.ts +0 -4
  147. package/lib/esm/browsers/getFileFromDataTransfer.d.ts +0 -4
  148. package/lib/esm/browsers/index.d.ts +0 -4
  149. package/lib/esm/browsers/index.js +0 -4
  150. package/lib/esm/browsers/loaders.d.ts +0 -6
  151. package/lib/esm/formats/formatBytes.d.ts +0 -11
  152. package/lib/esm/index.d.ts +0 -10
  153. package/lib/esm/index.js +0 -15
  154. package/lib/esm/io/index.d.ts +0 -1
  155. package/lib/esm/io/index.js +0 -1
  156. package/lib/esm/io/isBuffer.d.ts +0 -2
  157. package/lib/esm/isomorphics/getGlobalThis.d.ts +0 -9
  158. package/lib/esm/maths/index.d.ts +0 -1
  159. package/lib/esm/maths/index.js +0 -1
  160. package/lib/esm/maths/random.d.ts +0 -3
  161. package/lib/esm/shim/urljoin.d.ts +0 -2
  162. package/lib/esm/shim/urljoin.test.d.ts +0 -1
  163. package/lib/esm/shim/urljoin.test.js +0 -4
  164. package/lib/esm/strings/camelCase.d.ts +0 -4
  165. package/lib/esm/strings/index.d.ts +0 -2
  166. package/lib/esm/strings/index.js +0 -2
  167. package/lib/esm/strings/templates.d.ts +0 -7
  168. package/lib/esm/validations/asserts.d.ts +0 -2
  169. package/lib/esm/validations/asserts.js +0 -10
  170. package/lib/esm/validations/index.d.ts +0 -4
  171. package/lib/esm/validations/index.js +0 -4
  172. package/lib/esm/validations/isClass.d.ts +0 -1
  173. package/lib/esm/validations/isDefined.d.ts +0 -1
  174. package/lib/esm/validations/isEmptyObject.d.ts +0 -1
  175. package/src/arrays/index.ts +0 -1
  176. package/src/asyncs/index.ts +0 -8
  177. package/src/browsers/index.ts +0 -4
  178. package/src/io/index.ts +0 -1
  179. package/src/maths/index.ts +0 -1
  180. package/src/strings/index.ts +0 -2
  181. package/src/validations/index.ts +0 -4
  182. package/tsconfig.jest.json +0 -7
@@ -1,16 +0,0 @@
1
- function* generatorOfStream(stream) {
2
- let done = false;
3
- stream.on("end", () => {
4
- done = true;
5
- });
6
- while (!done) {
7
- yield new Promise((resolve, reject) => {
8
- stream.once("data", resolve);
9
- stream.once("end", resolve);
10
- stream.once("error", reject);
11
- });
12
- }
13
- }
14
- export {
15
- generatorOfStream
16
- };
@@ -1,7 +0,0 @@
1
- export * from './LazyPromise';
2
- export * from './AsyncInterval';
3
- export * from './MaybePromise';
4
- export * from './sleep';
5
- export * from './timeout';
6
- export * from './isPromise';
7
- export * from './promiseOfCallback';
@@ -1,7 +0,0 @@
1
- export * from "./LazyPromise";
2
- export * from "./AsyncInterval";
3
- export * from "./MaybePromise";
4
- export * from "./sleep";
5
- export * from "./timeout";
6
- export * from "./isPromise";
7
- export * from "./promiseOfCallback";
@@ -1 +0,0 @@
1
- export declare function isPromise<T>(v: any): v is Promise<T>;
@@ -1 +0,0 @@
1
- export declare function promiseOfCallback<T>(fun: (cb: (err: any, val?: T) => void) => void): Promise<T>;
@@ -1,18 +0,0 @@
1
- function promiseOfCallback(fun) {
2
- return new Promise((resolve, reject) => {
3
- try {
4
- fun((e, v) => {
5
- if (e) {
6
- reject(e);
7
- } else {
8
- resolve(v);
9
- }
10
- });
11
- } catch (e) {
12
- reject(e);
13
- }
14
- });
15
- }
16
- export {
17
- promiseOfCallback
18
- };
@@ -1 +0,0 @@
1
- export declare const sleep: (ms: number) => Promise<unknown>;
@@ -1,4 +0,0 @@
1
- export declare function timeout<T = any>(v: Promise<T>, ms: number): Promise<T>;
2
- export declare class TimeoutError extends Error {
3
- constructor();
4
- }
@@ -1 +0,0 @@
1
- export declare function copy(text: string): void;
@@ -1,4 +0,0 @@
1
- export declare function download(filename: string, data: any, { type, raw }?: {
2
- type?: string | undefined;
3
- raw?: boolean | undefined;
4
- }): void;
@@ -1,4 +0,0 @@
1
- export declare function getFileFromDataTransfer(dataTransfer?: DataTransfer | null): {
2
- file?: File;
3
- name?: string;
4
- };
@@ -1,4 +0,0 @@
1
- export * from './copy';
2
- export * from './download';
3
- export * from './loaders';
4
- export * from './getFileFromDataTransfer';
@@ -1,4 +0,0 @@
1
- export * from "./copy";
2
- export * from "./download";
3
- export * from "./loaders";
4
- export * from "./getFileFromDataTransfer";
@@ -1,6 +0,0 @@
1
- export declare function loadScripts(src: string, options?: {
2
- attributes: Record<string, string>;
3
- }): Promise<unknown>;
4
- export declare function loadStyles(href: string, options?: {
5
- attributes: Record<string, string>;
6
- }): Promise<unknown>;
@@ -1,11 +0,0 @@
1
- /**
2
- * Format bytes as human-readable text.
3
- *
4
- * @param bytes Number of bytes.
5
- * @param si True to use metric (SI) units, aka powers of 1000. False to use
6
- * binary (IEC), aka powers of 1024.
7
- * @param dp Number of decimal places to display.
8
- *
9
- * @return Formatted string.
10
- */
11
- export declare function formatBytes(bytes: number, si?: boolean, dp?: number): string;
@@ -1,10 +0,0 @@
1
- export * from './arrays/index';
2
- export * from './asyncs';
3
- export * from './validations';
4
- export * from './strings';
5
- export * from './maths';
6
- export * from './io';
7
- export * from './browsers';
8
- export { getGlobalThis } from './isomorphics/getGlobalThis';
9
- export { formatBytes } from './formats/formatBytes';
10
- export { urljoin } from './shim/urljoin';
package/lib/esm/index.js DELETED
@@ -1,15 +0,0 @@
1
- export * from "./arrays/index";
2
- export * from "./asyncs";
3
- export * from "./validations";
4
- export * from "./strings";
5
- export * from "./maths";
6
- export * from "./io";
7
- export * from "./browsers";
8
- import { getGlobalThis } from "./isomorphics/getGlobalThis";
9
- import { formatBytes } from "./formats/formatBytes";
10
- import { urljoin } from "./shim/urljoin";
11
- export {
12
- formatBytes,
13
- getGlobalThis,
14
- urljoin
15
- };
@@ -1 +0,0 @@
1
- export * from './isBuffer';
@@ -1 +0,0 @@
1
- export * from "./isBuffer";
@@ -1,2 +0,0 @@
1
- /// <reference types="node" />
2
- export declare function isBuffer(obj: any): obj is Buffer;
@@ -1,9 +0,0 @@
1
- /**
2
- * isomorphic globalThis
3
- *
4
- * globalThis supported by ff 65, Chrome 71, Node 12, babel
5
- *
6
- * @see https://caniuse.com/#search=globalThis
7
- * @see https://v8.dev/features/globalthis
8
- */
9
- export declare const getGlobalThis: () => typeof globalThis;
@@ -1 +0,0 @@
1
- export * from './random';
@@ -1 +0,0 @@
1
- export * from "./random";
@@ -1,3 +0,0 @@
1
- export declare function createRandom(o?: {
2
- seed?: string | number;
3
- }): () => number;
@@ -1,2 +0,0 @@
1
- export declare function urljoin(...strArray: string[]): string;
2
- export declare function urljoin(strArray: string[]): string;
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- import { urljoin } from "./urljoin";
2
- test("join ext", () => {
3
- expect(urljoin("http://wener.me/sub/", "/a/", "/hello.js")).toBe("http://wener.me/sub/a/hello.js");
4
- });
@@ -1,4 +0,0 @@
1
- export declare function pascalCase(input: string | string[]): string;
2
- export declare function camelCase(input: string | string[], options?: {
3
- pascalCase: boolean;
4
- }): string;
@@ -1,2 +0,0 @@
1
- export * from './camelCase';
2
- export * from './templates';
@@ -1,2 +0,0 @@
1
- export * from "./camelCase";
2
- export * from "./templates";
@@ -1,7 +0,0 @@
1
- /**
2
- * 替换类似于 JS 的模板字符串
3
- *
4
- * @example
5
- * templateString('My name is ${name}',{name:'wener'})
6
- */
7
- export declare function templateString(template: string, getter: (v: string) => any): string;
@@ -1,2 +0,0 @@
1
- export declare function assert(condition: any, msg?: string): asserts condition;
2
- export declare function assertIsDefined<T>(val: T): asserts val is NonNullable<T>;
@@ -1,10 +0,0 @@
1
- function assert(condition, msg) {
2
- console.assert(!condition, msg);
3
- }
4
- function assertIsDefined(val) {
5
- console.assert(val === void 0 || val === null, "Expected defined");
6
- }
7
- export {
8
- assert,
9
- assertIsDefined
10
- };
@@ -1,4 +0,0 @@
1
- export * from './asserts';
2
- export * from './isDefined';
3
- export * from './isEmptyObject';
4
- export * from './isClass';
@@ -1,4 +0,0 @@
1
- export * from "./asserts";
2
- export * from "./isDefined";
3
- export * from "./isEmptyObject";
4
- export * from "./isClass";
@@ -1 +0,0 @@
1
- export declare function isClass(func: any): boolean;
@@ -1 +0,0 @@
1
- export declare function isDefined<T = any>(v: T): v is NonNullable<T>;
@@ -1 +0,0 @@
1
- export declare function isEmptyObject(o: any): boolean;
@@ -1 +0,0 @@
1
- export * from './MaybeArray';
@@ -1,8 +0,0 @@
1
- export * from './LazyPromise';
2
- export * from './AsyncInterval';
3
- export * from './MaybePromise';
4
-
5
- export * from './sleep';
6
- export * from './timeout';
7
- export * from './isPromise';
8
- export * from './promiseOfCallback';
@@ -1,4 +0,0 @@
1
- export * from './copy';
2
- export * from './download';
3
- export * from './loaders';
4
- export * from './getFileFromDataTransfer';
package/src/io/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './isBuffer';
@@ -1 +0,0 @@
1
- export * from './random';
@@ -1,2 +0,0 @@
1
- export * from './camelCase';
2
- export * from './templates';
@@ -1,4 +0,0 @@
1
- export * from './asserts';
2
- export * from './isDefined';
3
- export * from './isEmptyObject';
4
- export * from './isClass';
@@ -1,7 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "sourceMap": true,
4
- "jsx": "react"
5
- },
6
- "extends": "./tsconfig.json"
7
- }