utilitas 2001.1.101 → 2001.1.102
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/dist/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/manifest.mjs +1 -1
- package/lib/utilitas.mjs +6 -2
- package/package.json +1 -1
package/lib/manifest.mjs
CHANGED
package/lib/utilitas.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { assertPath, decodeBase64DataURL, readJson } from './storage.mjs';
|
|
|
8
8
|
|
|
9
9
|
const call = (f, ...a) => promisify(Array.isArray(f) ? f[0].bind(f[1]) : f)(...a);
|
|
10
10
|
const invalidTime = 'Invalid time.';
|
|
11
|
-
const [Chrome, Edge] = ['Chrome', 'Edge'];
|
|
11
|
+
const [Chrome, Edge, LOCKS] = ['Chrome', 'Edge', {}];
|
|
12
12
|
const getDateByUnixTimestamp = timestamp => new Date(~~timestamp * 1000);
|
|
13
13
|
const getUnixTimestampByDate = date => Math.round(date.getTime() / 1000);
|
|
14
14
|
const getRandomInt = max => Math.floor(Math.random() * Math.floor(max));
|
|
@@ -46,7 +46,6 @@ const modules = {};
|
|
|
46
46
|
const defaultName = filename => String(filename || __filename);
|
|
47
47
|
const basename = f => _basename(defaultName(f)).replace(/\.[^\.]*$/, '').trim();
|
|
48
48
|
const checkChance = chance => Math.random() < 1 / (~~chance || 100);
|
|
49
|
-
const [LOCKS, getLockKey] = [{}, key => `LOCK_${key}`];
|
|
50
49
|
const unlock = (key) => delete LOCKS[getLockKey(key)];
|
|
51
50
|
|
|
52
51
|
const timeEmojis = {
|
|
@@ -845,6 +844,11 @@ const reverseKeyValues = obj => Object.fromEntries(
|
|
|
845
844
|
Object.entries(obj).map(x => x.reverse())
|
|
846
845
|
);
|
|
847
846
|
|
|
847
|
+
const getLockKey = key => {
|
|
848
|
+
assert(key, 'Invalid lock key.', 500);
|
|
849
|
+
return `LOCK_${key}`;
|
|
850
|
+
};
|
|
851
|
+
|
|
848
852
|
const lock = async (key, options) => {
|
|
849
853
|
key = getLockKey(key);
|
|
850
854
|
while (new Date().getTime() - parseInt(LOCKS?.[key] || 0)
|