@neovici/cosmoz-utils 3.22.0 → 3.25.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.
package/index.js CHANGED
@@ -40,3 +40,5 @@ export {
40
40
  Money,
41
41
  DateUtils as Date
42
42
  };
43
+
44
+ export * from './lib/tagged';
package/lib/date.js CHANGED
@@ -24,6 +24,13 @@ const
24
24
  }
25
25
  return [secDiff, 'second'];
26
26
  },
27
+ rules = { isoBasic: /^\d{4}-\d{2}-\d{2}$/ui },
28
+ parse = val => {
29
+ if (typeof val === 'string' && rules.isoBasic.test(val)) {
30
+ return new Date(`${ val }T00:00`);
31
+ }
32
+ return new Date(val);
33
+ },
27
34
  /**
28
35
  * Validate a Date object or date string.
29
36
  * @param {date/string} date Date to check.
@@ -37,7 +44,7 @@ const
37
44
  return date;
38
45
  }
39
46
 
40
- const ensuredDate = new Date(date);
47
+ const ensuredDate = parse(date);
41
48
 
42
49
  if (ensuredDate instanceof Date && isNaN(ensuredDate)) {
43
50
  return;
package/lib/function.js CHANGED
@@ -1,11 +1,20 @@
1
- const identity = obj => obj,
1
+ const
2
+ constant = v => () => v,
3
+ constTrue = constant(true),
4
+ constUndefined = constant(),
5
+ noop = constUndefined,
6
+ identity = obj => obj,
2
7
  or = (...fns) => (...args) => fns.reduce((res, fn) => res || fn(...args), false),
3
- once = (fn, check) => {
8
+ once = (fn, check = constTrue) => {
4
9
  let result; // eslint-disable-next-line no-return-assign
5
10
  return (...args) => result ??= check(args) ? fn(...args) : undefined;
6
11
  };
7
12
 
8
13
  export {
14
+ constant,
15
+ constTrue,
16
+ constUndefined,
17
+ noop,
9
18
  identity,
10
19
  once,
11
20
  or
package/lib/promise.js ADDED
@@ -0,0 +1,16 @@
1
+ export const
2
+ timeout$ = ms => new Promise(res => setTimeout(res, ms)),
3
+ event$ = (target, type, predicate = () => true, timeout = 300000) => new Promise((resolve, reject) => {
4
+ let handler;
5
+ const tid = setTimeout(() => {
6
+ target.removeEventListener(type, handler);
7
+ reject(new Error('Timeout out'));
8
+ }, timeout);
9
+ target.addEventListener(type, handler = e => {
10
+ if (predicate(e)) {
11
+ target.removeEventListener(type, handler);
12
+ clearTimeout(tid);
13
+ resolve(e);
14
+ }
15
+ });
16
+ });
package/lib/tagged.js ADDED
@@ -0,0 +1 @@
1
+ export const tagged = (strings, ...values) => strings.flatMap((s, i) => [s, values[i] || '']).join('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-utils",
3
- "version": "3.22.0",
3
+ "version": "3.25.0",
4
4
  "description": "Date, money and template management functions commonly needed in Cosmoz views.",
5
5
  "keywords": [
6
6
  "polymer",
@@ -53,8 +53,8 @@
53
53
  "haunted": "^4.8.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@commitlint/cli": "^14.0.0",
57
- "@commitlint/config-conventional": "^14.0.0",
56
+ "@commitlint/cli": "^16.0.0",
57
+ "@commitlint/config-conventional": "^16.0.0",
58
58
  "@neovici/eslint-config": "^1.3.0",
59
59
  "@open-wc/testing": "^2.5.0",
60
60
  "@polymer/polymer": "^3.3.1",
@@ -62,10 +62,9 @@
62
62
  "@semantic-release/git": "^10.0.0",
63
63
  "@web/test-runner": "^0.13.0",
64
64
  "@web/test-runner-selenium": "^0.5.0",
65
- "eslint": "^7.0.0",
66
- "husky": "^6.0.0",
65
+ "husky": "^7.0.0",
67
66
  "lit-html": "^1.0.0",
68
67
  "semantic-release": "^18.0.0",
69
- "sinon": "^11.0.0"
68
+ "sinon": "^12.0.0"
70
69
  }
71
70
  }