@koine/utils 2.0.0-beta.2 → 2.0.0-beta.4

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 (283) hide show
  1. package/Defer.js +23 -18
  2. package/Defer.mjs +6 -5
  3. package/Emitter.js +31 -20
  4. package/Emitter.mjs +13 -16
  5. package/README.md +5 -1
  6. package/accentSets.js +129 -37
  7. package/accentSets.mjs +113 -29
  8. package/addOrReplaceAtIdx.js +27 -10
  9. package/addOrReplaceAtIdx.mjs +9 -6
  10. package/areEqual.js +35 -41
  11. package/areEqual.mjs +16 -22
  12. package/arrayOfAll.js +20 -11
  13. package/arrayOfAll.mjs +1 -6
  14. package/arraySum.js +20 -9
  15. package/arraySum.mjs +1 -4
  16. package/arrayToLookup.js +21 -9
  17. package/arrayToLookup.mjs +2 -4
  18. package/buildUrlQueryString.js +32 -29
  19. package/buildUrlQueryString.mjs +11 -14
  20. package/capitalize.js +21 -9
  21. package/capitalize.mjs +3 -5
  22. package/changeUrlPath.js +23 -17
  23. package/changeUrlPath.mjs +2 -3
  24. package/chunkByChunks.js +35 -24
  25. package/chunkByChunks.mjs +17 -20
  26. package/chunkBySize.js +21 -8
  27. package/chunkBySize.mjs +3 -4
  28. package/clamp.js +19 -6
  29. package/clamp.mjs +1 -2
  30. package/clsx.js +29 -23
  31. package/clsx.mjs +11 -14
  32. package/convertRange.js +20 -7
  33. package/convertRange.mjs +2 -3
  34. package/cookie.js +13 -5
  35. package/cookie.mjs +3 -2
  36. package/createPalette.js +27 -19
  37. package/createPalette.mjs +9 -6
  38. package/debounce.js +27 -21
  39. package/debounce.mjs +9 -17
  40. package/debouncePromise.js +20 -11
  41. package/debouncePromise.mjs +1 -2
  42. package/debounceRaf.js +23 -14
  43. package/debounceRaf.mjs +5 -10
  44. package/decode.js +20 -7
  45. package/decode.mjs +2 -3
  46. package/encode.js +20 -7
  47. package/encode.mjs +2 -3
  48. package/ensureInt.js +20 -9
  49. package/ensureInt.mjs +1 -4
  50. package/env.js +1 -1
  51. package/env.mjs +0 -1
  52. package/errorToString.js +21 -14
  53. package/errorToString.mjs +1 -4
  54. package/findDuplicatedIndexes.js +22 -9
  55. package/findDuplicatedIndexes.mjs +4 -5
  56. package/forin.js +20 -7
  57. package/forin.mjs +2 -3
  58. package/gbToBytes.js +20 -7
  59. package/gbToBytes.mjs +1 -2
  60. package/getEmptyArray.js +25 -16
  61. package/getEmptyArray.mjs +4 -3
  62. package/getKeys.js +20 -6
  63. package/getKeys.mjs +1 -2
  64. package/getMediaQueryWidthResolvers.js +62 -53
  65. package/getMediaQueryWidthResolvers.mjs +44 -49
  66. package/getMediaQueryWidthTailwindScreens.js +36 -18
  67. package/getMediaQueryWidthTailwindScreens.mjs +18 -14
  68. package/getNonce.js +20 -10
  69. package/getNonce.mjs +1 -2
  70. package/getParamAmong.js +22 -19
  71. package/getParamAmong.mjs +2 -4
  72. package/getParamAsInt.js +22 -19
  73. package/getParamAsInt.mjs +2 -4
  74. package/getParamAsString.js +21 -16
  75. package/getParamAsString.mjs +1 -2
  76. package/getType.js +19 -12
  77. package/getType.mjs +2 -4
  78. package/getUrlHashParams.js +20 -13
  79. package/getUrlHashParams.mjs +2 -4
  80. package/getUrlHashPathname.js +20 -8
  81. package/getUrlHashPathname.mjs +1 -3
  82. package/getUrlPathnameParts.js +23 -23
  83. package/getUrlPathnameParts.mjs +2 -7
  84. package/getUrlQueryParams.js +26 -33
  85. package/getUrlQueryParams.mjs +7 -18
  86. package/imgEmptyPixel.js +20 -6
  87. package/imgEmptyPixel.mjs +1 -2
  88. package/index.js +531 -266
  89. package/index.mjs +2 -2
  90. package/invariant.js +24 -12
  91. package/invariant.mjs +6 -8
  92. package/isAnyObject.js +21 -12
  93. package/isAnyObject.mjs +1 -2
  94. package/isArray.js +21 -12
  95. package/isArray.mjs +1 -2
  96. package/isBlob.js +21 -12
  97. package/isBlob.mjs +1 -2
  98. package/isBoolean.js +21 -12
  99. package/isBoolean.mjs +1 -2
  100. package/isBrowser.js +20 -6
  101. package/isBrowser.mjs +1 -2
  102. package/isBrowserNow.js +21 -11
  103. package/isBrowserNow.mjs +1 -2
  104. package/isDate.js +21 -12
  105. package/isDate.mjs +1 -2
  106. package/isEmptyArray.js +21 -12
  107. package/isEmptyArray.mjs +1 -2
  108. package/isEmptyObject.js +21 -12
  109. package/isEmptyObject.mjs +1 -2
  110. package/isEmptyString.js +19 -6
  111. package/isEmptyString.mjs +1 -2
  112. package/isError.js +21 -12
  113. package/isError.mjs +1 -2
  114. package/isExternalUrl.js +24 -18
  115. package/isExternalUrl.mjs +4 -6
  116. package/isFile.js +21 -12
  117. package/isFile.mjs +1 -2
  118. package/isFloat.js +21 -12
  119. package/isFloat.mjs +1 -2
  120. package/isFormData.js +21 -12
  121. package/isFormData.mjs +1 -2
  122. package/isFullArray.js +21 -12
  123. package/isFullArray.mjs +1 -2
  124. package/isFullObject.js +21 -12
  125. package/isFullObject.mjs +1 -2
  126. package/isFullString.js +21 -12
  127. package/isFullString.mjs +1 -2
  128. package/isFunction.js +18 -9
  129. package/isFunction.mjs +1 -2
  130. package/isInt.js +21 -12
  131. package/isInt.mjs +1 -2
  132. package/isMap.js +21 -12
  133. package/isMap.mjs +1 -2
  134. package/isNaNValue.js +21 -12
  135. package/isNaNValue.mjs +1 -2
  136. package/isNegativeNumber.js +21 -12
  137. package/isNegativeNumber.mjs +1 -2
  138. package/isNull.js +21 -12
  139. package/isNull.mjs +1 -2
  140. package/isNullOrUndefined.js +23 -13
  141. package/isNullOrUndefined.mjs +1 -2
  142. package/isNumber.js +21 -14
  143. package/isNumber.mjs +1 -2
  144. package/isObject.js +21 -12
  145. package/isObject.mjs +1 -2
  146. package/isObjectLike.js +21 -14
  147. package/isObjectLike.mjs +1 -2
  148. package/isOneOf.js +19 -11
  149. package/isOneOf.mjs +1 -7
  150. package/isPlainObject.js +22 -15
  151. package/isPlainObject.mjs +3 -6
  152. package/isPositiveNumber.js +21 -12
  153. package/isPositiveNumber.mjs +1 -2
  154. package/isPrimitive.js +26 -22
  155. package/isPrimitive.mjs +5 -11
  156. package/isPromise.js +21 -12
  157. package/isPromise.mjs +1 -2
  158. package/isRegExp.js +21 -12
  159. package/isRegExp.mjs +1 -2
  160. package/isServer.js +22 -11
  161. package/isServer.mjs +1 -2
  162. package/isServerNow.js +21 -11
  163. package/isServerNow.mjs +1 -2
  164. package/isSet.js +21 -12
  165. package/isSet.mjs +1 -2
  166. package/isString.js +21 -12
  167. package/isString.mjs +1 -2
  168. package/isSymbol.js +21 -12
  169. package/isSymbol.mjs +1 -2
  170. package/isType.js +22 -17
  171. package/isType.mjs +3 -5
  172. package/isUndefined.js +21 -12
  173. package/isUndefined.mjs +1 -2
  174. package/isWeakMap.js +21 -12
  175. package/isWeakMap.mjs +1 -2
  176. package/isWeakSet.js +21 -12
  177. package/isWeakSet.mjs +1 -2
  178. package/kbToBytes.js +20 -7
  179. package/kbToBytes.mjs +1 -2
  180. package/location.js +6 -2
  181. package/location.mjs +3 -1
  182. package/lowercase.js +20 -9
  183. package/lowercase.mjs +1 -4
  184. package/mapListBy.js +21 -10
  185. package/mapListBy.mjs +2 -5
  186. package/matchSorter.js +132 -133
  187. package/matchSorter.mjs +108 -126
  188. package/mbToBytes.js +20 -7
  189. package/mbToBytes.mjs +1 -2
  190. package/mergeObjects.d.ts +1 -1
  191. package/mergeObjects.js +24 -26
  192. package/mergeObjects.mjs +12 -15
  193. package/mergeUrlQueryParams.js +25 -20
  194. package/mergeUrlQueryParams.mjs +4 -8
  195. package/moveSortableArrayItemByKey.js +26 -12
  196. package/moveSortableArrayItemByKey.mjs +8 -8
  197. package/noop.js +20 -7
  198. package/noop.mjs +1 -2
  199. package/normaliseUrl.js +22 -18
  200. package/normaliseUrl.mjs +1 -3
  201. package/normaliseUrlPathname.js +22 -17
  202. package/normaliseUrlPathname.mjs +1 -3
  203. package/objectOmit.js +21 -9
  204. package/objectOmit.mjs +3 -5
  205. package/objectPick.js +22 -9
  206. package/objectPick.mjs +4 -5
  207. package/package.json +11 -8
  208. package/parseCookie.js +29 -26
  209. package/parseCookie.mjs +11 -15
  210. package/parseURL.js +23 -10
  211. package/parseURL.mjs +5 -6
  212. package/quaranteneProps.js +24 -12
  213. package/quaranteneProps.mjs +6 -8
  214. package/randomInt.js +19 -6
  215. package/randomInt.mjs +1 -2
  216. package/randomKey.js +21 -8
  217. package/randomKey.mjs +3 -4
  218. package/readCookie.js +25 -12
  219. package/readCookie.mjs +7 -8
  220. package/removeAccents.js +24 -15
  221. package/removeAccents.mjs +5 -8
  222. package/removeCookie.js +26 -17
  223. package/removeCookie.mjs +6 -5
  224. package/removeDuplicates.js +1 -1
  225. package/removeDuplicates.mjs +0 -1
  226. package/removeDuplicatesByKey.js +24 -12
  227. package/removeDuplicatesByKey.mjs +5 -7
  228. package/removeDuplicatesComparing.js +22 -11
  229. package/removeDuplicatesComparing.mjs +3 -4
  230. package/removeIndexesFromArray.js +21 -8
  231. package/removeIndexesFromArray.mjs +3 -4
  232. package/removeTrailingSlash.js +20 -8
  233. package/removeTrailingSlash.mjs +1 -3
  234. package/removeUrlQueryParams.js +27 -20
  235. package/removeUrlQueryParams.mjs +5 -7
  236. package/render.js +61 -137
  237. package/render.mjs +43 -98
  238. package/roundTo.js +34 -22
  239. package/roundTo.mjs +15 -17
  240. package/serializeCookie.js +29 -35
  241. package/serializeCookie.mjs +9 -15
  242. package/setCookie.js +37 -31
  243. package/setCookie.mjs +13 -16
  244. package/shuffle.js +28 -14
  245. package/shuffle.mjs +10 -10
  246. package/slugify.js +33 -25
  247. package/slugify.mjs +13 -11
  248. package/split.js +18 -4
  249. package/swapMap.js +22 -10
  250. package/swapMap.mjs +3 -5
  251. package/throttle.d.ts +1 -0
  252. package/throttle.js +23 -15
  253. package/throttle.mjs +5 -11
  254. package/titleCase.js +20 -11
  255. package/titleCase.mjs +1 -6
  256. package/toNumber.js +20 -9
  257. package/toNumber.mjs +1 -2
  258. package/toRgba.js +22 -10
  259. package/toRgba.mjs +3 -5
  260. package/transformToUrlPathname.js +21 -18
  261. package/transformToUrlPathname.mjs +2 -5
  262. package/truncate.js +20 -13
  263. package/truncate.mjs +1 -8
  264. package/tryUntil.js +26 -15
  265. package/tryUntil.mjs +7 -10
  266. package/types.js +4 -1
  267. package/types.mjs +2 -1
  268. package/uid.js +21 -13
  269. package/uid.mjs +3 -5
  270. package/updateLinkParams.js +21 -14
  271. package/updateLinkParams.mjs +2 -3
  272. package/updateUrlQueryParams.js +26 -21
  273. package/updateUrlQueryParams.mjs +3 -7
  274. package/uppercase.js +20 -9
  275. package/uppercase.mjs +1 -4
  276. package/uuid.js +21 -10
  277. package/uuid.mjs +2 -5
  278. package/uuidNumeric.js +20 -7
  279. package/uuidNumeric.mjs +1 -2
  280. package/wait.js +20 -9
  281. package/wait.mjs +1 -4
  282. package/without.js +2 -3
  283. package/without.mjs +1 -3
package/render.js CHANGED
@@ -1,169 +1,93 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.render = void 0;
4
- var varname = "data";
5
- var evaluate = /<%([\s\S]+?(\}?)+)%>/g;
6
- var interpolate = /<%=([\s\S]+?)%>/g;
7
- var conditional = /<%\?(\?)?\s*([\s\S]*?)\s*%>/g;
8
- var iterate = /<%~\s*(?:%>|([\s\S]+?)\s*:\s*([\w$]+)\s*(?::\s*([\w$]+))?\s*%>)/g;
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ render: function() {
13
+ return render;
14
+ },
15
+ default: function() {
16
+ return _default;
17
+ }
18
+ });
19
+ const varname = "data";
20
+ const evaluate = /<%([\s\S]+?(\}?)+)%>/g;
21
+ const interpolate = /<%=([\s\S]+?)%>/g;
22
+ const conditional = /<%\?(\?)?\s*([\s\S]*?)\s*%>/g;
23
+ const iterate = /<%~\s*(?:%>|([\s\S]+?)\s*:\s*([\w$]+)\s*(?::\s*([\w$]+))?\s*%>)/g;
9
24
  // const encode = /<%!([\s\S]+?)%>/g;
10
- var use = /<%#([\s\S]+?)%>/g;
11
- var useParams = /(^|[^\w$])def(?:\.|\[['"])([\w$.]+)(?:['"]\])?\s*:\s*([\w$.]+|"[^"]+"|'[^']+'|\{[^}]+\})/g;
12
- var define = /<%##\s*([\w.$]+)\s*(:|=)([\s\S]+?)#%>/g;
13
- var defineParams = /^\s*([\w$]+):([\s\S]+)/;
14
- var start = "'+(";
15
- var end = ")+'";
25
+ const use = /<%#([\s\S]+?)%>/g;
26
+ const useParams = /(^|[^\w$])def(?:\.|\[['"])([\w$.]+)(?:['"]\])?\s*:\s*([\w$.]+|"[^"]+"|'[^']+'|\{[^}]+\})/g;
27
+ const define = /<%##\s*([\w.$]+)\s*(:|=)([\s\S]+?)#%>/g;
28
+ const defineParams = /^\s*([\w$]+):([\s\S]+)/;
29
+ const start = "'+(";
30
+ const end = ")+'";
16
31
  // const startencode = "'+encodeHTML(";
17
- var skip = /$^/;
18
- var resolveDefs = function (block, def) {
19
- return (typeof block === "string" ? block : block.toString())
20
- .replace(define || skip, function (_, code, assign, value) {
32
+ const skip = /$^/;
33
+ const resolveDefs = (block, def)=>(typeof block === "string" ? block : block.toString()).replace(define || skip, (_, code, assign, value)=>{
21
34
  if (code.indexOf("def.") === 0) {
22
35
  code = code.substring(4);
23
36
  }
24
37
  if (!(code in def)) {
25
38
  if (assign === ":") {
26
- value.replace(defineParams,
27
- // @ts-expect-error nevermind
28
- function (_, param, v) {
29
- def[code] = { arg: param, text: v };
39
+ value.replace(defineParams, // @ts-expect-error nevermind
40
+ (_, param, v)=>{
41
+ def[code] = {
42
+ arg: param,
43
+ text: v
44
+ };
30
45
  });
31
46
  // @ts-expect-error nevermind
32
- if (!(code in def))
33
- def[code] = value;
34
- }
35
- else {
47
+ if (!(code in def)) def[code] = value;
48
+ } else {
36
49
  new Function("def", "def['" + code + "']=" + value)(def);
37
50
  }
38
51
  }
39
52
  return "";
40
- })
41
- .replace(use || skip, function (_, code) {
42
- code = code.replace(useParams, function (_, s, d, param) {
53
+ }).replace(use || skip, (_, code)=>{
54
+ code = code.replace(useParams, (_, s, d, param)=>{
43
55
  if (def[d] && def[d].arg && param) {
44
- var rw = (d + ":" + param).replace(/'|\\/g, "_");
56
+ const rw = (d + ":" + param).replace(/'|\\/g, "_");
45
57
  def.__exp = def.__exp || {};
46
58
  def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
47
59
  return s + "def.__exp['" + rw + "']";
48
60
  }
49
61
  return s;
50
62
  });
51
- var v = new Function("def", "return " + code)(def);
63
+ const v = new Function("def", "return " + code)(def);
52
64
  return v ? resolveDefs(v, def) : v;
53
65
  });
54
- };
55
- var unescape = function (code) {
56
- return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
57
- };
58
- /**
59
- * Render template (adapted from doT.js)
60
- *
61
- * The data made available to the template is always on the `data` key, e.g.:
62
- * `renderer({ myVal: "xx" })`
63
- * ... will be accessible on
64
- * `<%= data.myVal %>`
65
- *
66
- * The default delimiters are customised to work without conflicts with Blade and Twig:
67
- * ```
68
- * <% %> for evaluation
69
- * <%= %> for interpolation
70
- * <%? %> for conditionals
71
- * <%~ %> for array iteration
72
- * <%# %> for compile-time evaluation/includes and partials
73
- * <%## #%> for compile-time defines
74
- *
75
- * Unsupported:
76
- * <%! %> for interpolation with encoding
77
- * ```
78
- *
79
- * @example
80
- *
81
- * ```js
82
- * import { render } from "...";
83
- *
84
- * const data = { name: "XYZ" };
85
- * const tpl = `Hello <%= data.name %>`;
86
- * const renderer = render(tpl);
87
- *
88
- * console.log(renderer(data)); // outputs 'Hello XYZ'
89
- * ```
90
- *
91
- * @borrows [olado/doT by Laura Doktorova](https://github.com/olado/doT)
92
- * @see https://olado.github.io/doT/index.html
93
- */
94
- var render = function (tmpl, def) {
95
- var sid = 0;
96
- var indv;
97
- var str = use || define ? resolveDefs(tmpl, def || {}) : tmpl;
98
- str = ("var X='" +
99
- str
100
- .replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g, " ")
101
- .replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g, "")
102
- .replace(/'|\\/g, "\\$&")
103
- .replace(interpolate || skip, function (_, code) { return start + unescape(code) + end; })
104
- // .replace(
105
- // encode || skip,
106
- // (_, code) => cse.startencode + unescape(code) + cse.end
107
- // )
108
- .replace(conditional || skip, function (_, elseCase, code) {
109
- return elseCase
110
- ? code
111
- ? "';}else if(" + unescape(code) + "){X+='"
112
- : "';}else{X+='"
113
- : code
114
- ? "';if(" + unescape(code) + "){X+='"
115
- : "';}X+='";
116
- })
117
- .replace(iterate || skip, function (_, arr, vName, iName) {
118
- if (!arr)
119
- return "';} } X+='";
120
- sid++;
121
- indv = iName || "i" + sid;
122
- arr = unescape(arr);
123
- return ("';var arr" +
124
- sid +
125
- "=" +
126
- arr +
127
- ";if(arr" +
128
- sid +
129
- "){var " +
130
- vName +
131
- "," +
132
- indv +
133
- "=-1,l" +
134
- sid +
135
- "=arr" +
136
- sid +
137
- ".length-1;while(" +
138
- indv +
139
- "<l" +
140
- sid +
141
- "){" +
142
- vName +
143
- "=arr" +
144
- sid +
145
- "[" +
146
- indv +
147
- "+=1];X+='");
148
- })
149
- .replace(evaluate || skip, function (_, code) { return "';" + unescape(code) + "X+='"; }) +
150
- "';return X;")
151
- .replace(/\n/g, "\\n")
152
- .replace(/\t/g, "\\t")
153
- .replace(/\r/g, "\\r")
154
- .replace(/(\s|;|\}|^|\{)X\+='';/g, "$1")
155
- .replace(/\+''/g, "");
66
+ const unescape = (code)=>code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
67
+ const render = (tmpl, def)=>{
68
+ let sid = 0;
69
+ let indv;
70
+ let str = use || define ? resolveDefs(tmpl, def || {}) : tmpl;
71
+ str = ("var X='" + str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g, " ").replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g, "").replace(/'|\\/g, "\\$&").replace(interpolate || skip, (_, code)=>start + unescape(code) + end)// .replace(
72
+ // encode || skip,
73
+ // (_, code) => cse.startencode + unescape(code) + cse.end
74
+ // )
75
+ .replace(conditional || skip, (_, elseCase, code)=>elseCase ? code ? "';}else if(" + unescape(code) + "){X+='" : "';}else{X+='" : code ? "';if(" + unescape(code) + "){X+='" : "';}X+='").replace(iterate || skip, (_, arr, vName, iName)=>{
76
+ if (!arr) return "';} } X+='";
77
+ sid++;
78
+ indv = iName || "i" + sid;
79
+ arr = unescape(arr);
80
+ return "';var arr" + sid + "=" + arr + ";if(arr" + sid + "){var " + vName + "," + indv + "=-1,l" + sid + "=arr" + sid + ".length-1;while(" + indv + "<l" + sid + "){" + vName + "=arr" + sid + "[" + indv + "+=1];X+='";
81
+ }).replace(evaluate || skip, (_, code)=>"';" + unescape(code) + "X+='") + "';return X;").replace(/\n/g, "\\n").replace(/\t/g, "\\t").replace(/\r/g, "\\r").replace(/(\s|;|\}|^|\{)X\+='';/g, "$1").replace(/\+''/g, "");
156
82
  //.replace(/(\s|;|\}|^|\{)X\+=''\+/g,'$1X+=');
157
83
  try {
158
84
  return new Function(varname, str);
159
- }
160
- catch (e) {
85
+ } catch (e) {
161
86
  if (process.env["NODE_ENV"] !== "production") {
162
87
  console.log("Could not create a template function: " + str);
163
88
  throw e;
164
89
  }
165
90
  }
166
- return function () { return ""; };
91
+ return ()=>"";
167
92
  };
168
- exports.render = render;
169
- exports.default = exports.render;
93
+ const _default = render;
package/render.mjs CHANGED
@@ -1,57 +1,51 @@
1
- var varname = "data";
2
- var evaluate = /<%([\s\S]+?(\}?)+)%>/g;
3
- var interpolate = /<%=([\s\S]+?)%>/g;
4
- var conditional = /<%\?(\?)?\s*([\s\S]*?)\s*%>/g;
5
- var iterate = /<%~\s*(?:%>|([\s\S]+?)\s*:\s*([\w$]+)\s*(?::\s*([\w$]+))?\s*%>)/g;
1
+ const varname = "data";
2
+ const evaluate = /<%([\s\S]+?(\}?)+)%>/g;
3
+ const interpolate = /<%=([\s\S]+?)%>/g;
4
+ const conditional = /<%\?(\?)?\s*([\s\S]*?)\s*%>/g;
5
+ const iterate = /<%~\s*(?:%>|([\s\S]+?)\s*:\s*([\w$]+)\s*(?::\s*([\w$]+))?\s*%>)/g;
6
6
  // const encode = /<%!([\s\S]+?)%>/g;
7
- var use = /<%#([\s\S]+?)%>/g;
8
- var useParams = /(^|[^\w$])def(?:\.|\[['"])([\w$.]+)(?:['"]\])?\s*:\s*([\w$.]+|"[^"]+"|'[^']+'|\{[^}]+\})/g;
9
- var define = /<%##\s*([\w.$]+)\s*(:|=)([\s\S]+?)#%>/g;
10
- var defineParams = /^\s*([\w$]+):([\s\S]+)/;
11
- var start = "'+(";
12
- var end = ")+'";
7
+ const use = /<%#([\s\S]+?)%>/g;
8
+ const useParams = /(^|[^\w$])def(?:\.|\[['"])([\w$.]+)(?:['"]\])?\s*:\s*([\w$.]+|"[^"]+"|'[^']+'|\{[^}]+\})/g;
9
+ const define = /<%##\s*([\w.$]+)\s*(:|=)([\s\S]+?)#%>/g;
10
+ const defineParams = /^\s*([\w$]+):([\s\S]+)/;
11
+ const start = "'+(";
12
+ const end = ")+'";
13
13
  // const startencode = "'+encodeHTML(";
14
- var skip = /$^/;
15
- var resolveDefs = function (block, def) {
16
- return (typeof block === "string" ? block : block.toString())
17
- .replace(define || skip, function (_, code, assign, value) {
14
+ const skip = /$^/;
15
+ const resolveDefs = (block, def)=>(typeof block === "string" ? block : block.toString()).replace(define || skip, (_, code, assign, value)=>{
18
16
  if (code.indexOf("def.") === 0) {
19
17
  code = code.substring(4);
20
18
  }
21
19
  if (!(code in def)) {
22
20
  if (assign === ":") {
23
- value.replace(defineParams,
24
- // @ts-expect-error nevermind
25
- function (_, param, v) {
26
- def[code] = { arg: param, text: v };
21
+ value.replace(defineParams, // @ts-expect-error nevermind
22
+ (_, param, v)=>{
23
+ def[code] = {
24
+ arg: param,
25
+ text: v
26
+ };
27
27
  });
28
28
  // @ts-expect-error nevermind
29
- if (!(code in def))
30
- def[code] = value;
31
- }
32
- else {
29
+ if (!(code in def)) def[code] = value;
30
+ } else {
33
31
  new Function("def", "def['" + code + "']=" + value)(def);
34
32
  }
35
33
  }
36
34
  return "";
37
- })
38
- .replace(use || skip, function (_, code) {
39
- code = code.replace(useParams, function (_, s, d, param) {
35
+ }).replace(use || skip, (_, code)=>{
36
+ code = code.replace(useParams, (_, s, d, param)=>{
40
37
  if (def[d] && def[d].arg && param) {
41
- var rw = (d + ":" + param).replace(/'|\\/g, "_");
38
+ const rw = (d + ":" + param).replace(/'|\\/g, "_");
42
39
  def.__exp = def.__exp || {};
43
40
  def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
44
41
  return s + "def.__exp['" + rw + "']";
45
42
  }
46
43
  return s;
47
44
  });
48
- var v = new Function("def", "return " + code)(def);
45
+ const v = new Function("def", "return " + code)(def);
49
46
  return v ? resolveDefs(v, def) : v;
50
47
  });
51
- };
52
- var unescape = function (code) {
53
- return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
54
- };
48
+ const unescape = (code)=>code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
55
49
  /**
56
50
  * Render template (adapted from doT.js)
57
51
  *
@@ -87,79 +81,30 @@ var unescape = function (code) {
87
81
  *
88
82
  * @borrows [olado/doT by Laura Doktorova](https://github.com/olado/doT)
89
83
  * @see https://olado.github.io/doT/index.html
90
- */
91
- export var render = function (tmpl, def) {
92
- var sid = 0;
93
- var indv;
94
- var str = use || define ? resolveDefs(tmpl, def || {}) : tmpl;
95
- str = ("var X='" +
96
- str
97
- .replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g, " ")
98
- .replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g, "")
99
- .replace(/'|\\/g, "\\$&")
100
- .replace(interpolate || skip, function (_, code) { return start + unescape(code) + end; })
101
- // .replace(
102
- // encode || skip,
103
- // (_, code) => cse.startencode + unescape(code) + cse.end
104
- // )
105
- .replace(conditional || skip, function (_, elseCase, code) {
106
- return elseCase
107
- ? code
108
- ? "';}else if(" + unescape(code) + "){X+='"
109
- : "';}else{X+='"
110
- : code
111
- ? "';if(" + unescape(code) + "){X+='"
112
- : "';}X+='";
113
- })
114
- .replace(iterate || skip, function (_, arr, vName, iName) {
115
- if (!arr)
116
- return "';} } X+='";
117
- sid++;
118
- indv = iName || "i" + sid;
119
- arr = unescape(arr);
120
- return ("';var arr" +
121
- sid +
122
- "=" +
123
- arr +
124
- ";if(arr" +
125
- sid +
126
- "){var " +
127
- vName +
128
- "," +
129
- indv +
130
- "=-1,l" +
131
- sid +
132
- "=arr" +
133
- sid +
134
- ".length-1;while(" +
135
- indv +
136
- "<l" +
137
- sid +
138
- "){" +
139
- vName +
140
- "=arr" +
141
- sid +
142
- "[" +
143
- indv +
144
- "+=1];X+='");
145
- })
146
- .replace(evaluate || skip, function (_, code) { return "';" + unescape(code) + "X+='"; }) +
147
- "';return X;")
148
- .replace(/\n/g, "\\n")
149
- .replace(/\t/g, "\\t")
150
- .replace(/\r/g, "\\r")
151
- .replace(/(\s|;|\}|^|\{)X\+='';/g, "$1")
152
- .replace(/\+''/g, "");
84
+ */ export const render = (tmpl, def)=>{
85
+ let sid = 0;
86
+ let indv;
87
+ let str = use || define ? resolveDefs(tmpl, def || {}) : tmpl;
88
+ str = ("var X='" + str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g, " ").replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g, "").replace(/'|\\/g, "\\$&").replace(interpolate || skip, (_, code)=>start + unescape(code) + end)// .replace(
89
+ // encode || skip,
90
+ // (_, code) => cse.startencode + unescape(code) + cse.end
91
+ // )
92
+ .replace(conditional || skip, (_, elseCase, code)=>elseCase ? code ? "';}else if(" + unescape(code) + "){X+='" : "';}else{X+='" : code ? "';if(" + unescape(code) + "){X+='" : "';}X+='").replace(iterate || skip, (_, arr, vName, iName)=>{
93
+ if (!arr) return "';} } X+='";
94
+ sid++;
95
+ indv = iName || "i" + sid;
96
+ arr = unescape(arr);
97
+ return "';var arr" + sid + "=" + arr + ";if(arr" + sid + "){var " + vName + "," + indv + "=-1,l" + sid + "=arr" + sid + ".length-1;while(" + indv + "<l" + sid + "){" + vName + "=arr" + sid + "[" + indv + "+=1];X+='";
98
+ }).replace(evaluate || skip, (_, code)=>"';" + unescape(code) + "X+='") + "';return X;").replace(/\n/g, "\\n").replace(/\t/g, "\\t").replace(/\r/g, "\\r").replace(/(\s|;|\}|^|\{)X\+='';/g, "$1").replace(/\+''/g, "");
153
99
  //.replace(/(\s|;|\}|^|\{)X\+=''\+/g,'$1X+=');
154
100
  try {
155
101
  return new Function(varname, str);
156
- }
157
- catch (e) {
102
+ } catch (e) {
158
103
  if (process.env["NODE_ENV"] !== "production") {
159
104
  console.log("Could not create a template function: " + str);
160
105
  throw e;
161
106
  }
162
107
  }
163
- return function () { return ""; };
108
+ return ()=>"";
164
109
  };
165
110
  export default render;
package/roundTo.js CHANGED
@@ -1,38 +1,50 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.roundTo = void 0;
4
1
  /**
5
2
  * Round to given number of the given number of decimals
6
3
  *
7
4
  * @category math
8
5
  * @see https://stackoverflow.com/a/15762794/1938970
9
- */
10
- function roundTo(num, decimals) {
11
- if (decimals === void 0) { decimals = 2; }
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ function _export(target, all) {
11
+ for(var name in all)Object.defineProperty(target, name, {
12
+ enumerable: true,
13
+ get: all[name]
14
+ });
15
+ }
16
+ _export(exports, {
17
+ roundTo: function() {
18
+ return roundTo;
19
+ },
20
+ default: function() {
21
+ return _default;
22
+ }
23
+ });
24
+ function roundTo(num, decimals = 2) {
12
25
  if (isFinite(num) && !isNaN(num)) {
13
26
  // method 1
14
27
  // return Number(num).toFixed(decimals);
15
28
  // method 2: @see https://stackoverflow.com/a/43532829/1938970
16
- var multiplicator = Math.pow(10, decimals);
29
+ const multiplicator = Math.pow(10, decimals);
17
30
  return Math.round(num * multiplicator) / multiplicator + "";
18
- // method 3: @see https://stackoverflow.com/a/15762794/1938970
19
- // let negative = false;
20
- // if (num < 0) {
21
- // negative = true;
22
- // num = num * -1;
23
- // }
24
- // const multiplicator = Math.pow(10, decimals);
25
- // const outputStr = parseFloat((num * multiplicator).toFixed(11));
26
- // let outputNum = (Math.round(outputStr) / multiplicator).toFixed(decimals);
27
- // if (negative) {
28
- // return (Number(outputNum) * -1).toFixed(decimals);
29
- // }
30
- // return outputNum;
31
+ // method 3: @see https://stackoverflow.com/a/15762794/1938970
32
+ // let negative = false;
33
+ // if (num < 0) {
34
+ // negative = true;
35
+ // num = num * -1;
36
+ // }
37
+ // const multiplicator = Math.pow(10, decimals);
38
+ // const outputStr = parseFloat((num * multiplicator).toFixed(11));
39
+ // let outputNum = (Math.round(outputStr) / multiplicator).toFixed(decimals);
40
+ // if (negative) {
41
+ // return (Number(outputNum) * -1).toFixed(decimals);
42
+ // }
43
+ // return outputNum;
31
44
  }
32
45
  if (process.env["NODE_ENV"] !== "production") {
33
46
  console.warn("[@koine/utils] math:roundTo -> given not a finite number as first arg");
34
47
  }
35
48
  return "";
36
49
  }
37
- exports.roundTo = roundTo;
38
- exports.default = roundTo;
50
+ const _default = roundTo;
package/roundTo.mjs CHANGED
@@ -3,28 +3,26 @@
3
3
  *
4
4
  * @category math
5
5
  * @see https://stackoverflow.com/a/15762794/1938970
6
- */
7
- export function roundTo(num, decimals) {
8
- if (decimals === void 0) { decimals = 2; }
6
+ */ export function roundTo(num, decimals = 2) {
9
7
  if (isFinite(num) && !isNaN(num)) {
10
8
  // method 1
11
9
  // return Number(num).toFixed(decimals);
12
10
  // method 2: @see https://stackoverflow.com/a/43532829/1938970
13
- var multiplicator = Math.pow(10, decimals);
11
+ const multiplicator = Math.pow(10, decimals);
14
12
  return Math.round(num * multiplicator) / multiplicator + "";
15
- // method 3: @see https://stackoverflow.com/a/15762794/1938970
16
- // let negative = false;
17
- // if (num < 0) {
18
- // negative = true;
19
- // num = num * -1;
20
- // }
21
- // const multiplicator = Math.pow(10, decimals);
22
- // const outputStr = parseFloat((num * multiplicator).toFixed(11));
23
- // let outputNum = (Math.round(outputStr) / multiplicator).toFixed(decimals);
24
- // if (negative) {
25
- // return (Number(outputNum) * -1).toFixed(decimals);
26
- // }
27
- // return outputNum;
13
+ // method 3: @see https://stackoverflow.com/a/15762794/1938970
14
+ // let negative = false;
15
+ // if (num < 0) {
16
+ // negative = true;
17
+ // num = num * -1;
18
+ // }
19
+ // const multiplicator = Math.pow(10, decimals);
20
+ // const outputStr = parseFloat((num * multiplicator).toFixed(11));
21
+ // let outputNum = (Math.round(outputStr) / multiplicator).toFixed(decimals);
22
+ // if (negative) {
23
+ // return (Number(outputNum) * -1).toFixed(decimals);
24
+ // }
25
+ // return outputNum;
28
26
  }
29
27
  if (process.env["NODE_ENV"] !== "production") {
30
28
  console.warn("[@koine/utils] math:roundTo -> given not a finite number as first arg");
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @file
4
3
  *
@@ -7,39 +6,37 @@
7
6
  * All cookie related code is inspired and adapted from:
8
7
  * - [js-cookie](https://github.com/js-cookie/js-cookie)
9
8
  * - [cookie](https://github.com/jshttp/cookie)
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.serializeCookie = void 0;
13
- var isNumber_1 = require("./isNumber");
9
+ */ "use strict";
10
+ Object.defineProperty(exports, "__esModule", {
11
+ value: true
12
+ });
13
+ function _export(target, all) {
14
+ for(var name in all)Object.defineProperty(target, name, {
15
+ enumerable: true,
16
+ get: all[name]
17
+ });
18
+ }
19
+ _export(exports, {
20
+ serializeCookie: function() {
21
+ return serializeCookie;
22
+ },
23
+ default: function() {
24
+ return _default;
25
+ }
26
+ });
27
+ const _isNumber = require("./isNumber");
14
28
  /**
15
29
  * RegExp to match field-content in RFC 7230 sec 3.2
16
30
  *
17
31
  * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
18
32
  * field-vchar = VCHAR / obs-text
19
33
  * obs-text = %x80-FF
20
- */
21
- // eslint-disable-next-line no-control-regex
22
- var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
23
- /**
24
- * Serialize data into a cookie header.
25
- *
26
- * Serialize the a name value pair into a cookie string suitable for
27
- * http headers. An optional attributes object specified cookie parameters.
28
- *
29
- * serialize('foo', 'bar', { httpOnly: true })
30
- * => "foo=bar; httpOnly"
31
- *
32
- * @category cookie
33
- *
34
- * All cookie related code is inspired and adapted from:
35
- * - [js-cookie](https://github.com/js-cookie/js-cookie)
36
- * - [cookie](https://github.com/jshttp/cookie)
37
- */
38
- function serializeCookie(name, val, attributes) {
39
- if (attributes === void 0) { attributes = {}; }
40
- var _a = attributes.encode, encode = _a === void 0 ? encodeURIComponent : _a, domain = attributes.domain, path = attributes.path, httpOnly = attributes.httpOnly, secure = attributes.secure, sameSite = attributes.sameSite;
41
- var maxAge = attributes.maxAge, expires = attributes.expires;
42
- var value = encode(val);
34
+ */ // eslint-disable-next-line no-control-regex
35
+ const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
36
+ function serializeCookie(name, val, attributes = {}) {
37
+ const { encode = encodeURIComponent, domain, path, httpOnly, secure, sameSite } = attributes;
38
+ let { maxAge, expires } = attributes;
39
+ const value = encode(val);
43
40
  if (process.env["NODE_ENV"] !== "production") {
44
41
  if (!fieldContentRegExp.test(name)) {
45
42
  throw new TypeError("argument name is invalid");
@@ -51,7 +48,7 @@ function serializeCookie(name, val, attributes) {
51
48
  throw new TypeError("argument val is invalid");
52
49
  }
53
50
  }
54
- var str = name + "=" + value;
51
+ let str = name + "=" + value;
55
52
  if (null != maxAge) {
56
53
  maxAge = maxAge - 0;
57
54
  if (isNaN(maxAge) || !isFinite(maxAge)) {
@@ -76,7 +73,7 @@ function serializeCookie(name, val, attributes) {
76
73
  str += "; Path=" + path;
77
74
  }
78
75
  if (expires) {
79
- if ((0, isNumber_1.isNumber)(expires)) {
76
+ if ((0, _isNumber.isNumber)(expires)) {
80
77
  expires = new Date(Date.now() + expires * 864e5);
81
78
  }
82
79
  str += "; Expires=" + expires.toUTCString();
@@ -88,7 +85,7 @@ function serializeCookie(name, val, attributes) {
88
85
  str += "; Secure";
89
86
  }
90
87
  if (sameSite) {
91
- switch (sameSite.toLowerCase()) {
88
+ switch(sameSite.toLowerCase()){
92
89
  case "lax":
93
90
  str += "; SameSite=Lax";
94
91
  break;
@@ -98,11 +95,8 @@ function serializeCookie(name, val, attributes) {
98
95
  case "none":
99
96
  str += "; SameSite=None";
100
97
  break;
101
- // default:
102
- // throw new TypeError('option sameSite is invalid');
103
98
  }
104
99
  }
105
100
  return str;
106
101
  }
107
- exports.serializeCookie = serializeCookie;
108
- exports.default = serializeCookie;
102
+ const _default = serializeCookie;