@lowdefy/helpers 4.0.0-alpha.8 → 4.0.0-rc.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.
@@ -0,0 +1,46 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ // https://stackoverflow.com/a/46432113/8295949
16
+ // Implementation of Least Recently Updated cache.
17
+ // It uses the fact that the implementation of Map keep track of item insertion order
18
+ let LRUCache = class LRUCache {
19
+ get(key) {
20
+ const item = this.cache.get(key);
21
+ if (item) {
22
+ // Refresh key.
23
+ this.cache.delete(key);
24
+ this.cache.set(key, item);
25
+ }
26
+ return item;
27
+ }
28
+ set(key, val) {
29
+ if (this.cache.has(key)) {
30
+ // Refresh key
31
+ this.cache.delete(key);
32
+ } else if (this.cache.size === this.maxSize) {
33
+ // Evict oldest
34
+ this.cache.delete(this.first());
35
+ }
36
+ this.cache.set(key, val);
37
+ }
38
+ first() {
39
+ return this.cache.keys().next().value;
40
+ }
41
+ constructor({ maxSize =100 } = {}){
42
+ this.maxSize = maxSize;
43
+ this.cache = new Map();
44
+ }
45
+ };
46
+ export default LRUCache;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,11 +12,11 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function createCachedPromises(getter) {
16
- const cache = new Map();
15
+ */ function createCachedPromises({ getter , cache }) {
17
16
  function cachedPromises(key) {
18
- if (cache.has(key)) {
19
- return Promise.resolve(cache.get(key));
17
+ const cached = cache.get(key);
18
+ if (cached) {
19
+ return Promise.resolve(cached);
20
20
  }
21
21
  const promise = getter(key);
22
22
  cache.set(key, promise);
package/dist/get.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
15
15
  */ import applyArrayIndices from './applyArrayIndices.js';
16
16
  import cachedPromises from './cachedPromises.js';
17
17
  import get from './get.js';
18
+ import LRUCache from './LRUCache.js';
18
19
  import mergeObjects from './mergeObjects.js';
19
20
  import omit from './omit.js';
20
21
  import serializer from './serializer.js';
@@ -25,4 +26,4 @@ import type from './type.js';
25
26
  import unset from './unset.js';
26
27
  import urlQuery from './urlQuery.js';
27
28
  import wait from './wait.js';
28
- export { applyArrayIndices, cachedPromises, get, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery, wait };
29
+ export { applyArrayIndices, cachedPromises, get, LRUCache, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery, wait };
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -18,8 +18,7 @@ import type from './type.js';
18
18
  const mergeObjects = (objects)=>{
19
19
  let merged = objects;
20
20
  if (type.isArray(objects)) {
21
- merged = merge(...objects.filter((obj)=>type.isObject(obj)
22
- ));
21
+ merged = merge(...objects.filter((obj)=>type.isObject(obj)));
23
22
  }
24
23
  return merged;
25
24
  };
package/dist/omit.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -17,13 +17,11 @@ import stableStringify from './stableStringify.js';
17
17
  const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
18
18
  let dateReplacer = (date)=>({
19
19
  _date: date.valueOf()
20
- })
21
- ;
20
+ });
22
21
  if (isoStringDates) {
23
22
  dateReplacer = (date)=>({
24
23
  _date: date.toISOString()
25
- })
26
- ;
24
+ });
27
25
  }
28
26
  let newValue = value;
29
27
  if (customReplacer) {
@@ -59,8 +57,7 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
59
57
  });
60
58
  }
61
59
  return newValue;
62
- }
63
- ;
60
+ };
64
61
  const makeReviver = (customReviver)=>(key, value)=>{
65
62
  let newValue = value;
66
63
  if (customReviver) {
@@ -85,8 +82,7 @@ const makeReviver = (customReviver)=>(key, value)=>{
85
82
  return result;
86
83
  }
87
84
  return newValue;
88
- }
89
- ;
85
+ };
90
86
  const serialize = (json, options = {})=>{
91
87
  if (type.isUndefined(json)) return json;
92
88
  if (type.isDate(json)) {
package/dist/set.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-plusplus */ /* eslint-disable no-use-before-define */ /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-continue */ /* eslint-disable no-plusplus */ /* eslint-disable consistent-return */ /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -39,8 +39,7 @@ function stableStringify(obj, opts) {
39
39
  let space = opts.space || '';
40
40
  if (typeof space === 'number') space = Array(space + 1).join(' ');
41
41
  const cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
42
- const replacer = opts.replacer || ((key, value)=>value
43
- );
42
+ const replacer = opts.replacer || ((key, value)=>value);
44
43
  const cmp = opts.cmp && ((f)=>{
45
44
  return (node)=>{
46
45
  return (a, b)=>{
@@ -57,7 +56,7 @@ function stableStringify(obj, opts) {
57
56
  };
58
57
  })(opts.cmp);
59
58
  const seen = [];
60
- return (function stringify(parent, key, node, level) {
59
+ return function stringify(parent, key, node, level) {
61
60
  const indent = space ? `\n${new Array(level + 1).join(space)}` : '';
62
61
  const colonSeparator = space ? ': ' : ':';
63
62
  if (node && node.toJSON && typeof node.toJSON === 'function') {
@@ -93,7 +92,7 @@ function stableStringify(obj, opts) {
93
92
  }
94
93
  seen.splice(seen.indexOf(node), 1);
95
94
  return `{${out.join(',')}${indent}}`;
96
- })({
95
+ }({
97
96
  '': obj
98
97
  }, '', obj, 0);
99
98
  }
package/dist/swap.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable indent */ /* eslint-disable default-case */ /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -146,39 +146,24 @@ type.isArray = isArray;
146
146
  type.isDate = isDate;
147
147
  type.isError = isError;
148
148
  type.isDateString = isDateString;
149
- type.isObject = (value)=>kindOf(value) === 'object'
150
- ;
151
- type.isString = (value)=>typeof value === 'string'
152
- ;
153
- type.isRegExp = (value)=>kindOf(value) === 'regexp'
154
- ;
155
- type.isFunction = (value)=>kindOf(value) === 'function'
156
- ;
157
- type.isBoolean = (value)=>typeof value === 'boolean'
158
- ;
159
- type.isNumber = (value)=>typeof value === 'number' && Number.isFinite(value)
160
- ;
161
- type.isNumeric = (value)=>!Number.isNaN(Number(value))
162
- ;
163
- type.isInt = (value)=>Number.isInteger(value) === true
164
- ;
165
- type.isSet = (value)=>kindOf(value) === 'set'
166
- ;
167
- type.isNull = (value)=>kindOf(value) === 'null'
168
- ;
169
- type.isUndefined = (value)=>kindOf(value) === 'undefined'
170
- ;
171
- type.isNone = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null'
172
- ;
173
- type.isPrimitive = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null' || kindOf(value) === 'string' || kindOf(value) === 'number' || kindOf(value) === 'boolean' || kindOf(value) === 'date'
174
- ;
175
- type.isEmptyObject = (value)=>kindOf(value) === 'object' && Object.keys(value).length === 0
176
- ;
149
+ type.isObject = (value)=>kindOf(value) === 'object';
150
+ type.isString = (value)=>typeof value === 'string';
151
+ type.isRegExp = (value)=>kindOf(value) === 'regexp';
152
+ type.isFunction = (value)=>kindOf(value) === 'function';
153
+ type.isBoolean = (value)=>typeof value === 'boolean';
154
+ type.isNumber = (value)=>typeof value === 'number' && Number.isFinite(value);
155
+ type.isNumeric = (value)=>!Number.isNaN(Number(value));
156
+ type.isInt = (value)=>Number.isInteger(value) === true;
157
+ type.isSet = (value)=>kindOf(value) === 'set';
158
+ type.isNull = (value)=>kindOf(value) === 'null';
159
+ type.isUndefined = (value)=>kindOf(value) === 'undefined';
160
+ type.isNone = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null';
161
+ type.isPrimitive = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null' || kindOf(value) === 'string' || kindOf(value) === 'number' || kindOf(value) === 'boolean' || kindOf(value) === 'date';
162
+ type.isEmptyObject = (value)=>kindOf(value) === 'object' && Object.keys(value).length === 0;
177
163
  // Lowdefy operator types
178
164
  function isName(value) {
179
165
  if (!type.isString(value)) return false;
180
- const noLeadingNumeric = value.split('.').reduce((acc, val)=>acc && !type.isNumeric(val.charAt(0))
181
- , true);
166
+ const noLeadingNumeric = value.split('.').reduce((acc, val)=>acc && !type.isNumeric(val.charAt(0)), true);
182
167
  const noLeadTrailStop = value.charAt(0) !== '.' && value.charAt(value.length - 1) !== '.';
183
168
  const noLowdefy = !value.toLowerCase().startsWith('lowdefy');
184
169
  return /^[a-zA-Z0-9_.]+$/g.test(value) && noLeadTrailStop && noLeadingNumeric && noLowdefy;
package/dist/unset.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/urlQuery.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/wait.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ async function wait(ms) {
16
- return new Promise((resolve)=>setTimeout(resolve, ms)
17
- );
16
+ return new Promise((resolve)=>setTimeout(resolve, ms));
18
17
  }
19
18
  export default wait;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lowdefy/helpers",
3
- "version": "4.0.0-alpha.8",
4
- "licence": "Apache-2.0",
3
+ "version": "4.0.0-rc.0",
4
+ "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
7
7
  "keywords": [
@@ -31,25 +31,24 @@
31
31
  "dist/*"
32
32
  ],
33
33
  "scripts": {
34
- "build": "yarn swc",
34
+ "build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
35
35
  "clean": "rm -rf dist",
36
- "prepare": "yarn build",
37
- "swc": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
36
+ "prepublishOnly": "pnpm build",
38
37
  "test": "jest --coverage"
39
38
  },
40
39
  "dependencies": {
41
40
  "lodash.merge": "4.6.2",
42
- "query-string": "7.1.0"
41
+ "query-string": "7.1.1"
43
42
  },
44
43
  "devDependencies": {
45
- "@swc/cli": "0.1.55",
46
- "@swc/core": "1.2.135",
47
- "@swc/jest": "0.2.17",
48
- "jest": "27.5.1",
49
- "jest-diff": "27.5.1"
44
+ "@swc/cli": "0.1.57",
45
+ "@swc/core": "1.2.194",
46
+ "@swc/jest": "0.2.21",
47
+ "jest": "28.1.0",
48
+ "jest-diff": "28.1.0"
50
49
  },
51
50
  "publishConfig": {
52
51
  "access": "public"
53
52
  },
54
- "gitHead": "9d56b83cf45e868afe3a1eeba750fe826eb74c8c"
53
+ "gitHead": "f6872d7ff6da421710096536fce7b2016ef8f35c"
55
54
  }