@aeriajs/common 0.0.23 → 0.0.25

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.
@@ -1,8 +1,7 @@
1
- export var arraysIntersects = function(subject, arr) {
2
- if (!arr) {
3
- return false;
4
- }
5
- return Array.isArray(subject) ? subject.some(function(e) {
6
- return arr.includes(e);
7
- }) : arr.includes(subject);
1
+ "use strict";
2
+ export const arraysIntersects = (subject, arr) => {
3
+ if (!arr) {
4
+ return false;
5
+ }
6
+ return Array.isArray(subject) ? subject.some((e) => arr.includes(e)) : arr.includes(subject);
8
7
  };
@@ -1,6 +1,7 @@
1
- export var checkForUndefined = function(property, propertyName, what) {
2
- if (property.readOnly || property.isTimestamp) {
3
- return false;
4
- }
5
- return what[propertyName] === null || what[propertyName] === undefined || what[propertyName] === "";
1
+ "use strict";
2
+ export const checkForUndefined = (property, propertyName, what) => {
3
+ if (property.readOnly || property.isTimestamp) {
4
+ return false;
5
+ }
6
+ return what[propertyName] === null || what[propertyName] === void 0 || what[propertyName] === "";
6
7
  };
@@ -1,72 +1,57 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
1
+ "use strict";
14
2
  import { getValueFromPath } from "./getValueFromPath.mjs";
15
- var convertExpression = function(condition, subject) {
16
- var term2 = "term2" in condition ? typeof condition.term2 === "string" && condition.term2.startsWith("$.") ? getValueFromPath(subject, condition.term2.split("$.")[1]) : condition.term2 : null;
17
- switch(condition.operator){
18
- case "truthy":
19
- return {
20
- $ne: [
21
- null,
22
- undefined
23
- ]
24
- };
25
- case "equal":
26
- return term2;
27
- case "gt":
28
- return {
29
- $gt: term2
30
- };
31
- case "lt":
32
- return {
33
- $lt: term2
34
- };
35
- case "gte":
36
- return {
37
- $gte: term2
38
- };
39
- case "lte":
40
- return {
41
- $lte: term2
42
- };
43
- case "in":
44
- {
45
- return Array.isArray(term2) ? {
46
- $in: term2
47
- } : term2;
48
- }
3
+ const convertExpression = (condition, subject) => {
4
+ const term2 = "term2" in condition ? typeof condition.term2 === "string" && condition.term2.startsWith("$.") ? getValueFromPath(subject, condition.term2.split("$.")[1]) : condition.term2 : null;
5
+ switch (condition.operator) {
6
+ case "truthy":
7
+ return {
8
+ $ne: [
9
+ null,
10
+ void 0
11
+ ]
12
+ };
13
+ case "equal":
14
+ return term2;
15
+ case "gt":
16
+ return {
17
+ $gt: term2
18
+ };
19
+ case "lt":
20
+ return {
21
+ $lt: term2
22
+ };
23
+ case "gte":
24
+ return {
25
+ $gte: term2
26
+ };
27
+ case "lte":
28
+ return {
29
+ $lte: term2
30
+ };
31
+ case "in": {
32
+ return Array.isArray(term2) ? {
33
+ $in: term2
34
+ } : term2;
49
35
  }
36
+ }
50
37
  };
51
- export var convertConditionToQuery = function(condition, subject) {
52
- if ("or" in condition) {
53
- return {
54
- $or: condition.or.map(function(sub) {
55
- return convertConditionToQuery(sub, subject);
56
- })
57
- };
58
- }
59
- if ("and" in condition) {
60
- return {
61
- $and: condition.and.map(function(sub) {
62
- return convertConditionToQuery(sub, subject);
63
- })
64
- };
65
- }
66
- if ("not" in condition) {
67
- return {
68
- $not: convertConditionToQuery(condition.not, subject)
69
- };
70
- }
71
- return _define_property({}, condition.term1, convertExpression(condition, subject));
38
+ export const convertConditionToQuery = (condition, subject) => {
39
+ if ("or" in condition) {
40
+ return {
41
+ $or: condition.or.map((sub) => convertConditionToQuery(sub, subject))
42
+ };
43
+ }
44
+ if ("and" in condition) {
45
+ return {
46
+ $and: condition.and.map((sub) => convertConditionToQuery(sub, subject))
47
+ };
48
+ }
49
+ if ("not" in condition) {
50
+ return {
51
+ $not: convertConditionToQuery(condition.not, subject)
52
+ };
53
+ }
54
+ return {
55
+ [condition.term1]: convertExpression(condition, subject)
56
+ };
72
57
  };
package/dist/date.mjs CHANGED
@@ -1,101 +1,36 @@
1
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _array_with_holes(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function _instanceof(left, right) {
10
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
11
- return !!right[Symbol.hasInstance](left);
12
- } else {
13
- return left instanceof right;
14
- }
15
- }
16
- function _iterable_to_array_limit(arr, i) {
17
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
18
- if (_i == null) return;
19
- var _arr = [];
20
- var _n = true;
21
- var _d = false;
22
- var _s, _e;
23
- try {
24
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
25
- _arr.push(_s.value);
26
- if (i && _arr.length === i) break;
27
- }
28
- } catch (err) {
29
- _d = true;
30
- _e = err;
31
- } finally{
32
- try {
33
- if (!_n && _i["return"] != null) _i["return"]();
34
- } finally{
35
- if (_d) throw _e;
36
- }
37
- }
38
- return _arr;
39
- }
40
- function _non_iterable_rest() {
41
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
42
- }
43
- function _sliced_to_array(arr, i) {
44
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
45
- }
46
- function _unsupported_iterable_to_array(o, minLen) {
47
- if (!o) return;
48
- if (typeof o === "string") return _array_like_to_array(o, minLen);
49
- var n = Object.prototype.toString.call(o).slice(8, -1);
50
- if (n === "Object" && o.constructor) n = o.constructor.name;
51
- if (n === "Map" || n === "Set") return Array.from(n);
52
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
53
- }
54
- var rtf = new Intl.RelativeTimeFormat(undefined, {
55
- numeric: "auto"
1
+ "use strict";
2
+ const rtf = new Intl.RelativeTimeFormat(void 0, {
3
+ numeric: "auto"
56
4
  });
57
- var units = {
58
- year: 31536000000,
59
- month: 2628000000,
60
- day: 86400000,
61
- hour: 3600000,
62
- minute: 6000,
63
- second: 1000
5
+ const units = {
6
+ year: 31536e6,
7
+ month: 2628e6,
8
+ day: 864e5,
9
+ hour: 36e5,
10
+ minute: 6e3,
11
+ second: 1e3
64
12
  };
65
- export var formatDateTime = function formatDateTime(date, options) {
66
- var target = _instanceof(date, Date) ? date : new Date(date);
67
- if (isNaN(target.getDate())) {
68
- return "-";
69
- }
70
- var _ref = options || {}, hours = _ref.hours, hoursOnly = _ref.hoursOnly, _ref_locale = _ref.locale, locale = _ref_locale === void 0 ? "navigator" in globalThis ? navigator.language : "en-US" : _ref_locale;
71
- if (hoursOnly) {
72
- return target.toLocaleTimeString();
73
- }
74
- return hours ? target.toLocaleString(locale) : target.toLocaleDateString(locale);
13
+ export const formatDateTime = function(date, options) {
14
+ const target = date instanceof Date ? date : new Date(date);
15
+ if (isNaN(target.getDate())) {
16
+ return "-";
17
+ }
18
+ const {
19
+ hours,
20
+ hoursOnly,
21
+ locale = "navigator" in globalThis ? navigator.language : "en-US"
22
+ } = options || {};
23
+ if (hoursOnly) {
24
+ return target.toLocaleTimeString();
25
+ }
26
+ return hours ? target.toLocaleString(locale) : target.toLocaleDateString(locale);
75
27
  };
76
- export var getRelativeTimeFromNow = function getRelativeTimeFromNow(target) {
77
- var now = new Date();
78
- var elapsed = now - target;
79
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
80
- try {
81
- for(var _iterator = Object.entries(units)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
82
- var _step_value = _sliced_to_array(_step.value, 2), u = _step_value[0], value = _step_value[1];
83
- if (Math.abs(elapsed) > value || u === "second") {
84
- return rtf.format(-1 * Math.round(elapsed / value), u);
85
- }
86
- }
87
- } catch (err) {
88
- _didIteratorError = true;
89
- _iteratorError = err;
90
- } finally{
91
- try {
92
- if (!_iteratorNormalCompletion && _iterator.return != null) {
93
- _iterator.return();
94
- }
95
- } finally{
96
- if (_didIteratorError) {
97
- throw _iteratorError;
98
- }
99
- }
28
+ export const getRelativeTimeFromNow = function(target) {
29
+ const now = /* @__PURE__ */ new Date();
30
+ const elapsed = now - target;
31
+ for (const [u, value] of Object.entries(units)) {
32
+ if (Math.abs(elapsed) > value || u === "second") {
33
+ return rtf.format(-1 * Math.round(elapsed / value), u);
100
34
  }
35
+ }
101
36
  };
@@ -1,3 +1,4 @@
1
- export var deepClone = function(obj) {
2
- return typeof structuredClone === "function" && typeof window === "undefined" ? structuredClone(obj) : JSON.parse(JSON.stringify(obj));
1
+ "use strict";
2
+ export const deepClone = (obj) => {
3
+ return typeof structuredClone === "function" && typeof window === "undefined" ? structuredClone(obj) : JSON.parse(JSON.stringify(obj));
3
4
  };
@@ -1,66 +1,34 @@
1
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _array_without_holes(arr) {
7
- if (Array.isArray(arr)) return _array_like_to_array(arr);
8
- }
9
- function _instanceof(left, right) {
10
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
11
- return !!right[Symbol.hasInstance](left);
12
- } else {
13
- return left instanceof right;
1
+ "use strict";
2
+ export const deepMerge = (left, right, options) => {
3
+ const result = Object.assign({}, left);
4
+ const { arrays = true } = options || {};
5
+ for (const key in right) {
6
+ const leftVal = result[key];
7
+ const rightVal = right[key];
8
+ if (options?.callback) {
9
+ const res = options.callback(key, leftVal, rightVal);
10
+ if (res !== void 0) {
11
+ result[key] = res;
12
+ continue;
13
+ }
14
14
  }
15
- }
16
- function _iterable_to_array(iter) {
17
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
18
- }
19
- function _non_iterable_spread() {
20
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
21
- }
22
- function _to_consumable_array(arr) {
23
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
24
- }
25
- function _unsupported_iterable_to_array(o, minLen) {
26
- if (!o) return;
27
- if (typeof o === "string") return _array_like_to_array(o, minLen);
28
- var n = Object.prototype.toString.call(o).slice(8, -1);
29
- if (n === "Object" && o.constructor) n = o.constructor.name;
30
- if (n === "Map" || n === "Set") return Array.from(n);
31
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
32
- }
33
- export var deepMerge = function(left, right, options) {
34
- var result = Object.assign({}, left);
35
- var _ref = options || {}, _ref_arrays = _ref.arrays, arrays = _ref_arrays === void 0 ? true : _ref_arrays;
36
- for(var key in right){
37
- var leftVal = result[key];
38
- var rightVal = right[key];
39
- if (options === null || options === void 0 ? void 0 : options.callback) {
40
- var res = options.callback(key, leftVal, rightVal);
41
- if (res !== undefined) {
42
- result[key] = res;
43
- continue;
44
- }
45
- }
46
- if (Array.isArray(leftVal) && Array.isArray(rightVal)) {
47
- var _result_key;
48
- result[key] = arrays ? (_result_key = result[key]).concat.apply(_result_key, _to_consumable_array(rightVal)) : rightVal;
49
- continue;
50
- }
51
- if (_instanceof(rightVal, Function)) {
52
- result[key] = rightVal;
53
- continue;
54
- }
55
- if (_instanceof(leftVal, Object) && _instanceof(rightVal, Object)) {
56
- if (rightVal.constructor !== Object) {
57
- result[key] = rightVal;
58
- continue;
59
- }
60
- result[key] = deepMerge(leftVal, rightVal, options);
61
- continue;
62
- }
15
+ if (Array.isArray(leftVal) && Array.isArray(rightVal)) {
16
+ result[key] = arrays ? result[key].concat(...rightVal) : rightVal;
17
+ continue;
18
+ }
19
+ if (rightVal instanceof Function) {
20
+ result[key] = rightVal;
21
+ continue;
22
+ }
23
+ if (leftVal instanceof Object && rightVal instanceof Object) {
24
+ if (rightVal.constructor !== Object) {
63
25
  result[key] = rightVal;
26
+ continue;
27
+ }
28
+ result[key] = deepMerge(leftVal, rightVal, options);
29
+ continue;
64
30
  }
65
- return result;
31
+ result[key] = rightVal;
32
+ }
33
+ return result;
66
34
  };
@@ -1,145 +1,12 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- function _ts_generator(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1) throw t[1];
35
- return t[1];
36
- },
37
- trys: [],
38
- ops: []
39
- };
40
- return g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
- return this;
46
- }), g;
47
- function verb(n) {
48
- return function(v) {
49
- return step([
50
- n,
51
- v
52
- ]);
53
- };
54
- }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
58
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
- if (y = 0, t) op = [
60
- op[0] & 2,
61
- t.value
62
- ];
63
- switch(op[0]){
64
- case 0:
65
- case 1:
66
- t = op;
67
- break;
68
- case 4:
69
- _.label++;
70
- return {
71
- value: op[1],
72
- done: false
73
- };
74
- case 5:
75
- _.label++;
76
- y = op[1];
77
- op = [
78
- 0
79
- ];
80
- continue;
81
- case 7:
82
- op = _.ops.pop();
83
- _.trys.pop();
84
- continue;
85
- default:
86
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
- _ = 0;
88
- continue;
89
- }
90
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
- _.label = op[1];
92
- break;
93
- }
94
- if (op[0] === 6 && _.label < t[1]) {
95
- _.label = t[1];
96
- t = op;
97
- break;
98
- }
99
- if (t && _.label < t[2]) {
100
- _.label = t[2];
101
- _.ops.push(op);
102
- break;
103
- }
104
- if (t[2]) _.ops.pop();
105
- _.trys.pop();
106
- continue;
107
- }
108
- op = body.call(thisArg, _);
109
- } catch (e) {
110
- op = [
111
- 6,
112
- e
113
- ];
114
- y = 0;
115
- } finally{
116
- f = t = 0;
117
- }
118
- if (op[0] & 5) throw op[1];
119
- return {
120
- value: op[0] ? op[1] : void 0,
121
- done: true
122
- };
123
- }
124
- }
125
- export var dynamicImport = function() {
126
- var _ref = _async_to_generator(function(path) {
127
- var fn;
128
- return _ts_generator(this, function(_state) {
129
- try {
130
- return [
131
- 2,
132
- require(path)
133
- ];
134
- } catch (err) {}
135
- fn = new Function("return (async () => {\n const { pathToFileURL } = await import('url')\n return import(pathToFileURL('".concat(path.replace(/\\/g, "\\\\"), "'))\n })()"));
136
- return [
137
- 2,
138
- fn()
139
- ];
140
- });
141
- });
142
- return function dynamicImport(path) {
143
- return _ref.apply(this, arguments);
144
- };
145
- }();
1
+ "use strict";
2
+ export const dynamicImport = async (path) => {
3
+ try {
4
+ return require(path);
5
+ } catch (err) {
6
+ }
7
+ const fn = new Function(`return (async () => {
8
+ const { pathToFileURL } = await import('url')
9
+ return import(pathToFileURL('${path.replace(/\\/g, "\\\\")}'))
10
+ })()`);
11
+ return fn();
12
+ };
package/dist/either.mjs CHANGED
@@ -1,32 +1,29 @@
1
- export var left = function(value) {
2
- return {
3
- _tag: "Left",
4
- value: value
5
- };
1
+ "use strict";
2
+ export const left = (value) => ({
3
+ _tag: "Left",
4
+ value
5
+ });
6
+ export const right = (value) => ({
7
+ _tag: "Right",
8
+ value
9
+ });
10
+ export const isLeft = (either) => {
11
+ return either._tag === "Left";
6
12
  };
7
- export var right = function(value) {
8
- return {
9
- _tag: "Right",
10
- value: value
11
- };
13
+ export const isRight = (either) => {
14
+ return either._tag === "Right";
12
15
  };
13
- export var isLeft = function(either) {
14
- return either._tag === "Left";
16
+ export const unwrapEither = (either) => {
17
+ return either.value;
15
18
  };
16
- export var isRight = function(either) {
17
- return either._tag === "Right";
18
- };
19
- export var unwrapEither = function(either) {
20
- return either.value;
21
- };
22
- export var error = left;
23
- export var ok = right;
24
- export var unsafe = function(either, message) {
25
- if (either._tag !== "Right") {
26
- if (process.env.NODE_ENV !== "production") {
27
- console.trace(JSON.stringify(either.value, null, 2));
28
- }
29
- throw new Error("unsafe threw: ".concat(either.value, " (").concat(message || "-", ")"));
19
+ export const error = left;
20
+ export const ok = right;
21
+ export const unsafe = (either, message) => {
22
+ if (either._tag !== "Right") {
23
+ if (true) {
24
+ console.trace(JSON.stringify(either.value, null, 2));
30
25
  }
31
- return either.value;
26
+ throw new Error(`unsafe threw: ${either.value} (${message || "-"})`);
27
+ }
28
+ return either.value;
32
29
  };