-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
80 lines (80 loc) · 2.6 KB
/
utils.js
File metadata and controls
80 lines (80 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
exports.__esModule = true;
exports.noop = function () { };
exports.identity = function (x) { return x; };
exports.assign = function (tar, src) {
// @ts-ignore
for (var k in src)
tar[k] = src[k];
return tar;
};
exports.isPromise = function (value) {
return value && typeof value === 'object' && typeof value.then === 'function';
};
exports.run = function (callback) {
return callback();
};
exports.blankObject = function () {
return Object.create(null);
};
exports.runAll = function (fns) {
fns.forEach(exports.run);
};
exports.isFunction = function (thing) {
return typeof thing === 'function';
};
exports.safeNotEqual = function (a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
};
exports.notEqual = function (a, b) {
return a != a ? b == b : a !== b;
};
exports.isEmpty = function (obj) {
return Object.keys(obj).length === 0;
};
exports.validateStore = function (store, name) {
if (store != null && typeof store.subscribe !== 'function')
throw new Error("'" + name + "' is not a store with a 'subscribe' method");
};
exports.subscribe = function (store) {
var callbacks = [];
for (var _i = 1; _i < arguments.length; _i++) {
callbacks[_i - 1] = arguments[_i];
}
if (store == null)
return exports.noop;
var unsub = store.subscribe.apply(store, callbacks);
return unsub.unsubscribe ? function () { return unsub.unsubscribe(); } : unsub;
};
exports.getStoreValue = function (store) {
var value;
exports.subscribe(store, function (_) { return value = _; })();
return value;
};
exports.once = function (fn) {
var ran = false;
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (ran)
return;
ran = true;
fn.call.apply(fn, __spreadArrays([this], args));
};
};
exports.nullToEmpty = function (value) {
return value == null ? '' : value;
};
exports.hasProp = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); };
exports.actionDestroyer = function (action_result) {
return action_result && exports.isFunction(action_result.destroy) ? action_result.destroy : exports.noop;
};