@jdeighan/coffee-utils 14.0.10 → 14.0.12
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -3
- package/src/browser.coffee +14 -0
- package/src/browser.js +14 -1
- package/src/fs.coffee +4 -16
- package/src/fs.js +5 -18
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "14.0.
|
4
|
+
"version": "14.0.12",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -49,13 +49,13 @@
|
|
49
49
|
},
|
50
50
|
"homepage": "https://github.com/johndeighan/coffee-utils#readme",
|
51
51
|
"dependencies": {
|
52
|
-
"@jdeighan/base-utils": "^4.0.
|
52
|
+
"@jdeighan/base-utils": "^4.0.6",
|
53
53
|
"cross-env": "^7.0.3",
|
54
54
|
"n-readlines": "^1.0.1",
|
55
55
|
"readline-sync": "^1.4.10",
|
56
56
|
"svelte": "^3.55.0"
|
57
57
|
},
|
58
58
|
"devDependencies": {
|
59
|
-
"@jdeighan/unit-tester": "^3.0.
|
59
|
+
"@jdeighan/unit-tester": "^3.0.23"
|
60
60
|
}
|
61
61
|
}
|
package/src/browser.coffee
CHANGED
@@ -35,3 +35,17 @@ export localStore = (key, value=undef) =>
|
|
35
35
|
if defined(value)
|
36
36
|
return JSON.parse(localStorage.getItem(key))
|
37
37
|
return undef
|
38
|
+
|
39
|
+
# ---------------------------------------------------------------------------
|
40
|
+
|
41
|
+
storeKey = 'hPrefs'
|
42
|
+
export hPrefs = localStore(storeKey) || {}
|
43
|
+
|
44
|
+
# ---------------------------------------------------------------------------
|
45
|
+
|
46
|
+
export setPref = (key, value) =>
|
47
|
+
|
48
|
+
hPrefs[key] = value
|
49
|
+
localStore storeKey, hPrefs
|
50
|
+
|
51
|
+
# ---------------------------------------------------------------------------
|
package/src/browser.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
2
|
// browser.coffee
|
3
|
-
var audio;
|
3
|
+
var audio, storeKey;
|
4
4
|
|
5
5
|
import {
|
6
6
|
undef,
|
@@ -44,3 +44,16 @@ export var localStore = (key, value = undef) => {
|
|
44
44
|
}
|
45
45
|
return undef;
|
46
46
|
};
|
47
|
+
|
48
|
+
// ---------------------------------------------------------------------------
|
49
|
+
storeKey = 'hPrefs';
|
50
|
+
|
51
|
+
export var hPrefs = localStore(storeKey) || {};
|
52
|
+
|
53
|
+
// ---------------------------------------------------------------------------
|
54
|
+
export var setPref = (key, value) => {
|
55
|
+
hPrefs[key] = value;
|
56
|
+
return localStore(storeKey, hPrefs);
|
57
|
+
};
|
58
|
+
|
59
|
+
// ---------------------------------------------------------------------------
|
package/src/fs.coffee
CHANGED
@@ -242,17 +242,13 @@ export barf = (filepath, contents) =>
|
|
242
242
|
# ---------------------------------------------------------------------------
|
243
243
|
# withExt - change file extention in a file name
|
244
244
|
|
245
|
-
export withExt = (path, newExt
|
246
|
-
# --- Valid options:
|
247
|
-
# removeLeadingUnderScore - boolean
|
245
|
+
export withExt = (path, newExt) =>
|
248
246
|
|
249
247
|
assert newExt, "withExt(): No newExt provided"
|
250
248
|
if newExt.indexOf('.') != 0
|
251
249
|
newExt = '.' + newExt
|
252
250
|
|
253
251
|
{dir, name, ext} = pathlib.parse(path)
|
254
|
-
if hOptions.removeLeadingUnderScore && (name.indexOf('_')==0)
|
255
|
-
name = name.substr(1)
|
256
252
|
return mkpath(dir, "#{name}#{newExt}")
|
257
253
|
|
258
254
|
# ---------------------------------------------------------------------------
|
@@ -261,12 +257,12 @@ export withExt = (path, newExt, hOptions={}) =>
|
|
261
257
|
export removeFileWithExt = (path, newExt, hOptions={}) =>
|
262
258
|
# --- Valid options:
|
263
259
|
# doLog
|
264
|
-
# removeLeadingUnderScore
|
265
260
|
|
266
|
-
|
261
|
+
{doLog} = getOptions(hOptions)
|
262
|
+
fullpath = withExt(path, newExt)
|
267
263
|
try
|
268
264
|
fs.unlinkSync fullpath
|
269
|
-
if
|
265
|
+
if doLog
|
270
266
|
LOG " unlink #{filename}"
|
271
267
|
success = true
|
272
268
|
catch err
|
@@ -274,14 +270,6 @@ export removeFileWithExt = (path, newExt, hOptions={}) =>
|
|
274
270
|
success = false
|
275
271
|
return success
|
276
272
|
|
277
|
-
# ---------------------------------------------------------------------------
|
278
|
-
# withUnderScore - add '_' to file name
|
279
|
-
|
280
|
-
export withUnderScore = (path) =>
|
281
|
-
|
282
|
-
{dir, base} = pathlib.parse(path)
|
283
|
-
return mkpath(dir, "_#{base}")
|
284
|
-
|
285
273
|
# ---------------------------------------------------------------------------
|
286
274
|
|
287
275
|
isSystemDir = (dir) ->
|
package/src/fs.js
CHANGED
@@ -284,32 +284,27 @@ export var barf = (filepath, contents) => {
|
|
284
284
|
|
285
285
|
// ---------------------------------------------------------------------------
|
286
286
|
// withExt - change file extention in a file name
|
287
|
-
export var withExt = (path, newExt
|
287
|
+
export var withExt = (path, newExt) => {
|
288
288
|
var dir, ext, name;
|
289
|
-
// --- Valid options:
|
290
|
-
// removeLeadingUnderScore - boolean
|
291
289
|
assert(newExt, "withExt(): No newExt provided");
|
292
290
|
if (newExt.indexOf('.') !== 0) {
|
293
291
|
newExt = '.' + newExt;
|
294
292
|
}
|
295
293
|
({dir, name, ext} = pathlib.parse(path));
|
296
|
-
if (hOptions.removeLeadingUnderScore && (name.indexOf('_') === 0)) {
|
297
|
-
name = name.substr(1);
|
298
|
-
}
|
299
294
|
return mkpath(dir, `${name}${newExt}`);
|
300
295
|
};
|
301
296
|
|
302
297
|
// ---------------------------------------------------------------------------
|
303
298
|
// removeFileWithExt - remove file with different ext
|
304
299
|
export var removeFileWithExt = (path, newExt, hOptions = {}) => {
|
305
|
-
var err, fullpath, success;
|
300
|
+
var doLog, err, fullpath, success;
|
306
301
|
// --- Valid options:
|
307
302
|
// doLog
|
308
|
-
|
309
|
-
fullpath = withExt(path, newExt
|
303
|
+
({doLog} = getOptions(hOptions));
|
304
|
+
fullpath = withExt(path, newExt);
|
310
305
|
try {
|
311
306
|
fs.unlinkSync(fullpath);
|
312
|
-
if (
|
307
|
+
if (doLog) {
|
313
308
|
LOG(` unlink ${filename}`);
|
314
309
|
}
|
315
310
|
success = true;
|
@@ -321,14 +316,6 @@ export var removeFileWithExt = (path, newExt, hOptions = {}) => {
|
|
321
316
|
return success;
|
322
317
|
};
|
323
318
|
|
324
|
-
// ---------------------------------------------------------------------------
|
325
|
-
// withUnderScore - add '_' to file name
|
326
|
-
export var withUnderScore = (path) => {
|
327
|
-
var base, dir;
|
328
|
-
({dir, base} = pathlib.parse(path));
|
329
|
-
return mkpath(dir, `_${base}`);
|
330
|
-
};
|
331
|
-
|
332
319
|
// ---------------------------------------------------------------------------
|
333
320
|
isSystemDir = function(dir) {
|
334
321
|
return dir === '$Recycle.Bin' || dir === '$WinREAgent';
|