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/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.101",
4
+ "version": "2001.1.102",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
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)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.101",
4
+ "version": "2001.1.102",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",