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/README.md +2 -0
- 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 +13 -0
- package/package.json +1 -1
package/lib/manifest.mjs
CHANGED
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,
|