utilitas 2001.1.100 → 2001.1.101

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.100",
4
+ "version": "2001.1.101",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/utilitas.mjs CHANGED
@@ -46,6 +46,8 @@ 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
+ const unlock = (key) => delete LOCKS[getLockKey(key)];
49
51
 
50
52
  const timeEmojis = {
51
53
  '00:00': '🕛', '00:30': '🕧', '01:00': '🕐', '01:30': '🕜', '02:00': '🕑',
@@ -843,6 +845,15 @@ const reverseKeyValues = obj => Object.fromEntries(
843
845
  Object.entries(obj).map(x => x.reverse())
844
846
  );
845
847
 
848
+ const lock = async (key, options) => {
849
+ key = getLockKey(key);
850
+ while (new Date().getTime() - parseInt(LOCKS?.[key] || 0)
851
+ < (options?.timeout || 1000)) {
852
+ await timeout(options?.checkInterval || 1000);
853
+ }
854
+ return (LOCKS[key] = new Date().getTime());
855
+ };
856
+
846
857
  export {
847
858
  __,
848
859
  analyzeModule,
@@ -915,6 +926,7 @@ export {
915
926
  lastItem,
916
927
  lineSplit,
917
928
  locate,
929
+ lock,
918
930
  log,
919
931
  makeStringByLength,
920
932
  mapKeys,
@@ -948,6 +960,7 @@ export {
948
960
  trim,
949
961
  tryUntil,
950
962
  uniqueArray,
963
+ unlock,
951
964
  verifyEmail,
952
965
  verifyPhone,
953
966
  verifyUrl,
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.100",
4
+ "version": "2001.1.101",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",