@cloudcome/utils-core 1.1.1 → 1.2.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 (291) hide show
  1. package/dist/array.cjs +129 -0
  2. package/dist/array.cjs.map +1 -0
  3. package/dist/array.d.ts +171 -0
  4. package/dist/array.mjs +129 -0
  5. package/dist/array.mjs.map +1 -0
  6. package/dist/async.cjs +219 -0
  7. package/dist/async.cjs.map +1 -0
  8. package/dist/async.d.ts +137 -0
  9. package/dist/async.mjs +219 -0
  10. package/dist/async.mjs.map +1 -0
  11. package/dist/base64.cjs +16 -0
  12. package/dist/base64.cjs.map +1 -0
  13. package/dist/base64.d.ts +7 -0
  14. package/dist/base64.mjs +16 -0
  15. package/dist/base64.mjs.map +1 -0
  16. package/dist/cache.cjs +79 -0
  17. package/dist/cache.cjs.map +1 -0
  18. package/dist/cache.d.ts +90 -0
  19. package/dist/cache.mjs +79 -0
  20. package/dist/cache.mjs.map +1 -0
  21. package/{src/color/contrast.ts → dist/color/contrast.d.ts} +2 -12
  22. package/dist/color/distance.d.ts +8 -0
  23. package/dist/color/helpers.d.ts +2 -0
  24. package/dist/color/hex-hsl.d.ts +3 -0
  25. package/{src/color/hex-hsv.ts → dist/color/hex-hsv.d.ts} +3 -11
  26. package/{src/color/hex-hwb.ts → dist/color/hex-hwb.d.ts} +3 -11
  27. package/dist/color/hex-rgb.d.ts +18 -0
  28. package/{src/color/hsl-lighten.ts → dist/color/hsl-lighten.d.ts} +2 -7
  29. package/{src/color/hsv-brighten.ts → dist/color/hsv-brighten.d.ts} +2 -7
  30. package/{src/color/luminance.ts → dist/color/luminance.d.ts} +2 -9
  31. package/{src/color/mix.ts → dist/color/mix.d.ts} +2 -10
  32. package/dist/color/rgb-hsl.d.ts +23 -0
  33. package/{src/color/rgb-hsv.ts → dist/color/rgb-hsv.d.ts} +3 -30
  34. package/dist/color/rgb-hwb.d.ts +29 -0
  35. package/{src/color/rgb-lab.ts → dist/color/rgb-lab.d.ts} +3 -11
  36. package/dist/color/rgb-whiter.d.ts +12 -0
  37. package/dist/color/rgb-xyz.d.ts +22 -0
  38. package/{src/color/types.ts → dist/color/types.d.ts} +30 -12
  39. package/{src/color/xyz-lab.ts → dist/color/xyz-lab.d.ts} +3 -32
  40. package/dist/color.cjs +250 -0
  41. package/dist/color.cjs.map +1 -0
  42. package/dist/color.mjs +250 -0
  43. package/dist/color.mjs.map +1 -0
  44. package/dist/const.cjs +14 -0
  45. package/dist/const.cjs.map +1 -0
  46. package/dist/const.mjs +15 -0
  47. package/dist/const.mjs.map +1 -0
  48. package/dist/core.cjs +250 -0
  49. package/dist/core.cjs.map +1 -0
  50. package/dist/core.mjs +251 -0
  51. package/dist/core.mjs.map +1 -0
  52. package/dist/crypto/md5.d.mts +1 -0
  53. package/dist/crypto/sha1.d.mts +1 -0
  54. package/dist/crypto/sha256.d.mts +1 -0
  55. package/dist/crypto/sha512.d.mts +1 -0
  56. package/dist/crypto.cjs +812 -0
  57. package/dist/crypto.cjs.map +1 -0
  58. package/{src/crypto.ts → dist/crypto.d.ts} +4 -20
  59. package/dist/crypto.mjs +812 -0
  60. package/dist/crypto.mjs.map +1 -0
  61. package/dist/date/const.d.ts +6 -0
  62. package/dist/date/core.d.ts +52 -0
  63. package/dist/date/days.d.ts +23 -0
  64. package/{src/date/is.ts → dist/date/is.d.ts} +8 -102
  65. package/dist/date/relative.d.ts +44 -0
  66. package/dist/date/start-end.d.ts +73 -0
  67. package/dist/date/timezone.d.ts +67 -0
  68. package/dist/date/weeks.d.ts +72 -0
  69. package/dist/date.cjs +239 -0
  70. package/dist/date.cjs.map +1 -0
  71. package/dist/date.mjs +241 -0
  72. package/dist/date.mjs.map +1 -0
  73. package/dist/dict.cjs +2 -0
  74. package/dist/dict.cjs.map +1 -0
  75. package/dist/dict.mjs +2 -0
  76. package/dist/dict.mjs.map +1 -0
  77. package/dist/each.cjs +18 -0
  78. package/dist/each.cjs.map +1 -0
  79. package/dist/each.mjs +19 -0
  80. package/dist/each.mjs.map +1 -0
  81. package/dist/easing.cjs +151 -0
  82. package/dist/easing.cjs.map +1 -0
  83. package/dist/easing.d.ts +46 -0
  84. package/dist/easing.mjs +151 -0
  85. package/dist/easing.mjs.map +1 -0
  86. package/dist/emitter.cjs +94 -0
  87. package/dist/emitter.cjs.map +1 -0
  88. package/dist/emitter.d.ts +68 -0
  89. package/dist/emitter.mjs +94 -0
  90. package/dist/emitter.mjs.map +1 -0
  91. package/dist/enum.cjs +58 -0
  92. package/dist/enum.cjs.map +1 -0
  93. package/dist/enum.d.ts +68 -0
  94. package/dist/enum.mjs +58 -0
  95. package/dist/enum.mjs.map +1 -0
  96. package/dist/env.cjs +28 -0
  97. package/dist/env.cjs.map +1 -0
  98. package/{src/env.ts → dist/env.d.ts} +6 -30
  99. package/dist/env.mjs +28 -0
  100. package/dist/env.mjs.map +1 -0
  101. package/dist/error.cjs +12 -0
  102. package/dist/error.cjs.map +1 -0
  103. package/{src/error.ts → dist/error.d.ts} +3 -12
  104. package/dist/error.mjs +12 -0
  105. package/dist/error.mjs.map +1 -0
  106. package/dist/exception.cjs +22 -0
  107. package/dist/exception.cjs.map +1 -0
  108. package/dist/exception.d.ts +31 -0
  109. package/dist/exception.mjs +22 -0
  110. package/dist/exception.mjs.map +1 -0
  111. package/dist/fn.cjs +76 -0
  112. package/dist/fn.cjs.map +1 -0
  113. package/dist/fn.d.ts +102 -0
  114. package/dist/fn.mjs +76 -0
  115. package/dist/fn.mjs.map +1 -0
  116. package/dist/index.cjs +5 -0
  117. package/dist/index.cjs.map +1 -0
  118. package/dist/index.d.ts +1 -0
  119. package/dist/index.mjs +5 -0
  120. package/dist/index.mjs.map +1 -0
  121. package/dist/merge.cjs +87 -0
  122. package/dist/merge.cjs.map +1 -0
  123. package/dist/merge.mjs +88 -0
  124. package/dist/merge.mjs.map +1 -0
  125. package/dist/number.cjs +14 -0
  126. package/dist/number.cjs.map +1 -0
  127. package/dist/number.d.ts +153 -0
  128. package/dist/number.mjs +14 -0
  129. package/dist/number.mjs.map +1 -0
  130. package/{src/object/each.ts → dist/object/each.d.ts} +3 -23
  131. package/dist/object/get-set.d.ts +111 -0
  132. package/dist/object/is.d.ts +32 -0
  133. package/dist/object/merge.d.ts +72 -0
  134. package/{src/object/process.ts → dist/object/process.d.ts} +4 -38
  135. package/dist/object.cjs +130 -0
  136. package/dist/object.cjs.map +1 -0
  137. package/dist/object.mjs +130 -0
  138. package/dist/object.mjs.map +1 -0
  139. package/dist/path.cjs +77 -0
  140. package/dist/path.cjs.map +1 -0
  141. package/dist/path.d.ts +82 -0
  142. package/dist/path.mjs +77 -0
  143. package/dist/path.mjs.map +1 -0
  144. package/dist/promise.cjs +62 -0
  145. package/dist/promise.cjs.map +1 -0
  146. package/{src/promise.ts → dist/promise.d.ts} +6 -67
  147. package/dist/promise.mjs +62 -0
  148. package/dist/promise.mjs.map +1 -0
  149. package/dist/qs.cjs +47 -0
  150. package/dist/qs.cjs.map +1 -0
  151. package/{src/qs.ts → dist/qs.d.ts} +3 -60
  152. package/dist/qs.mjs +47 -0
  153. package/dist/qs.mjs.map +1 -0
  154. package/dist/regexp.cjs +66 -0
  155. package/dist/regexp.cjs.map +1 -0
  156. package/dist/regexp.d.ts +65 -0
  157. package/dist/regexp.mjs +66 -0
  158. package/dist/regexp.mjs.map +1 -0
  159. package/dist/string.cjs +16 -0
  160. package/dist/string.cjs.map +1 -0
  161. package/dist/string.d.ts +80 -0
  162. package/dist/string.mjs +16 -0
  163. package/dist/string.mjs.map +1 -0
  164. package/dist/string2.cjs +157 -0
  165. package/dist/string2.cjs.map +1 -0
  166. package/dist/string2.mjs +158 -0
  167. package/dist/string2.mjs.map +1 -0
  168. package/dist/time/from.d.ts +14 -0
  169. package/dist/time/to.d.ts +38 -0
  170. package/dist/time.cjs +82 -0
  171. package/dist/time.cjs.map +1 -0
  172. package/dist/time.mjs +82 -0
  173. package/dist/time.mjs.map +1 -0
  174. package/dist/timer.cjs +119 -0
  175. package/dist/timer.cjs.map +1 -0
  176. package/dist/timer.d.ts +96 -0
  177. package/{src/timer.ts → dist/timer.mjs} +17 -124
  178. package/dist/timer.mjs.map +1 -0
  179. package/dist/tree.cjs +125 -0
  180. package/dist/tree.cjs.map +1 -0
  181. package/{src/tree.ts → dist/tree.d.ts} +41 -225
  182. package/dist/tree.mjs +125 -0
  183. package/dist/tree.mjs.map +1 -0
  184. package/dist/type.cjs +78 -0
  185. package/dist/type.cjs.map +1 -0
  186. package/{src/type.ts → dist/type.d.ts} +20 -96
  187. package/dist/type.mjs +78 -0
  188. package/dist/type.mjs.map +1 -0
  189. package/dist/types.cjs +2 -0
  190. package/dist/types.cjs.map +1 -0
  191. package/{src/types.ts → dist/types.d.ts} +12 -33
  192. package/dist/types.mjs +2 -0
  193. package/dist/types.mjs.map +1 -0
  194. package/dist/unique.cjs +46 -0
  195. package/dist/unique.cjs.map +1 -0
  196. package/dist/unique.d.ts +22 -0
  197. package/dist/unique.mjs +46 -0
  198. package/dist/unique.mjs.map +1 -0
  199. package/dist/url.cjs +37 -0
  200. package/dist/url.cjs.map +1 -0
  201. package/dist/url.d.ts +53 -0
  202. package/dist/url.mjs +37 -0
  203. package/dist/url.mjs.map +1 -0
  204. package/dist/version.cjs +33 -0
  205. package/dist/version.cjs.map +1 -0
  206. package/dist/version.d.ts +32 -0
  207. package/dist/version.mjs +33 -0
  208. package/dist/version.mjs.map +1 -0
  209. package/package.json +8 -2
  210. package/CHANGELOG.md +0 -52
  211. package/src/array.ts +0 -312
  212. package/src/async.ts +0 -379
  213. package/src/base64.ts +0 -20
  214. package/src/cache.ts +0 -146
  215. package/src/color/distance.ts +0 -28
  216. package/src/color/helpers.ts +0 -23
  217. package/src/color/hex-hsl.ts +0 -11
  218. package/src/color/hex-rgb.ts +0 -39
  219. package/src/color/rgb-hsl.ts +0 -53
  220. package/src/color/rgb-hwb.ts +0 -56
  221. package/src/color/rgb-whiter.ts +0 -22
  222. package/src/color/rgb-xyz.ts +0 -62
  223. package/src/crypto/md5.mjs +0 -357
  224. package/src/crypto/sha1.mjs +0 -300
  225. package/src/crypto/sha256.mjs +0 -310
  226. package/src/crypto/sha512.mjs +0 -459
  227. package/src/date/const.ts +0 -6
  228. package/src/date/core.ts +0 -162
  229. package/src/date/days.ts +0 -51
  230. package/src/date/relative.ts +0 -92
  231. package/src/date/start-end.ts +0 -246
  232. package/src/date/timezone.ts +0 -220
  233. package/src/date/weeks.ts +0 -100
  234. package/src/dts/global.d.ts +0 -27
  235. package/src/easing.ts +0 -166
  236. package/src/emitter.ts +0 -117
  237. package/src/enum.ts +0 -171
  238. package/src/exception.ts +0 -68
  239. package/src/fn.ts +0 -197
  240. package/src/index.ts +0 -1
  241. package/src/number.ts +0 -236
  242. package/src/object/get-set.ts +0 -273
  243. package/src/object/is.ts +0 -128
  244. package/src/object/merge.ts +0 -180
  245. package/src/path.ts +0 -188
  246. package/src/regexp.ts +0 -156
  247. package/src/string.ts +0 -146
  248. package/src/time/from.ts +0 -57
  249. package/src/time/to.ts +0 -106
  250. package/src/unique.ts +0 -77
  251. package/src/url.ts +0 -93
  252. package/src/version.ts +0 -71
  253. package/test/array.test.ts +0 -332
  254. package/test/async-real.test.ts +0 -39
  255. package/test/async.test.ts +0 -375
  256. package/test/base64.test.ts +0 -32
  257. package/test/cache.test.ts +0 -83
  258. package/test/color.test.ts +0 -163
  259. package/test/crypto.test.ts +0 -34
  260. package/test/date-tz.test.ts +0 -206
  261. package/test/date.test.ts +0 -353
  262. package/test/easing.test.ts +0 -33
  263. package/test/emitter.test.ts +0 -71
  264. package/test/enum.test.ts +0 -113
  265. package/test/env.test.ts +0 -69
  266. package/test/error.test.ts +0 -58
  267. package/test/exception.test.ts +0 -43
  268. package/test/fn.test.ts +0 -263
  269. package/test/helpers.ts +0 -23
  270. package/test/index.test.ts +0 -6
  271. package/test/number.test.ts +0 -213
  272. package/test/object.test.ts +0 -309
  273. package/test/path.test.ts +0 -156
  274. package/test/promise.test.ts +0 -199
  275. package/test/qs.test.ts +0 -79
  276. package/test/regexp.test.ts +0 -97
  277. package/test/string.test.ts +0 -150
  278. package/test/time.test.ts +0 -214
  279. package/test/timer.test.ts +0 -114
  280. package/test/tree.test.ts +0 -348
  281. package/test/type.test.ts +0 -226
  282. package/test/unique.test.ts +0 -71
  283. package/test/url.test.ts +0 -136
  284. package/test/version.test.ts +0 -52
  285. package/tsconfig.json +0 -31
  286. package/vite.config.mts +0 -114
  287. /package/{src/color.ts → dist/color.d.ts} +0 -0
  288. /package/{src/date.ts → dist/date.d.ts} +0 -0
  289. /package/{src/dict.ts → dist/dict.d.ts} +0 -0
  290. /package/{src/object.ts → dist/object.d.ts} +0 -0
  291. /package/{src/time.ts → dist/time.d.ts} +0 -0
@@ -1,459 +0,0 @@
1
- /*
2
- * A JavaScript implementation of the Secure Hash Algorithm, SHA-512, as defined
3
- * in FIPS 180-2
4
- * Version 2.2 Copyright Anonymous Contributor, Paul Johnston 2000 - 2009.
5
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6
- * Distributed under the BSD License
7
- * See http://pajhome.org.uk/crypt/md5 for details.
8
- */
9
-
10
- /*
11
- * Configurable variables. You may need to tweak these to be compatible with
12
- * the server-side, but the defaults work in most cases.
13
- */
14
- var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
15
- var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
16
-
17
- /*
18
- * These are the functions you'll usually want to call
19
- * They take string arguments and return either hex or base-64 encoded strings
20
- */
21
- export function hex_sha512(s) { return rstr2hex(rstr_sha512(str2rstr_utf8(s))); }
22
- function b64_sha512(s) { return rstr2b64(rstr_sha512(str2rstr_utf8(s))); }
23
- function any_sha512(s, e) { return rstr2any(rstr_sha512(str2rstr_utf8(s)), e); }
24
- function hex_hmac_sha512(k, d) { return rstr2hex(rstr_hmac_sha512(str2rstr_utf8(k), str2rstr_utf8(d))); }
25
- function b64_hmac_sha512(k, d) { return rstr2b64(rstr_hmac_sha512(str2rstr_utf8(k), str2rstr_utf8(d))); }
26
- function any_hmac_sha512(k, d, e) { return rstr2any(rstr_hmac_sha512(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
27
-
28
- /*
29
- * Perform a simple self-test to see if the VM is working
30
- */
31
- function sha512_vm_test() {
32
- return hex_sha512("abc").toLowerCase() ==
33
- "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" +
34
- "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
35
- }
36
-
37
- /*
38
- * Calculate the SHA-512 of a raw string
39
- */
40
- function rstr_sha512(s) {
41
- return binb2rstr(binb_sha512(rstr2binb(s), s.length * 8));
42
- }
43
-
44
- /*
45
- * Calculate the HMAC-SHA-512 of a key and some data (raw strings)
46
- */
47
- function rstr_hmac_sha512(key, data) {
48
- var bkey = rstr2binb(key);
49
- if (bkey.length > 32) bkey = binb_sha512(bkey, key.length * 8);
50
-
51
- var ipad = Array(32), opad = Array(32);
52
- for (var i = 0; i < 32; i++) {
53
- ipad[i] = bkey[i] ^ 0x36363636;
54
- opad[i] = bkey[i] ^ 0x5C5C5C5C;
55
- }
56
-
57
- var hash = binb_sha512(ipad.concat(rstr2binb(data)), 1024 + data.length * 8);
58
- return binb2rstr(binb_sha512(opad.concat(hash), 1024 + 512));
59
- }
60
-
61
- /*
62
- * Convert a raw string to a hex string
63
- */
64
- function rstr2hex(input) {
65
- try { hexcase } catch (e) { hexcase = 0; }
66
- var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
67
- var output = "";
68
- var x;
69
- for (var i = 0; i < input.length; i++) {
70
- x = input.charCodeAt(i);
71
- output += hex_tab.charAt((x >>> 4) & 0x0F)
72
- + hex_tab.charAt(x & 0x0F);
73
- }
74
- return output;
75
- }
76
-
77
- /*
78
- * Convert a raw string to a base-64 string
79
- */
80
- function rstr2b64(input) {
81
- try { b64pad } catch (e) { b64pad = ''; }
82
- var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
83
- var output = "";
84
- var len = input.length;
85
- for (var i = 0; i < len; i += 3) {
86
- var triplet = (input.charCodeAt(i) << 16)
87
- | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0)
88
- | (i + 2 < len ? input.charCodeAt(i + 2) : 0);
89
- for (var j = 0; j < 4; j++) {
90
- if (i * 8 + j * 6 > input.length * 8) output += b64pad;
91
- else output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);
92
- }
93
- }
94
- return output;
95
- }
96
-
97
- /*
98
- * Convert a raw string to an arbitrary string encoding
99
- */
100
- function rstr2any(input, encoding) {
101
- var divisor = encoding.length;
102
- var i, j, q, x, quotient;
103
-
104
- /* Convert to an array of 16-bit big-endian values, forming the dividend */
105
- var dividend = Array(Math.ceil(input.length / 2));
106
- for (i = 0; i < dividend.length; i++) {
107
- dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
108
- }
109
-
110
- /*
111
- * Repeatedly perform a long division. The binary array forms the dividend,
112
- * the length of the encoding is the divisor. Once computed, the quotient
113
- * forms the dividend for the next step. All remainders are stored for later
114
- * use.
115
- */
116
- var full_length = Math.ceil(input.length * 8 /
117
- (Math.log(encoding.length) / Math.log(2)));
118
- var remainders = Array(full_length);
119
- for (j = 0; j < full_length; j++) {
120
- quotient = Array();
121
- x = 0;
122
- for (i = 0; i < dividend.length; i++) {
123
- x = (x << 16) + dividend[i];
124
- q = Math.floor(x / divisor);
125
- x -= q * divisor;
126
- if (quotient.length > 0 || q > 0)
127
- quotient[quotient.length] = q;
128
- }
129
- remainders[j] = x;
130
- dividend = quotient;
131
- }
132
-
133
- /* Convert the remainders to the output string */
134
- var output = "";
135
- for (i = remainders.length - 1; i >= 0; i--)
136
- output += encoding.charAt(remainders[i]);
137
-
138
- return output;
139
- }
140
-
141
- /*
142
- * Encode a string as utf-8.
143
- * For efficiency, this assumes the input is valid utf-16.
144
- */
145
- function str2rstr_utf8(input) {
146
- var output = "";
147
- var i = -1;
148
- var x, y;
149
-
150
- while (++i < input.length) {
151
- /* Decode utf-16 surrogate pairs */
152
- x = input.charCodeAt(i);
153
- y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
154
- if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
155
- x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
156
- i++;
157
- }
158
-
159
- /* Encode output as utf-8 */
160
- if (x <= 0x7F)
161
- output += String.fromCharCode(x);
162
- else if (x <= 0x7FF)
163
- output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F),
164
- 0x80 | (x & 0x3F));
165
- else if (x <= 0xFFFF)
166
- output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
167
- 0x80 | ((x >>> 6) & 0x3F),
168
- 0x80 | (x & 0x3F));
169
- else if (x <= 0x1FFFFF)
170
- output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
171
- 0x80 | ((x >>> 12) & 0x3F),
172
- 0x80 | ((x >>> 6) & 0x3F),
173
- 0x80 | (x & 0x3F));
174
- }
175
- return output;
176
- }
177
-
178
- /*
179
- * Encode a string as utf-16
180
- */
181
- function str2rstr_utf16le(input) {
182
- var output = "";
183
- for (var i = 0; i < input.length; i++)
184
- output += String.fromCharCode(input.charCodeAt(i) & 0xFF,
185
- (input.charCodeAt(i) >>> 8) & 0xFF);
186
- return output;
187
- }
188
-
189
- function str2rstr_utf16be(input) {
190
- var output = "";
191
- for (var i = 0; i < input.length; i++)
192
- output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
193
- input.charCodeAt(i) & 0xFF);
194
- return output;
195
- }
196
-
197
- /*
198
- * Convert a raw string to an array of big-endian words
199
- * Characters >255 have their high-byte silently ignored.
200
- */
201
- function rstr2binb(input) {
202
- var output = Array(input.length >> 2);
203
- for (var i = 0; i < output.length; i++)
204
- output[i] = 0;
205
- for (var i = 0; i < input.length * 8; i += 8)
206
- output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
207
- return output;
208
- }
209
-
210
- /*
211
- * Convert an array of big-endian words to a string
212
- */
213
- function binb2rstr(input) {
214
- var output = "";
215
- for (var i = 0; i < input.length * 32; i += 8)
216
- output += String.fromCharCode((input[i >> 5] >>> (24 - i % 32)) & 0xFF);
217
- return output;
218
- }
219
-
220
- /*
221
- * Calculate the SHA-512 of an array of big-endian dwords, and a bit length
222
- */
223
- var sha512_k;
224
- function binb_sha512(x, len) {
225
- if (sha512_k == undefined) {
226
- //SHA512 constants
227
- sha512_k = new Array(
228
- new int64(0x428a2f98, -685199838), new int64(0x71374491, 0x23ef65cd),
229
- new int64(-1245643825, -330482897), new int64(-373957723, -2121671748),
230
- new int64(0x3956c25b, -213338824), new int64(0x59f111f1, -1241133031),
231
- new int64(-1841331548, -1357295717), new int64(-1424204075, -630357736),
232
- new int64(-670586216, -1560083902), new int64(0x12835b01, 0x45706fbe),
233
- new int64(0x243185be, 0x4ee4b28c), new int64(0x550c7dc3, -704662302),
234
- new int64(0x72be5d74, -226784913), new int64(-2132889090, 0x3b1696b1),
235
- new int64(-1680079193, 0x25c71235), new int64(-1046744716, -815192428),
236
- new int64(-459576895, -1628353838), new int64(-272742522, 0x384f25e3),
237
- new int64(0xfc19dc6, -1953704523), new int64(0x240ca1cc, 0x77ac9c65),
238
- new int64(0x2de92c6f, 0x592b0275), new int64(0x4a7484aa, 0x6ea6e483),
239
- new int64(0x5cb0a9dc, -1119749164), new int64(0x76f988da, -2096016459),
240
- new int64(-1740746414, -295247957), new int64(-1473132947, 0x2db43210),
241
- new int64(-1341970488, -1728372417), new int64(-1084653625, -1091629340),
242
- new int64(-958395405, 0x3da88fc2), new int64(-710438585, -1828018395),
243
- new int64(0x6ca6351, -536640913), new int64(0x14292967, 0xa0e6e70),
244
- new int64(0x27b70a85, 0x46d22ffc), new int64(0x2e1b2138, 0x5c26c926),
245
- new int64(0x4d2c6dfc, 0x5ac42aed), new int64(0x53380d13, -1651133473),
246
- new int64(0x650a7354, -1951439906), new int64(0x766a0abb, 0x3c77b2a8),
247
- new int64(-2117940946, 0x47edaee6), new int64(-1838011259, 0x1482353b),
248
- new int64(-1564481375, 0x4cf10364), new int64(-1474664885, -1136513023),
249
- new int64(-1035236496, -789014639), new int64(-949202525, 0x654be30),
250
- new int64(-778901479, -688958952), new int64(-694614492, 0x5565a910),
251
- new int64(-200395387, 0x5771202a), new int64(0x106aa070, 0x32bbd1b8),
252
- new int64(0x19a4c116, -1194143544), new int64(0x1e376c08, 0x5141ab53),
253
- new int64(0x2748774c, -544281703), new int64(0x34b0bcb5, -509917016),
254
- new int64(0x391c0cb3, -976659869), new int64(0x4ed8aa4a, -482243893),
255
- new int64(0x5b9cca4f, 0x7763e373), new int64(0x682e6ff3, -692930397),
256
- new int64(0x748f82ee, 0x5defb2fc), new int64(0x78a5636f, 0x43172f60),
257
- new int64(-2067236844, -1578062990), new int64(-1933114872, 0x1a6439ec),
258
- new int64(-1866530822, 0x23631e28), new int64(-1538233109, -561857047),
259
- new int64(-1090935817, -1295615723), new int64(-965641998, -479046869),
260
- new int64(-903397682, -366583396), new int64(-779700025, 0x21c0c207),
261
- new int64(-354779690, -840897762), new int64(-176337025, -294727304),
262
- new int64(0x6f067aa, 0x72176fba), new int64(0xa637dc5, -1563912026),
263
- new int64(0x113f9804, -1090974290), new int64(0x1b710b35, 0x131c471b),
264
- new int64(0x28db77f5, 0x23047d84), new int64(0x32caab7b, 0x40c72493),
265
- new int64(0x3c9ebe0a, 0x15c9bebc), new int64(0x431d67c4, -1676669620),
266
- new int64(0x4cc5d4be, -885112138), new int64(0x597f299c, -60457430),
267
- new int64(0x5fcb6fab, 0x3ad6faec), new int64(0x6c44198c, 0x4a475817));
268
- }
269
-
270
- //Initial hash values
271
- var H = new Array(
272
- new int64(0x6a09e667, -205731576),
273
- new int64(-1150833019, -2067093701),
274
- new int64(0x3c6ef372, -23791573),
275
- new int64(-1521486534, 0x5f1d36f1),
276
- new int64(0x510e527f, -1377402159),
277
- new int64(-1694144372, 0x2b3e6c1f),
278
- new int64(0x1f83d9ab, -79577749),
279
- new int64(0x5be0cd19, 0x137e2179));
280
-
281
- var T1 = new int64(0, 0),
282
- T2 = new int64(0, 0),
283
- a = new int64(0, 0),
284
- b = new int64(0, 0),
285
- c = new int64(0, 0),
286
- d = new int64(0, 0),
287
- e = new int64(0, 0),
288
- f = new int64(0, 0),
289
- g = new int64(0, 0),
290
- h = new int64(0, 0),
291
- //Temporary variables not specified by the document
292
- s0 = new int64(0, 0),
293
- s1 = new int64(0, 0),
294
- Ch = new int64(0, 0),
295
- Maj = new int64(0, 0),
296
- r1 = new int64(0, 0),
297
- r2 = new int64(0, 0),
298
- r3 = new int64(0, 0);
299
- var j, i;
300
- var W = new Array(80);
301
- for (i = 0; i < 80; i++)
302
- W[i] = new int64(0, 0);
303
-
304
- // append padding to the source string. The format is described in the FIPS.
305
- x[len >> 5] |= 0x80 << (24 - (len & 0x1f));
306
- x[((len + 128 >> 10) << 5) + 31] = len;
307
-
308
- for (i = 0; i < x.length; i += 32) //32 dwords is the block size
309
- {
310
- int64copy(a, H[0]);
311
- int64copy(b, H[1]);
312
- int64copy(c, H[2]);
313
- int64copy(d, H[3]);
314
- int64copy(e, H[4]);
315
- int64copy(f, H[5]);
316
- int64copy(g, H[6]);
317
- int64copy(h, H[7]);
318
-
319
- for (j = 0; j < 16; j++) {
320
- W[j].h = x[i + 2 * j];
321
- W[j].l = x[i + 2 * j + 1];
322
- }
323
-
324
- for (j = 16; j < 80; j++) {
325
- //sigma1
326
- int64rrot(r1, W[j - 2], 19);
327
- int64revrrot(r2, W[j - 2], 29);
328
- int64shr(r3, W[j - 2], 6);
329
- s1.l = r1.l ^ r2.l ^ r3.l;
330
- s1.h = r1.h ^ r2.h ^ r3.h;
331
- //sigma0
332
- int64rrot(r1, W[j - 15], 1);
333
- int64rrot(r2, W[j - 15], 8);
334
- int64shr(r3, W[j - 15], 7);
335
- s0.l = r1.l ^ r2.l ^ r3.l;
336
- s0.h = r1.h ^ r2.h ^ r3.h;
337
-
338
- int64add4(W[j], s1, W[j - 7], s0, W[j - 16]);
339
- }
340
-
341
- for (j = 0; j < 80; j++) {
342
- //Ch
343
- Ch.l = (e.l & f.l) ^ (~e.l & g.l);
344
- Ch.h = (e.h & f.h) ^ (~e.h & g.h);
345
-
346
- //Sigma1
347
- int64rrot(r1, e, 14);
348
- int64rrot(r2, e, 18);
349
- int64revrrot(r3, e, 9);
350
- s1.l = r1.l ^ r2.l ^ r3.l;
351
- s1.h = r1.h ^ r2.h ^ r3.h;
352
-
353
- //Sigma0
354
- int64rrot(r1, a, 28);
355
- int64revrrot(r2, a, 2);
356
- int64revrrot(r3, a, 7);
357
- s0.l = r1.l ^ r2.l ^ r3.l;
358
- s0.h = r1.h ^ r2.h ^ r3.h;
359
-
360
- //Maj
361
- Maj.l = (a.l & b.l) ^ (a.l & c.l) ^ (b.l & c.l);
362
- Maj.h = (a.h & b.h) ^ (a.h & c.h) ^ (b.h & c.h);
363
-
364
- int64add5(T1, h, s1, Ch, sha512_k[j], W[j]);
365
- int64add(T2, s0, Maj);
366
-
367
- int64copy(h, g);
368
- int64copy(g, f);
369
- int64copy(f, e);
370
- int64add(e, d, T1);
371
- int64copy(d, c);
372
- int64copy(c, b);
373
- int64copy(b, a);
374
- int64add(a, T1, T2);
375
- }
376
- int64add(H[0], H[0], a);
377
- int64add(H[1], H[1], b);
378
- int64add(H[2], H[2], c);
379
- int64add(H[3], H[3], d);
380
- int64add(H[4], H[4], e);
381
- int64add(H[5], H[5], f);
382
- int64add(H[6], H[6], g);
383
- int64add(H[7], H[7], h);
384
- }
385
-
386
- //represent the hash as an array of 32-bit dwords
387
- var hash = new Array(16);
388
- for (i = 0; i < 8; i++) {
389
- hash[2 * i] = H[i].h;
390
- hash[2 * i + 1] = H[i].l;
391
- }
392
- return hash;
393
- }
394
-
395
- //A constructor for 64-bit numbers
396
- function int64(h, l) {
397
- this.h = h;
398
- this.l = l;
399
- //this.toString = int64toString;
400
- }
401
-
402
- //Copies src into dst, assuming both are 64-bit numbers
403
- function int64copy(dst, src) {
404
- dst.h = src.h;
405
- dst.l = src.l;
406
- }
407
-
408
- //Right-rotates a 64-bit number by shift
409
- //Won't handle cases of shift>=32
410
- //The function revrrot() is for that
411
- function int64rrot(dst, x, shift) {
412
- dst.l = (x.l >>> shift) | (x.h << (32 - shift));
413
- dst.h = (x.h >>> shift) | (x.l << (32 - shift));
414
- }
415
-
416
- //Reverses the dwords of the source and then rotates right by shift.
417
- //This is equivalent to rotation by 32+shift
418
- function int64revrrot(dst, x, shift) {
419
- dst.l = (x.h >>> shift) | (x.l << (32 - shift));
420
- dst.h = (x.l >>> shift) | (x.h << (32 - shift));
421
- }
422
-
423
- //Bitwise-shifts right a 64-bit number by shift
424
- //Won't handle shift>=32, but it's never needed in SHA512
425
- function int64shr(dst, x, shift) {
426
- dst.l = (x.l >>> shift) | (x.h << (32 - shift));
427
- dst.h = (x.h >>> shift);
428
- }
429
-
430
- //Adds two 64-bit numbers
431
- //Like the original implementation, does not rely on 32-bit operations
432
- function int64add(dst, x, y) {
433
- var w0 = (x.l & 0xffff) + (y.l & 0xffff);
434
- var w1 = (x.l >>> 16) + (y.l >>> 16) + (w0 >>> 16);
435
- var w2 = (x.h & 0xffff) + (y.h & 0xffff) + (w1 >>> 16);
436
- var w3 = (x.h >>> 16) + (y.h >>> 16) + (w2 >>> 16);
437
- dst.l = (w0 & 0xffff) | (w1 << 16);
438
- dst.h = (w2 & 0xffff) | (w3 << 16);
439
- }
440
-
441
- //Same, except with 4 addends. Works faster than adding them one by one.
442
- function int64add4(dst, a, b, c, d) {
443
- var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff);
444
- var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (w0 >>> 16);
445
- var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (w1 >>> 16);
446
- var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (w2 >>> 16);
447
- dst.l = (w0 & 0xffff) | (w1 << 16);
448
- dst.h = (w2 & 0xffff) | (w3 << 16);
449
- }
450
-
451
- //Same, except with 5 addends
452
- function int64add5(dst, a, b, c, d, e) {
453
- var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff) + (e.l & 0xffff);
454
- var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (e.l >>> 16) + (w0 >>> 16);
455
- var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (e.h & 0xffff) + (w1 >>> 16);
456
- var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (e.h >>> 16) + (w2 >>> 16);
457
- dst.l = (w0 & 0xffff) | (w1 << 16);
458
- dst.h = (w2 & 0xffff) | (w3 << 16);
459
- }
package/src/date/const.ts DELETED
@@ -1,6 +0,0 @@
1
- export const DATE_SECOND_MS = 1000;
2
- export const DATE_MINUTE_MS = 60 * DATE_SECOND_MS;
3
- export const DATE_HOUR_MS = 60 * DATE_MINUTE_MS;
4
- export const DATE_DAY_MS = 24 * DATE_HOUR_MS;
5
- export const DATE_MONTH_MS = 30 * DATE_DAY_MS;
6
- export const DATE_YEAR_MS = 365 * DATE_DAY_MS;
package/src/date/core.ts DELETED
@@ -1,162 +0,0 @@
1
- import { objectEach } from '@/object';
2
- import { isDate, isString } from '@/type';
3
- import { TzDate } from './timezone';
4
-
5
- /**
6
- * 判断一个值是否为有效的日期对象
7
- * @param unknown - 需要判断的值
8
- * @returns 如果值是有效的日期对象则返回 true,否则返回 false
9
- * @example
10
- * ```typescript
11
- * isValidDate(new Date()); // true
12
- * isValidDate('2023-01-01'); // false
13
- * isValidDate(NaN); // false
14
- * ```
15
- */
16
- export function isValidDate(unknown: unknown): unknown is Date | TzDate {
17
- return (
18
- (unknown instanceof Date && !Number.isNaN(unknown.getTime())) ||
19
- (unknown instanceof TzDate && !Number.isNaN(unknown.getTime()))
20
- );
21
- }
22
-
23
- export type TDateLike = Date | TzDate;
24
- export type TDateValue = number | string | TDateLike;
25
-
26
- function _guessDateSeparator(value: TDateValue): Date | undefined {
27
- if (!isString(value)) return;
28
-
29
- const value2 = value.replace(/-/g, '/');
30
-
31
- return new Date(value2);
32
- }
33
-
34
- function _guessDateTimezone(value: TDateValue): Date | undefined {
35
- if (!isString(value)) return;
36
-
37
- const re = /([+-])(\d\d)(\d\d)$/;
38
-
39
- const matches = re.exec(value);
40
-
41
- if (!matches) return;
42
-
43
- const value2 = value.replace(re, 'Z');
44
- const d = new Date(value2);
45
-
46
- if (!isValidDate(d)) return;
47
-
48
- const [, flag, hours, minutes] = matches;
49
- const hours2 = Number.parseInt(hours, 10);
50
- const minutes2 = Number.parseInt(minutes, 10);
51
- const offset = (a: number, b: number): number => (flag === '+' ? a - b : a + b);
52
-
53
- d.setHours(offset(d.getHours(), hours2));
54
- d.setMinutes(offset(d.getMinutes(), minutes2));
55
-
56
- return d;
57
- }
58
-
59
- /**
60
- * 解析为Date对象
61
- * @param dateValue - 可以是数值、字符串或 Date 对象
62
- * @returns 解析后的 Date 对象
63
- * @throws {SyntaxError} 如果无法解析为有效的日期对象,则抛出错误
64
- * @example
65
- * ```typescript
66
- * dateParse('2023-01-01'); // Date对象
67
- * dateParse(1672531200000); // Date对象
68
- * dateParse(new Date()); // Date对象
69
- * dateParse('invalid date'); // 抛出 SyntaxError
70
- * ```
71
- */
72
- export function dateParse(dateValue: TDateValue): TDateLike {
73
- // 传入的 Date 对象有 Date、TzDate
74
- // @ts-ignore
75
- const d1 = isDate(dateValue)
76
- ? new Date(dateValue)
77
- : dateValue instanceof TzDate
78
- ? new TzDate(dateValue)
79
- : new Date(dateValue);
80
- if (isValidDate(d1)) return d1;
81
-
82
- // safari 浏览器的日期解析有问题
83
- // new Date('2020-06-26 18:06:15') 返回值是一个非法日期对象
84
- const d2 = _guessDateSeparator(dateValue);
85
- if (isValidDate(d2)) return d2;
86
-
87
- // safari 浏览器的日期解析有问题
88
- // new Date('2020-06-26T18:06:15.000+0800') 返回值是一个非法日期对象
89
- const d3 = _guessDateTimezone(dateValue);
90
- if (isValidDate(d3)) return d3;
91
-
92
- throw new SyntaxError(`${dateValue.toString()} 不是一个合法的日期值`);
93
- }
94
-
95
- function _pad(num: number, len = 2) {
96
- return `${num}`.padStart(len, '0');
97
- }
98
-
99
- const rules: [RegExp, (date: TDateLike) => number | string][] = [
100
- [/Y{4}/gi, (date) => date.getFullYear()],
101
- [/Y{2}/gi, (date) => date.getFullYear() % 100],
102
- [/M{2}/g, (date) => _pad(date.getMonth() + 1)],
103
- [/M{1}/g, (date) => date.getMonth() + 1],
104
- [/D{2}/gi, (date) => _pad(date.getDate())],
105
- [/D{1}/gi, (date) => date.getDate()],
106
- [/H{2}/g, (date) => _pad(date.getHours())],
107
- [/H{1}/g, (date) => date.getHours()],
108
- [
109
- /h{2}/g,
110
- (date) => {
111
- const h = date.getHours();
112
- return _pad(h > 12 ? h - 12 : h);
113
- },
114
- ],
115
- [
116
- /h{1}/g,
117
- (date) => {
118
- const h = date.getHours();
119
- return h > 12 ? h - 12 : h;
120
- },
121
- ],
122
- [/m{2}/g, (date) => _pad(date.getMinutes())],
123
- [/m{1}/g, (date) => date.getMinutes()],
124
- [/s{2}/g, (date) => _pad(date.getSeconds())],
125
- [/s{1}/g, (date) => date.getSeconds()],
126
- [/S{3}/g, (date) => _pad(date.getMilliseconds(), 3)],
127
- [/S{2}/g, (date) => _pad(date.getMilliseconds(), 2)],
128
- [/S{1}/g, (date) => date.getMilliseconds()],
129
- ];
130
-
131
- /**
132
- * 格式化为日期字符串(带自定义格式化模板)
133
- * @param dateValue - 可以是数值、字符串或 Date 对象
134
- * @param format - 模板,默认是 'YYYY-MM-DD HH:mm:ss',模板字符:
135
- * - YYYY:年
136
- * - yyyy: 年
137
- * - MM:月
138
- * - DD:日
139
- * - dd: 日
140
- * - HH:时(24 小时制)
141
- * - hh:时(12 小时制)
142
- * - mm:分
143
- * - ss:秒
144
- * - SSS:毫秒
145
- * @returns 格式化后的日期字符串
146
- * @example
147
- * ```typescript
148
- * dateFormat(new Date(), 'YYYY-MM-DD'); // '2023-01-01'
149
- * dateFormat(1672531200000, 'YYYY/MM/DD HH:mm:ss'); // '2023/01/01 00:00:00'
150
- * dateFormat('2023-01-01', 'YYYY年MM月DD日'); // '2023年01月01日'
151
- * ```
152
- */
153
- export function dateFormat(dateValue: TDateValue, format = 'YYYY-MM-DD HH:mm:ss'): string {
154
- const date = dateParse(dateValue);
155
- let result = format;
156
-
157
- for (const rule of rules) {
158
- result = result.replace(rule[0], String(rule[1](date)));
159
- }
160
-
161
- return result;
162
- }
package/src/date/days.ts DELETED
@@ -1,51 +0,0 @@
1
- import { DATE_DAY_MS } from './const';
2
- import { type TDateValue, dateParse } from './core';
3
- import { dateEndInMonth, dateEndInYear, dateStartInMonth, dateStartInYear } from './start-end';
4
-
5
- /**
6
- * 计算指定日期所在年或月的天数
7
- * @param dateValue - 可以是数值、字符串或 Date 对象
8
- * @param unit - 时间单位符号,可选值为 'Y'(年)、'M'(月),默认为 'M'
9
- * @returns 返回指定日期所在年或月的天数
10
- * @example
11
- * ```typescript
12
- * dateDays(new Date('2023-02-15')); // 28
13
- * dateDays(new Date('2024-02-15')); // 29 (闰年)
14
- * dateDays(new Date('2023-02-15'), 'Y'); // 365
15
- * dateDays(new Date('2024-02-15'), 'Y'); // 366 (闰年)
16
- * ```
17
- */
18
- function _dateDays(dateValue: TDateValue, unit: 'Y' | 'M') {
19
- const d = dateParse(dateValue);
20
- const ds = unit === 'M' ? dateStartInMonth(d) : dateStartInYear(d);
21
- const de = unit === 'M' ? dateEndInMonth(d) : dateEndInYear(d);
22
- return Math.ceil((de.getTime() - ds.getTime()) / DATE_DAY_MS);
23
- }
24
-
25
- /**
26
- * 计算指定日期所在月份的天数
27
- * @param dateValue - 可以是数值、字符串或 Date 对象
28
- * @returns 返回指定日期所在月份的天数
29
- * @example
30
- * ```typescript
31
- * dateDaysInMonth(new Date('2023-02-15')); // 28
32
- * dateDaysInMonth(new Date('2024-02-15')); // 29 (闰年)
33
- * ```
34
- */
35
- export function dateDaysInMonth(dateValue: TDateValue) {
36
- return _dateDays(dateValue, 'M');
37
- }
38
-
39
- /**
40
- * 计算指定日期所在年份的天数
41
- * @param dateValue - 可以是数值、字符串或 Date 对象
42
- * @returns 返回指定日期所在年份的天数
43
- * @example
44
- * ```typescript
45
- * dateDaysInYear(new Date('2023-02-15')); // 365
46
- * dateDaysInYear(new Date('2024-02-15')); // 366 (闰年)
47
- * ```
48
- */
49
- export function dateDaysInYear(dateValue: TDateValue) {
50
- return _dateDays(dateValue, 'Y');
51
- }