@react-fabric/utilities 1.0.0-beta.0
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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/cjs/_ascii.js +76 -0
- package/dist/cjs/_boundingBox.js +59 -0
- package/dist/cjs/_countries.js +2805 -0
- package/dist/cjs/_debounce.js +53 -0
- package/dist/cjs/_dedupe.js +63 -0
- package/dist/cjs/_fetch.js +128 -0
- package/dist/cjs/_fileType.js +967 -0
- package/dist/cjs/_format.js +118 -0
- package/dist/cjs/_getByPath.js +125 -0
- package/dist/cjs/_hash.js +67 -0
- package/dist/cjs/_interpolate.js +47 -0
- package/dist/cjs/_isEqual.js +108 -0
- package/dist/cjs/_isType.js +98 -0
- package/dist/cjs/_mergeRefs.js +40 -0
- package/dist/cjs/_tokenize.js +67 -0
- package/dist/cjs/getImageColorset.js +70 -0
- package/dist/cjs/index.js +116 -0
- package/dist/cjs/useLogger.js +339 -0
- package/dist/cjs/yup.js +172 -0
- package/dist/esm/_ascii.js +76 -0
- package/dist/esm/_boundingBox.js +58 -0
- package/dist/esm/_countries.js +2805 -0
- package/dist/esm/_debounce.js +53 -0
- package/dist/esm/_dedupe.js +60 -0
- package/dist/esm/_fetch.js +128 -0
- package/dist/esm/_fileType.js +967 -0
- package/dist/esm/_format.js +120 -0
- package/dist/esm/_getByPath.js +124 -0
- package/dist/esm/_hash.js +65 -0
- package/dist/esm/_interpolate.js +46 -0
- package/dist/esm/_isEqual.js +106 -0
- package/dist/esm/_isType.js +85 -0
- package/dist/esm/_mergeRefs.js +40 -0
- package/dist/esm/_tokenize.js +66 -0
- package/dist/esm/getImageColorset.js +70 -0
- package/dist/esm/index.js +52 -0
- package/dist/esm/useLogger.js +339 -0
- package/dist/esm/yup.js +152 -0
- package/dist/types/_ascii.d.ts +5 -0
- package/dist/types/_boundingBox.d.ts +10 -0
- package/dist/types/_countries.d.ts +85 -0
- package/dist/types/_debounce.d.ts +8 -0
- package/dist/types/_dedupe.d.ts +4 -0
- package/dist/types/_fetch.d.ts +23 -0
- package/dist/types/_fileType.d.ts +926 -0
- package/dist/types/_format.d.ts +27 -0
- package/dist/types/_getByPath.d.ts +10 -0
- package/dist/types/_hash.d.ts +16 -0
- package/dist/types/_interpolate.d.ts +6 -0
- package/dist/types/_isEqual.d.ts +15 -0
- package/dist/types/_isType.d.ts +14 -0
- package/dist/types/_mergeRefs.d.ts +1 -0
- package/dist/types/_tokenize.d.ts +8 -0
- package/dist/types/getImageColorset.d.ts +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/useLogger.d.ts +25 -0
- package/dist/types/yup.d.ts +1 -0
- package/package.json +48 -0
- package/src/_ascii.ts +93 -0
- package/src/_boundingBox.ts +72 -0
- package/src/_countries.ts +3046 -0
- package/src/_debounce.ts +42 -0
- package/src/_dedupe.ts +56 -0
- package/src/_fetch.ts +109 -0
- package/src/_fileType.ts +993 -0
- package/src/_format.ts +141 -0
- package/src/_getByPath.ts +108 -0
- package/src/_hash.ts +62 -0
- package/src/_interpolate.ts +42 -0
- package/src/_isEqual.ts +102 -0
- package/src/_isType.ts +105 -0
- package/src/_mergeRefs.ts +33 -0
- package/src/_tokenize.ts +69 -0
- package/src/getImageColorset.ts +81 -0
- package/src/index.ts +51 -0
- package/src/useLogger.ts +304 -0
- package/src/yup.ts +75 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dateFns = require('date-fns');
|
|
4
|
+
var libphonenumberJs = require('libphonenumber-js');
|
|
5
|
+
var numeral = require('numeral');
|
|
6
|
+
var _countries = require('./_countries.js');
|
|
7
|
+
var _isType = require('./_isType.js');
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* React Fabric
|
|
11
|
+
* @version: 1.0.0
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* The MIT License (MIT)
|
|
15
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
18
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
19
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
20
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
21
|
+
* subject to the following conditions:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
24
|
+
* portions of the Software.
|
|
25
|
+
*
|
|
26
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
27
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
28
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
29
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
34
|
+
exports.Format = void 0;
|
|
35
|
+
(function (_Format) {
|
|
36
|
+
/** ***************** get phone number object using `libphonenumber-js` *******************/
|
|
37
|
+
var getPhone = function getPhone(value, country) {
|
|
38
|
+
var phone = value.match(/^[0+]/) != null ? value.replace(/^00/, "+") : "+".concat(value);
|
|
39
|
+
var number = libphonenumberJs.parsePhoneNumberFromString(phone, country);
|
|
40
|
+
/* istanbul ignore next */
|
|
41
|
+
return number !== null && number !== void 0 ? number : {
|
|
42
|
+
country: "",
|
|
43
|
+
formatInternational: function formatInternational() {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** ***************** common number format method using `numeral` *******************/
|
|
50
|
+
var numberFormat = function numberFormat(number) {
|
|
51
|
+
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "0,0[.]00a";
|
|
52
|
+
if (_isType.isNil(number)) {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
var prefix = "".concat(number).startsWith("+") ? "+" : "";
|
|
56
|
+
return prefix + numeral(number).format(format);
|
|
57
|
+
};
|
|
58
|
+
var makeDuration = function makeDuration(value) {
|
|
59
|
+
var fmt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "HH:mm:ss.SSS";
|
|
60
|
+
if (!isNaN(value)) {
|
|
61
|
+
var days = dateFns.differenceInDays(value, 0);
|
|
62
|
+
var prefix = days > 0 ? "".concat(days, "d:") : "";
|
|
63
|
+
var time = dateFns.format(dateFns.parseISO(new Date(value).toISOString().replace("Z", "")), fmt);
|
|
64
|
+
if (!prefix) time = time.replace(/^00:/, "");
|
|
65
|
+
return "".concat(prefix).concat(time);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** ***************** format phone number using `libphonenumber-js` *******************/
|
|
70
|
+
_Format.phone = function (value) {
|
|
71
|
+
var _phone$country;
|
|
72
|
+
var country = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "AE";
|
|
73
|
+
var useCss = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
74
|
+
if (_isType.isEmpty(value) || value.length < 6 || !/^[\d+\s\-()]+$/.test(value)) return value;
|
|
75
|
+
var phone = getPhone(value, country);
|
|
76
|
+
/* istanbul ignore next */
|
|
77
|
+
return "".concat(useCss ? "<span class=\"flag ".concat(phone.country, "\"></span>") : _countries.emoji((_phone$country = phone.country) !== null && _phone$country !== void 0 ? _phone$country : ""), " ").concat(phone.formatInternational());
|
|
78
|
+
};
|
|
79
|
+
_Format.number = function (number, format) {
|
|
80
|
+
return numberFormat(number, format);
|
|
81
|
+
};
|
|
82
|
+
_Format.bytes = function (number) {
|
|
83
|
+
return numberFormat(number, "0,0[.]00b");
|
|
84
|
+
};
|
|
85
|
+
_Format.percent = function (number) {
|
|
86
|
+
return numberFormat(number, "0,0[.]00%");
|
|
87
|
+
};
|
|
88
|
+
_Format.date = function (date) {
|
|
89
|
+
var fmt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "d-M-y";
|
|
90
|
+
return date ? dateFns.format(new Date(date), fmt) : "";
|
|
91
|
+
};
|
|
92
|
+
_Format.duration = function (number, isFraction) {
|
|
93
|
+
if (_isType.isNil(number)) {
|
|
94
|
+
return "00:00.000";
|
|
95
|
+
}
|
|
96
|
+
if (number === Infinity) {
|
|
97
|
+
return "∞";
|
|
98
|
+
}
|
|
99
|
+
var value = parseFloat("".concat(number)) * (isFraction ? 1000 : 1);
|
|
100
|
+
if (!isNaN(value)) {
|
|
101
|
+
return makeDuration(value);
|
|
102
|
+
}
|
|
103
|
+
return "00:00.000";
|
|
104
|
+
};
|
|
105
|
+
_Format.durationSeconds = function (number, isFraction) {
|
|
106
|
+
if (_isType.isNil(number)) {
|
|
107
|
+
return "00:00";
|
|
108
|
+
}
|
|
109
|
+
if (number === Infinity) {
|
|
110
|
+
return "∞";
|
|
111
|
+
}
|
|
112
|
+
var value = parseFloat("".concat(number)) * (isFraction ? 1000 : 1);
|
|
113
|
+
if (!isNaN(value)) {
|
|
114
|
+
return makeDuration(value, "HH:mm:ss");
|
|
115
|
+
}
|
|
116
|
+
return "00:00";
|
|
117
|
+
};
|
|
118
|
+
})(exports.Format || (exports.Format = {}));
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _isType = require('./_isType.js');
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
14
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
15
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
16
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
17
|
+
* subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
20
|
+
* portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
23
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
24
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
25
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
var _get = function _get(hit, field) {
|
|
29
|
+
/** ***************** return if object is empty *******************/
|
|
30
|
+
/* istanbul ignore next */
|
|
31
|
+
if (_isType.isNil(hit)) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
/** ***************** return object if property is empty *******************/
|
|
35
|
+
/* istanbul ignore next */
|
|
36
|
+
if (_isType.isNil(field)) {
|
|
37
|
+
return hit;
|
|
38
|
+
}
|
|
39
|
+
if (_isType.isObject(hit)) {
|
|
40
|
+
/** ***************** return value if object.property is not empty *******************/
|
|
41
|
+
if (!_isType.isNil(hit[field])) {
|
|
42
|
+
return hit[field];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** ***************** if property name contains `.` separator split to multiple property names *******************/
|
|
46
|
+
if (field.includes(".")) {
|
|
47
|
+
var currentValue = hit;
|
|
48
|
+
var path = field.split(".");
|
|
49
|
+
var _loop = function _loop() {
|
|
50
|
+
/** ***************** when property name is `a.b.c` iterate until property found in object. eg. `a`, `a.b` *******************/
|
|
51
|
+
var outerPath = path.slice(0, i).join(".");
|
|
52
|
+
|
|
53
|
+
/** ***************** join rest of property list *******************/
|
|
54
|
+
var innerPath = path.slice(i).join(".");
|
|
55
|
+
|
|
56
|
+
/** ***************** if current outer path found in object *******************/
|
|
57
|
+
if (outerPath in currentValue) {
|
|
58
|
+
currentValue = currentValue[outerPath];
|
|
59
|
+
|
|
60
|
+
/** ***************** check for type array *******************/
|
|
61
|
+
if (_isType.isArray(currentValue)) {
|
|
62
|
+
/** ***************** return value if remaining path found *******************/
|
|
63
|
+
if (currentValue[innerPath]) {
|
|
64
|
+
return {
|
|
65
|
+
v: currentValue[innerPath]
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** ***************** return array map of inner propeties *******************/
|
|
69
|
+
return {
|
|
70
|
+
v: currentValue.map(function (val) {
|
|
71
|
+
return _get(val, innerPath);
|
|
72
|
+
}).filter(function (val) {
|
|
73
|
+
return !_isType.isEmpty(val);
|
|
74
|
+
})
|
|
75
|
+
};
|
|
76
|
+
} else {
|
|
77
|
+
/** ***************** return value of remaining path *******************/
|
|
78
|
+
return {
|
|
79
|
+
v: _get(currentValue, innerPath)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
_ret;
|
|
85
|
+
for (var i = path.length - 1; i >= 0; i--) {
|
|
86
|
+
_ret = _loop();
|
|
87
|
+
if (_ret) return _ret.v;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* get property value by path
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
var getByPath = function getByPath(obj, path) {
|
|
99
|
+
var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
100
|
+
/** ***************** if empty object/path return defaultValue *******************/
|
|
101
|
+
if (_isType.isEmpty(obj) || _isType.isEmpty(path)) {
|
|
102
|
+
return defaultValue;
|
|
103
|
+
}
|
|
104
|
+
var value = _get(obj, path);
|
|
105
|
+
if (!_isType.isNil(value)) {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
return defaultValue;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* get first available value in list
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
var getValue = function getValue() {
|
|
116
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
117
|
+
args[_key] = arguments[_key];
|
|
118
|
+
}
|
|
119
|
+
return args.find(function (a) {
|
|
120
|
+
return !_isType.isEmpty(a);
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
exports.getByPath = getByPath;
|
|
125
|
+
exports.getValue = getValue;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _isType = require('./_isType.js');
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
14
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
15
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
16
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
17
|
+
* subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
20
|
+
* portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
23
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
24
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
25
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* calculate hash from string
|
|
31
|
+
* @param str
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
var hash = function hash(str) {
|
|
35
|
+
var hash = 0;
|
|
36
|
+
var i;
|
|
37
|
+
var chr;
|
|
38
|
+
if (_isType.isEmpty(str)) return hash;
|
|
39
|
+
for (i = 0; i < str.length; i++) {
|
|
40
|
+
chr = str.charCodeAt(i);
|
|
41
|
+
hash = (hash << 5) - hash + chr;
|
|
42
|
+
hash |= 0; // Convert to 32bit integer
|
|
43
|
+
}
|
|
44
|
+
return hash;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* generate short hash from current time
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
var shortHash = function shortHash() {
|
|
52
|
+
return (new Date().getTime() + Math.trunc(Math.random() * 1000)).toString(36);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* generate uuid using `crypto.getRandomValues`
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
var uuid = function uuid() {
|
|
60
|
+
return [1e7, 1e3, 4e3, 8e3, 1e11].join("-").replace(/[018]/g, function (c) {
|
|
61
|
+
return (+c ^ Math.random() * 16 & 15 >> +c / 4).toString(16);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
exports.hash = hash;
|
|
66
|
+
exports.shortHash = shortHash;
|
|
67
|
+
exports.uuid = uuid;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _getByPath = require('./_getByPath.js');
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
14
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
15
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
16
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
17
|
+
* subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
20
|
+
* portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
23
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
24
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
25
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* interpolate string template using model
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
var interpolate = function interpolate(str, model) {
|
|
34
|
+
return str.replace(/\${([^{}]*)}/g, function (a, b) {
|
|
35
|
+
var r = _getByPath.getByPath(model, b);
|
|
36
|
+
return typeof r === "string" || typeof r === "number" ? "".concat(r) : "";
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var renderTemplate = function renderTemplate(str, model) {
|
|
40
|
+
return str.replace(/{{([^{}]*)}}/g, function (a, b) {
|
|
41
|
+
var r = _getByPath.getByPath(model, b);
|
|
42
|
+
return typeof r === "string" || typeof r === "number" ? "".concat(r) : "";
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
exports.interpolate = interpolate;
|
|
47
|
+
exports.renderTemplate = renderTemplate;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _ascii = require('./_ascii.js');
|
|
4
|
+
var _isType = require('./_isType.js');
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* React Fabric
|
|
8
|
+
* @version: 1.0.0
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* The MIT License (MIT)
|
|
12
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
15
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
16
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
+
* subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
21
|
+
* portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
24
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
25
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
26
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* check equality of objects
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
var isEqual = function isEqual(obj, test) {
|
|
35
|
+
if (_isType.isString(obj) || _isType.isNumber(obj) || _isType.isBoolean(obj)) {
|
|
36
|
+
return obj === test;
|
|
37
|
+
} else if (Array.isArray(obj) && Array.isArray(test)) {
|
|
38
|
+
// if length dont match return false
|
|
39
|
+
if (obj.length !== test.length) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
// check if some value is false
|
|
43
|
+
return !obj.some(function (o, i) {
|
|
44
|
+
return !isEqual(o, test[i]);
|
|
45
|
+
});
|
|
46
|
+
} else if (_isType.isObject(obj) && _isType.isObject(test)) {
|
|
47
|
+
var okeys = Object.keys(obj);
|
|
48
|
+
var tkeys = Object.keys(test);
|
|
49
|
+
// if keys length dont match return false
|
|
50
|
+
if (okeys.length !== tkeys.length) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
// if keys dont match return false
|
|
54
|
+
if (okeys.some(function (k) {
|
|
55
|
+
return !tkeys.includes(k);
|
|
56
|
+
})) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
// check if some value is false
|
|
60
|
+
return !Object.keys(obj).some(function (k) {
|
|
61
|
+
return !isEqual(obj[k], test[k]);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* match strings
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
var matchString = function matchString(base, match) {
|
|
72
|
+
var equality = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
73
|
+
var _base = _ascii.ascii(base).toLowerCase();
|
|
74
|
+
var _match = _ascii.ascii(match).toLowerCase();
|
|
75
|
+
return equality === true ? _base === _match : equality === "start" ? _base.startsWith(_match) : _base.includes(_match);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* compare values
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
var compareValues = function compareValues() {
|
|
83
|
+
var order = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "asc";
|
|
84
|
+
var key = arguments.length > 1 ? arguments[1] : undefined;
|
|
85
|
+
return function (a, b) {
|
|
86
|
+
var aValue = key && _isType.isObject(a) ? a[key] : a;
|
|
87
|
+
var bValue = key && _isType.isObject(b) ? b[key] : b;
|
|
88
|
+
var bigger = order === "asc" ? 1 : -1;
|
|
89
|
+
var smaller = order === "desc" ? 1 : -1;
|
|
90
|
+
// return 0 when equal, allowing for multiple sorting properties
|
|
91
|
+
if (aValue === bValue) return 0;
|
|
92
|
+
// if numbers check greater
|
|
93
|
+
if (_isType.isNumber(aValue) && _isType.isNumber(bValue)) {
|
|
94
|
+
return aValue > bValue ? bigger : smaller;
|
|
95
|
+
}
|
|
96
|
+
// if boolean sort true first
|
|
97
|
+
if (_isType.isBoolean(aValue) && _isType.isBoolean(bValue)) {
|
|
98
|
+
return aValue ? smaller : bigger;
|
|
99
|
+
}
|
|
100
|
+
var _a = _ascii.ascii(aValue).toLowerCase();
|
|
101
|
+
var _b = _ascii.ascii(bValue).toLowerCase();
|
|
102
|
+
return _a.localeCompare(_b) === 1 ? bigger : smaller;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
exports.compareValues = compareValues;
|
|
107
|
+
exports.isEqual = isEqual;
|
|
108
|
+
exports.matchString = matchString;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
14
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
15
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
16
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
17
|
+
* subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
20
|
+
* portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
23
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
24
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
25
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
var isUndefined = function isUndefined(value) {
|
|
29
|
+
return value === undefined;
|
|
30
|
+
};
|
|
31
|
+
var isNull = function isNull(value) {
|
|
32
|
+
return value === null;
|
|
33
|
+
};
|
|
34
|
+
var isNil = function isNil(val) {
|
|
35
|
+
return val === undefined || val === null;
|
|
36
|
+
};
|
|
37
|
+
var isEmpty = function isEmpty(val) {
|
|
38
|
+
if (val instanceof Date) return false;
|
|
39
|
+
if (isNil(val) || val === "") {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(val) && val.filter(Boolean).length === 0) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (val instanceof Map || val instanceof Set) return val.size === 0;
|
|
46
|
+
if (["boolean", "number", "bigint", "function"].includes(_typeof(val))) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return !!val && _typeof(val) === "object" && Object.entries(val).length === 0;
|
|
50
|
+
};
|
|
51
|
+
var isObject = function isObject(val) {
|
|
52
|
+
return !isNil(val) && !(val instanceof Date) && _typeof(val) === "object" && !Array.isArray(val);
|
|
53
|
+
};
|
|
54
|
+
var isArray = function isArray(val) {
|
|
55
|
+
return Array.isArray(val);
|
|
56
|
+
};
|
|
57
|
+
var isString = function isString(value) {
|
|
58
|
+
return typeof value === "string";
|
|
59
|
+
};
|
|
60
|
+
var isNumber = function isNumber(value) {
|
|
61
|
+
return typeof value === "number";
|
|
62
|
+
};
|
|
63
|
+
var isBoolean = function isBoolean(value) {
|
|
64
|
+
return typeof value === "boolean";
|
|
65
|
+
};
|
|
66
|
+
var isTrue = function isTrue() {
|
|
67
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
68
|
+
return value === true || value === 1 || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "yes" || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "true";
|
|
69
|
+
};
|
|
70
|
+
var isFalse = function isFalse() {
|
|
71
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
72
|
+
return value === false || value === 0 || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "no" || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "false";
|
|
73
|
+
};
|
|
74
|
+
var isColor = function isColor(color) {
|
|
75
|
+
var _color$startsWith, _color$startsWith2, _color$startsWith3, _color$startsWith4;
|
|
76
|
+
return ((_color$startsWith = color.startsWith) === null || _color$startsWith === void 0 ? void 0 : _color$startsWith.call(color, "#")) || ((_color$startsWith2 = color.startsWith) === null || _color$startsWith2 === void 0 ? void 0 : _color$startsWith2.call(color, "rgb")) || ((_color$startsWith3 = color.startsWith) === null || _color$startsWith3 === void 0 ? void 0 : _color$startsWith3.call(color, "hsl")) || ((_color$startsWith4 = color.startsWith) === null || _color$startsWith4 === void 0 ? void 0 : _color$startsWith4.call(color, "lab")) || color === "transparent";
|
|
77
|
+
};
|
|
78
|
+
var isSvgPath = function isSvgPath(value) {
|
|
79
|
+
return typeof value === "string" && value.match(/^[Mm][\d.].*[\dzZ]$/) !== null;
|
|
80
|
+
};
|
|
81
|
+
var isRtl = function isRtl() {
|
|
82
|
+
return getComputedStyle(document.documentElement).direction === "rtl";
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
exports.isArray = isArray;
|
|
86
|
+
exports.isBoolean = isBoolean;
|
|
87
|
+
exports.isColor = isColor;
|
|
88
|
+
exports.isEmpty = isEmpty;
|
|
89
|
+
exports.isFalse = isFalse;
|
|
90
|
+
exports.isNil = isNil;
|
|
91
|
+
exports.isNull = isNull;
|
|
92
|
+
exports.isNumber = isNumber;
|
|
93
|
+
exports.isObject = isObject;
|
|
94
|
+
exports.isRtl = isRtl;
|
|
95
|
+
exports.isString = isString;
|
|
96
|
+
exports.isSvgPath = isSvgPath;
|
|
97
|
+
exports.isTrue = isTrue;
|
|
98
|
+
exports.isUndefined = isUndefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* React Fabric
|
|
5
|
+
* @version: 1.0.0
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
12
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
13
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
14
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
* subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
18
|
+
* portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
21
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
22
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/* istanbul ignore file */
|
|
27
|
+
|
|
28
|
+
var mergeRefs = function mergeRefs() {
|
|
29
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
30
|
+
refs[_key] = arguments[_key];
|
|
31
|
+
}
|
|
32
|
+
return function (el) {
|
|
33
|
+
refs.forEach(function (ref) {
|
|
34
|
+
if (typeof ref === "function") ref(el);
|
|
35
|
+
if (ref && "current" in ref) ref.current = el;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.mergeRefs = mergeRefs;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _isType = require('./_isType.js');
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
14
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
15
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
16
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
17
|
+
* subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
20
|
+
* portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
23
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
24
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
25
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* split text into array of tokens by word boundaries
|
|
31
|
+
* @param str
|
|
32
|
+
* @param keywords
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
var tokenize = function tokenize(str, keywords) {
|
|
36
|
+
if (_isType.isEmpty(keywords)) {
|
|
37
|
+
return [[str, ""]];
|
|
38
|
+
}
|
|
39
|
+
var keys = _isType.isArray(keywords) ? keywords : [keywords];
|
|
40
|
+
var keyMap = keys.map(function (key) {
|
|
41
|
+
// escape regex control characters
|
|
42
|
+
var escapedKey = key.replace(/([+*.?^$()[\]\\!&|\-=])/gm, "\\$1");
|
|
43
|
+
// place token within word boundaries if start/end with alpha-numeric
|
|
44
|
+
if (key.match(/^[a-z0-9]/i) != null) escapedKey = "\\b".concat(escapedKey);
|
|
45
|
+
if (key.match(/[a-z0-9]$/i) != null) escapedKey = "".concat(escapedKey, "\\b");
|
|
46
|
+
return escapedKey;
|
|
47
|
+
});
|
|
48
|
+
var regx = new RegExp("(".concat(keyMap.join("|"), ")"), "img");
|
|
49
|
+
var match;
|
|
50
|
+
var lastIndex = 0;
|
|
51
|
+
var tokens = [];
|
|
52
|
+
while ((match = regx.exec(str)) !== null) {
|
|
53
|
+
tokens.push([str.substring(lastIndex, match.index), str.substring(match.index, regx.lastIndex)]);
|
|
54
|
+
lastIndex = regx.lastIndex;
|
|
55
|
+
}
|
|
56
|
+
tokens.push([str.substring(lastIndex), ""]);
|
|
57
|
+
return tokens;
|
|
58
|
+
};
|
|
59
|
+
var iconToken = function iconToken(str) {
|
|
60
|
+
var split = str.trim().split(" ");
|
|
61
|
+
var first = split[0];
|
|
62
|
+
var last = split.length > 1 && split.pop();
|
|
63
|
+
return (first && last ? "".concat(first.charAt(0)).concat(last.charAt(0)) : "".concat(first.substring(0, 2))).toUpperCase();
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.iconToken = iconToken;
|
|
67
|
+
exports.tokenize = tokenize;
|