@react-fabric/utilities 1.0.0-beta.9 → 1.0.2
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/dist/cjs/css/boundingBox.js +72 -0
- package/dist/cjs/css/cn.js +39 -0
- package/dist/cjs/css/imageColorset.js +96 -0
- package/dist/cjs/data/countries.js +98 -0
- package/dist/cjs/{_fileType.js → data/fileType.js} +37 -19
- package/dist/cjs/data/format.js +136 -0
- package/dist/cjs/helpers/debounce.js +63 -0
- package/dist/cjs/{useLogger.js → helpers/getLogger.js} +96 -96
- package/dist/cjs/helpers/lonlat.js +99 -0
- package/dist/cjs/index.js +99 -76
- package/dist/cjs/lists/dedupe.js +54 -0
- package/dist/cjs/lists/flatten.js +66 -0
- package/dist/cjs/{_getByPath.js → lists/getByPath.js} +58 -37
- package/dist/cjs/lists/groupBy.js +49 -0
- package/dist/cjs/matchers/compare.js +70 -0
- package/dist/cjs/matchers/isEmpty.js +34 -0
- package/dist/cjs/matchers/isEqual.js +82 -0
- package/dist/cjs/matchers/nullChecks.js +61 -0
- package/dist/cjs/matchers/typeChecks.js +127 -0
- package/dist/cjs/strings/ascii.js +105 -0
- package/dist/cjs/strings/hash.js +75 -0
- package/dist/cjs/strings/interpolate.js +47 -0
- package/dist/cjs/strings/matchString.js +54 -0
- package/dist/cjs/strings/template.js +48 -0
- package/dist/cjs/strings/tokenize.js +83 -0
- package/dist/cjs/utils/mergeRefs.js +56 -0
- package/dist/esm/css/boundingBox.js +71 -0
- package/dist/esm/css/cn.js +39 -0
- package/dist/esm/css/imageColorset.js +96 -0
- package/dist/esm/data/countries.js +98 -0
- package/dist/esm/{_fileType.js → data/fileType.js} +37 -19
- package/dist/esm/data/format.js +138 -0
- package/dist/esm/helpers/debounce.js +63 -0
- package/dist/esm/{useLogger.js → helpers/getLogger.js} +96 -96
- package/dist/esm/helpers/lonlat.js +97 -0
- package/dist/esm/index.js +54 -36
- package/dist/esm/lists/dedupe.js +54 -0
- package/dist/esm/lists/flatten.js +65 -0
- package/dist/esm/{_getByPath.js → lists/getByPath.js} +50 -29
- package/dist/esm/lists/groupBy.js +49 -0
- package/dist/esm/matchers/compare.js +70 -0
- package/dist/esm/matchers/isEmpty.js +34 -0
- package/dist/esm/matchers/isEqual.js +82 -0
- package/dist/esm/matchers/nullChecks.js +58 -0
- package/dist/esm/matchers/typeChecks.js +119 -0
- package/dist/esm/strings/ascii.js +105 -0
- package/dist/esm/strings/hash.js +73 -0
- package/dist/esm/strings/interpolate.js +47 -0
- package/dist/esm/strings/matchString.js +54 -0
- package/dist/esm/strings/template.js +48 -0
- package/dist/esm/strings/tokenize.js +82 -0
- package/dist/esm/utils/mergeRefs.js +56 -0
- package/dist/types/css/boundingBox.d.ts +46 -0
- package/dist/types/css/cn.d.ts +26 -0
- package/dist/types/css/imageColorset.d.ts +37 -0
- package/dist/types/data/countries.d.ts +136 -0
- package/dist/types/{_fileType.d.ts → data/fileType.d.ts} +41 -1
- package/dist/types/data/format.d.ts +122 -0
- package/dist/types/helpers/debounce.d.ts +38 -0
- package/dist/types/helpers/getLogger.d.ts +49 -0
- package/dist/types/helpers/lonlat.d.ts +48 -0
- package/dist/types/index.d.ts +54 -20
- package/dist/types/lists/dedupe.d.ts +36 -0
- package/dist/types/lists/flatten.d.ts +47 -0
- package/dist/types/lists/getByPath.d.ts +45 -0
- package/dist/types/lists/groupBy.d.ts +36 -0
- package/dist/types/matchers/compare.d.ts +38 -0
- package/dist/types/matchers/isEmpty.d.ts +38 -0
- package/dist/types/matchers/isEqual.d.ts +39 -0
- package/dist/types/matchers/nullChecks.d.ts +43 -0
- package/dist/types/matchers/typeChecks.d.ts +107 -0
- package/dist/types/strings/ascii.d.ts +34 -0
- package/dist/types/strings/hash.d.ts +46 -0
- package/dist/types/strings/interpolate.d.ts +34 -0
- package/dist/types/strings/matchString.d.ts +41 -0
- package/dist/types/strings/template.d.ts +35 -0
- package/dist/types/strings/tokenize.d.ts +44 -0
- package/dist/types/utils/mergeRefs.d.ts +36 -0
- package/package.json +13 -11
- package/src/css/boundingBox.ts +80 -0
- package/src/css/cn.ts +32 -0
- package/src/css/imageColorset.ts +97 -0
- package/src/data/countries.ts +126 -0
- package/src/{_fileType.ts → data/fileType.ts} +72 -89
- package/src/data/format.ts +192 -0
- package/src/helpers/debounce.ts +49 -0
- package/src/{useLogger.ts → helpers/getLogger.ts} +52 -101
- package/src/helpers/lonlat.ts +124 -0
- package/src/index.ts +57 -37
- package/src/lists/dedupe.ts +46 -0
- package/src/lists/flatten.ts +56 -0
- package/src/lists/getByPath.ts +122 -0
- package/src/lists/groupBy.ts +47 -0
- package/src/matchers/compare.ts +64 -0
- package/src/matchers/isEmpty.ts +54 -0
- package/src/matchers/isEqual.ts +71 -0
- package/src/matchers/nullChecks.ts +55 -0
- package/src/matchers/typeChecks.ts +146 -0
- package/src/strings/ascii.ts +100 -0
- package/src/strings/hash.ts +68 -0
- package/src/strings/interpolate.ts +42 -0
- package/src/strings/matchString.ts +49 -0
- package/src/strings/template.ts +43 -0
- package/src/strings/tokenize.ts +77 -0
- package/src/utils/mergeRefs.ts +47 -0
- package/src/{yup.ts → utils/yup.ts} +3 -3
- package/dist/cjs/_ascii.js +0 -76
- package/dist/cjs/_boundingBox.js +0 -59
- package/dist/cjs/_countries.js +0 -2805
- package/dist/cjs/_debounce.js +0 -53
- package/dist/cjs/_dedupe.js +0 -63
- package/dist/cjs/_fetch.js +0 -128
- package/dist/cjs/_format.js +0 -118
- package/dist/cjs/_hash.js +0 -67
- package/dist/cjs/_interpolate.js +0 -47
- package/dist/cjs/_isEqual.js +0 -108
- package/dist/cjs/_isType.js +0 -98
- package/dist/cjs/_mergeRefs.js +0 -40
- package/dist/cjs/_tokenize.js +0 -67
- package/dist/cjs/getImageColorset.js +0 -70
- package/dist/esm/_ascii.js +0 -76
- package/dist/esm/_boundingBox.js +0 -58
- package/dist/esm/_countries.js +0 -2805
- package/dist/esm/_debounce.js +0 -53
- package/dist/esm/_dedupe.js +0 -60
- package/dist/esm/_fetch.js +0 -128
- package/dist/esm/_format.js +0 -120
- package/dist/esm/_hash.js +0 -65
- package/dist/esm/_interpolate.js +0 -46
- package/dist/esm/_isEqual.js +0 -106
- package/dist/esm/_isType.js +0 -85
- package/dist/esm/_mergeRefs.js +0 -40
- package/dist/esm/_tokenize.js +0 -66
- package/dist/esm/getImageColorset.js +0 -70
- package/dist/types/_ascii.d.ts +0 -5
- package/dist/types/_boundingBox.d.ts +0 -10
- package/dist/types/_countries.d.ts +0 -85
- package/dist/types/_debounce.d.ts +0 -8
- package/dist/types/_dedupe.d.ts +0 -4
- package/dist/types/_fetch.d.ts +0 -23
- package/dist/types/_format.d.ts +0 -27
- package/dist/types/_getByPath.d.ts +0 -10
- package/dist/types/_hash.d.ts +0 -16
- package/dist/types/_interpolate.d.ts +0 -6
- package/dist/types/_isEqual.d.ts +0 -15
- package/dist/types/_isType.d.ts +0 -14
- package/dist/types/_mergeRefs.d.ts +0 -1
- package/dist/types/_tokenize.d.ts +0 -8
- package/dist/types/getImageColorset.d.ts +0 -1
- package/dist/types/useLogger.d.ts +0 -25
- package/src/_ascii.ts +0 -93
- package/src/_boundingBox.ts +0 -72
- package/src/_countries.ts +0 -3046
- package/src/_debounce.ts +0 -42
- package/src/_dedupe.ts +0 -56
- package/src/_fetch.ts +0 -109
- package/src/_format.ts +0 -141
- package/src/_getByPath.ts +0 -108
- package/src/_hash.ts +0 -62
- package/src/_interpolate.ts +0 -42
- package/src/_isEqual.ts +0 -102
- package/src/_isType.ts +0 -105
- package/src/_mergeRefs.ts +0 -33
- package/src/_tokenize.ts +0 -69
- package/src/getImageColorset.ts +0 -81
- /package/dist/cjs/{yup.js → utils/yup.js} +0 -0
- /package/dist/esm/{yup.js → utils/yup.js} +0 -0
- /package/dist/types/{yup.d.ts → utils/yup.d.ts} +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var isEmpty = require('../matchers/isEmpty.js');
|
|
5
|
+
|
|
6
|
+
function _getBox(box) {
|
|
7
|
+
var boundingBox;
|
|
8
|
+
if (isEmpty.isEmpty(box)) return [0, 0, 0, 0];
|
|
9
|
+
if (typeof box === "string") {
|
|
10
|
+
boundingBox = box.split(",").map(function (b) {
|
|
11
|
+
return parseInt(b, 10);
|
|
12
|
+
});
|
|
13
|
+
} else {
|
|
14
|
+
boundingBox = box;
|
|
15
|
+
}
|
|
16
|
+
return boundingBox;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get box dimensions from a string or array.
|
|
21
|
+
* The box can be in the format "x,y,w,h" or [x,y,w,h].
|
|
22
|
+
* The box is adjusted to ensure that x and y are non-negative.
|
|
23
|
+
* The width and height are adjusted accordingly.
|
|
24
|
+
*
|
|
25
|
+
* @param box "x,y,w,h" | [x,y,w,h]
|
|
26
|
+
* @returns canvas box [x,y,w,h]
|
|
27
|
+
*/
|
|
28
|
+
function getBox() {
|
|
29
|
+
var box = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "0,0,0,0";
|
|
30
|
+
var boundingBox = _getBox(box);
|
|
31
|
+
var _boundingBox = _slicedToArray(boundingBox, 4),
|
|
32
|
+
x = _boundingBox[0],
|
|
33
|
+
y = _boundingBox[1],
|
|
34
|
+
w = _boundingBox[2],
|
|
35
|
+
h = _boundingBox[3];
|
|
36
|
+
w = x < 0 ? w + x : w;
|
|
37
|
+
h = y < 0 ? h + y : h;
|
|
38
|
+
x = x > 0 ? x : 0;
|
|
39
|
+
y = y > 0 ? y : 0;
|
|
40
|
+
return [x, y, w, h];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get bounding box dimensions from a string or array.
|
|
45
|
+
* The box can be in the format "x1,y1,x2,y2" or [x1,y1,x2,y2].
|
|
46
|
+
* The box is adjusted to ensure that x1 and y1 are non-negative.
|
|
47
|
+
* The width and height are calculated as x2 - x1 and y2 - y1 respectively.
|
|
48
|
+
* If x1 or y1 are negative, they are set to 0 and the width and height are adjusted accordingly.
|
|
49
|
+
* This is useful for ensuring that the bounding box is always within the canvas area.
|
|
50
|
+
*
|
|
51
|
+
* @param box "x1,y1,x2,y2" | [x1,y1,x2,y2]
|
|
52
|
+
* @returns canvas box [x,y,w,h]
|
|
53
|
+
*/
|
|
54
|
+
function getBoundingBox() {
|
|
55
|
+
var box = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "0,0,0,0";
|
|
56
|
+
var boundingBox = _getBox(box);
|
|
57
|
+
|
|
58
|
+
// eslint-disable-next-line prefer-const
|
|
59
|
+
var _boundingBox2 = _slicedToArray(boundingBox, 4),
|
|
60
|
+
x1 = _boundingBox2[0],
|
|
61
|
+
y1 = _boundingBox2[1],
|
|
62
|
+
x2 = _boundingBox2[2],
|
|
63
|
+
y2 = _boundingBox2[3];
|
|
64
|
+
var w = x2 - x1;
|
|
65
|
+
var h = y2 - y1;
|
|
66
|
+
x1 = x1 > 0 ? x1 : 0;
|
|
67
|
+
y1 = y1 > 0 ? y1 : 0;
|
|
68
|
+
return [x1, y1, w, h];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.getBoundingBox = getBoundingBox;
|
|
72
|
+
exports.getBox = getBox;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var clsx = require('clsx');
|
|
4
|
+
var tailwindMerge = require('tailwind-merge');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* React Fabric
|
|
8
|
+
* @version 1.0.0
|
|
9
|
+
* @license MIT
|
|
10
|
+
* @copyright 2024 Adarsh Pastakia
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
var cn = function cn() {
|
|
32
|
+
for (var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
33
|
+
classes[_key] = arguments[_key];
|
|
34
|
+
}
|
|
35
|
+
// test
|
|
36
|
+
return tailwindMerge.twMerge(clsx.clsx(classes));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.cn = cn;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chroma = require('chroma-js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @license MIT
|
|
9
|
+
* @copyright 2024 Adarsh Pastakia
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
* in the Software without restriction, including without limitation the rights
|
|
14
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
* furnished to do so, subject to the following conditions:
|
|
17
|
+
*
|
|
18
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
* copies or substantial portions of the Software.
|
|
20
|
+
*
|
|
21
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
* SOFTWARE.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get the color set of an image element.
|
|
33
|
+
* This function analyzes the pixel data of an image to determine if it is predominantly light or dark.
|
|
34
|
+
* It returns "light", "dark", or "light_transparent"/"dark_transparent" based on the pixel analysis.
|
|
35
|
+
* It uses a canvas to draw the image and extract pixel data for analysis.
|
|
36
|
+
* * The function calculates the brightness of each pixel using the formula:
|
|
37
|
+
* brightness = 0.2126 * R + 0.7152 * G + 0.0722 * B
|
|
38
|
+
* * It counts the number of light and dark pixels, and determines the overall color set based on the ratio of light to dark pixels.
|
|
39
|
+
* * If the image has transparent pixels, it appends "_transparent" to the result.
|
|
40
|
+
* * This function is useful for determining the color scheme of an image, which can be helpful for UI design,
|
|
41
|
+
* theming, and accessibility considerations.
|
|
42
|
+
*/
|
|
43
|
+
function getImageColorset(el) {
|
|
44
|
+
var transparentOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
45
|
+
// create canvas
|
|
46
|
+
var canvas = document.createElement("canvas");
|
|
47
|
+
canvas.width = Math.min(500, el.naturalWidth);
|
|
48
|
+
canvas.height = Math.min(500, el.naturalHeight);
|
|
49
|
+
var ctx = canvas.getContext("2d");
|
|
50
|
+
if (ctx != null) {
|
|
51
|
+
ctx.drawImage(el, 0, 0, el.naturalWidth, el.naturalHeight, 0, 0, canvas.width, canvas.height);
|
|
52
|
+
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
53
|
+
var data = imageData.data;
|
|
54
|
+
var r, g, b;
|
|
55
|
+
var dark = 0;
|
|
56
|
+
var light = 0;
|
|
57
|
+
var totalPixels = 0;
|
|
58
|
+
var transparent = (data === null || data === void 0 ? void 0 : data[3]) === 0;
|
|
59
|
+
for (var x = 0, len = data.length; x < len; x += 4) {
|
|
60
|
+
if (transparentOnly && data[x + 3] / 255 > 0.9) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (data[x + 3] === 0) {
|
|
64
|
+
transparent = true;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (data[x + 3] < 255) {
|
|
68
|
+
transparent = true;
|
|
69
|
+
}
|
|
70
|
+
r = data[x];
|
|
71
|
+
g = data[x + 1];
|
|
72
|
+
b = data[x + 2];
|
|
73
|
+
var l = chroma([r, g, b]).lab()[0];
|
|
74
|
+
if (transparentOnly) {
|
|
75
|
+
l < 35 && (dark++, totalPixels++);
|
|
76
|
+
l > 65 && (light++, totalPixels++);
|
|
77
|
+
} else {
|
|
78
|
+
l < 50 && (dark++, totalPixels++);
|
|
79
|
+
l >= 50 && (light++, totalPixels++);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (totalPixels === 0) return "auto";
|
|
83
|
+
var diff = light / totalPixels - dark / totalPixels;
|
|
84
|
+
var ret = diff > 0 ? "light" : "dark";
|
|
85
|
+
if (!transparentOnly && transparent) {
|
|
86
|
+
ret += "_transparent";
|
|
87
|
+
}
|
|
88
|
+
return ret;
|
|
89
|
+
}
|
|
90
|
+
return "light";
|
|
91
|
+
}
|
|
92
|
+
if (typeof window !== "undefined")
|
|
93
|
+
// @ts-expect-error ignore
|
|
94
|
+
window.getImageColorset = getImageColorset;
|
|
95
|
+
|
|
96
|
+
exports.getImageColorset = getImageColorset;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
var worldCountries = require('world-countries');
|
|
5
|
+
|
|
6
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
+
/**
|
|
9
|
+
* Country list with helper functions
|
|
10
|
+
* This is a list of all countries with their details.
|
|
11
|
+
* It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
|
|
12
|
+
* This list can be used to retrieve country information based on various codes or names.
|
|
13
|
+
* @type {Country[]}
|
|
14
|
+
*/
|
|
15
|
+
var Countries = {
|
|
16
|
+
/**
|
|
17
|
+
* Get ISO2 country code
|
|
18
|
+
*
|
|
19
|
+
* @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
|
|
20
|
+
* @return {string | undefined} - Returns the ISO2 country code if found, otherwise undefined.
|
|
21
|
+
*/
|
|
22
|
+
toIso2: function toIso2(code) {
|
|
23
|
+
var ctry = this.find(code);
|
|
24
|
+
return ctry != null ? ctry.cca2 : undefined;
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Get ISO3 country code
|
|
28
|
+
*
|
|
29
|
+
* @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
|
|
30
|
+
* @return {string | undefined} - Returns the ISO3 country code if found, otherwise undefined.
|
|
31
|
+
*/
|
|
32
|
+
toIso3: function toIso3(code) {
|
|
33
|
+
var ctry = this.find(code);
|
|
34
|
+
return ctry != null ? ctry.cca3 : undefined;
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Get country emoji
|
|
38
|
+
*
|
|
39
|
+
* @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
|
|
40
|
+
* @return {string} - Returns the emoji representation of the country if found, otherwise returns a default flag emoji.
|
|
41
|
+
*/
|
|
42
|
+
emoji: function emoji(code) {
|
|
43
|
+
var ctry = this.find(code);
|
|
44
|
+
return ctry != null ? ctry.flag : "🏳️";
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* Get country name
|
|
48
|
+
*
|
|
49
|
+
* @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
|
|
50
|
+
* @return {string} - Returns the name of the country if found, otherwise returns the code itself.
|
|
51
|
+
*/
|
|
52
|
+
name: function name(code) {
|
|
53
|
+
var ctry = this.find(code);
|
|
54
|
+
return ctry != null ? ctry.name.common : code;
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* This function searches for a country in the list by its code.
|
|
58
|
+
* It supports various formats:
|
|
59
|
+
* - ISO2 code (e.g., "US")
|
|
60
|
+
* - ISO3 code (e.g., "USA")
|
|
61
|
+
* - Alternative code (e.g., "US", "USA", "United States")
|
|
62
|
+
* It returns the first matching country object or undefined if not found.
|
|
63
|
+
* This function is useful for retrieving country details based on different code formats.
|
|
64
|
+
*
|
|
65
|
+
* @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
|
|
66
|
+
* @return {Country | undefined} - Returns the country object if found, otherwise undefined.
|
|
67
|
+
*/
|
|
68
|
+
find: function find(code) {
|
|
69
|
+
return this.list.find(function (ct) {
|
|
70
|
+
var _ct$cioc;
|
|
71
|
+
return ((_ct$cioc = ct.cioc) !== null && _ct$cioc !== void 0 ? _ct$cioc : "__").toLowerCase() === code.toLowerCase() || ct.cca2.toLowerCase() === code.toLowerCase() || ct.cca3.toLowerCase() === code.toLowerCase();
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Country list
|
|
76
|
+
* This is a list of all countries with their details.
|
|
77
|
+
* It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
|
|
78
|
+
* This list can be used to retrieve country information based on various codes or names.
|
|
79
|
+
*
|
|
80
|
+
* @type {Country[]}
|
|
81
|
+
*/
|
|
82
|
+
list: worldCountries.map(function (ct) {
|
|
83
|
+
var _ct$idd$suffixes$, _ct$idd$suffixes, _Object$entries$pop, _Object$entries$pop2;
|
|
84
|
+
return _objectSpread(_objectSpread({}, ct), {}, {
|
|
85
|
+
iconCode: ct.cca2.toLowerCase(),
|
|
86
|
+
alpha: ct.name.common.charAt(0),
|
|
87
|
+
phone: "".concat(ct.idd.root).concat((_ct$idd$suffixes$ = (_ct$idd$suffixes = ct.idd.suffixes) === null || _ct$idd$suffixes === void 0 ? void 0 : _ct$idd$suffixes[0]) !== null && _ct$idd$suffixes$ !== void 0 ? _ct$idd$suffixes$ : ""),
|
|
88
|
+
region: ct.region === "Americas" ? ct.subregion : ct.region,
|
|
89
|
+
currency: ct.currencies ? _objectSpread(_objectSpread({}, (_Object$entries$pop = Object.entries(ct.currencies).pop()) === null || _Object$entries$pop === void 0 ? void 0 : _Object$entries$pop[1]), {}, {
|
|
90
|
+
code: "".concat((_Object$entries$pop2 = Object.entries(ct.currencies).pop()) === null || _Object$entries$pop2 === void 0 ? void 0 : _Object$entries$pop2[0])
|
|
91
|
+
}) : {
|
|
92
|
+
code: "UNK"
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
})
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
module.exports = Countries;
|
|
@@ -2,32 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
6
|
* React Fabric
|
|
7
|
-
* @version
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @license MIT
|
|
9
|
+
* @copyright 2024 Adarsh Pastakia
|
|
8
10
|
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
* in the Software without restriction, including without limitation the rights
|
|
14
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
* furnished to do so, subject to the following conditions:
|
|
9
17
|
*
|
|
10
|
-
* The
|
|
11
|
-
*
|
|
18
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
* copies or substantial portions of the Software.
|
|
12
20
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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.
|
|
21
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
* SOFTWARE.
|
|
26
28
|
*/
|
|
27
29
|
|
|
28
30
|
/* istanbul ignore file */
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
/**
|
|
33
|
+
* File type utility to get the file type from a MIME type.
|
|
34
|
+
* This utility provides a mapping of common MIME types to their human-readable names.
|
|
35
|
+
* It can be used to display file types in a user-friendly manner.
|
|
36
|
+
*/
|
|
37
|
+
var fileType = {
|
|
38
|
+
/**
|
|
39
|
+
* Get the human-readable file type from a MIME type.
|
|
40
|
+
* This method looks up the MIME type in a predefined list
|
|
41
|
+
* and returns a user-friendly name.
|
|
42
|
+
*
|
|
43
|
+
* @param mime MIME type string, e.g. "application/pdf"
|
|
44
|
+
* @returns {string} - The human-readable file type.
|
|
45
|
+
*/
|
|
31
46
|
mime: function mime() {
|
|
32
47
|
var mime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
33
48
|
var ret = this.mimeList[mime.split(";")[0]];
|
|
@@ -40,6 +55,9 @@ var _fileType = {
|
|
|
40
55
|
}
|
|
41
56
|
return ret || "Unknown type";
|
|
42
57
|
},
|
|
58
|
+
/**
|
|
59
|
+
* List of common MIME types and their human-readable names.
|
|
60
|
+
*/
|
|
43
61
|
mimeList: {
|
|
44
62
|
"application/x-tika-msoffice": "Microsft Office File",
|
|
45
63
|
"application/x-tika-ooxml": "Open Office File",
|
|
@@ -964,4 +982,4 @@ var _fileType = {
|
|
|
964
982
|
}
|
|
965
983
|
};
|
|
966
984
|
|
|
967
|
-
module.exports =
|
|
985
|
+
module.exports = fileType;
|
|
@@ -0,0 +1,136 @@
|
|
|
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 isEmpty = require('../matchers/isEmpty.js');
|
|
8
|
+
var nullChecks = require('../matchers/nullChecks.js');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* React Fabric
|
|
12
|
+
* @version 1.0.0
|
|
13
|
+
* @license MIT
|
|
14
|
+
* @copyright 2024 Adarsh Pastakia
|
|
15
|
+
*
|
|
16
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
* in the Software without restriction, including without limitation the rights
|
|
19
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
* furnished to do so, subject to the following conditions:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
24
|
+
* copies or substantial portions of the Software.
|
|
25
|
+
*
|
|
26
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
+
* SOFTWARE.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Format utility functions for various data types.
|
|
38
|
+
* This namespace provides methods to format phone numbers, numbers, bytes, percentages, dates, and durations.
|
|
39
|
+
*/
|
|
40
|
+
exports.Format = void 0;
|
|
41
|
+
(function (_Format) {
|
|
42
|
+
function getPhone(value, country) {
|
|
43
|
+
var phone = value.match(/^[0+]/) != null ? value.replace(/^00/, "+") : "+".concat(value);
|
|
44
|
+
var number = libphonenumberJs.parsePhoneNumberFromString(phone, country);
|
|
45
|
+
/* istanbul ignore next */
|
|
46
|
+
return number !== null && number !== void 0 ? number : {
|
|
47
|
+
country: "",
|
|
48
|
+
formatInternational: function formatInternational() {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function numberFormat(number) {
|
|
54
|
+
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "0,0[.]00a";
|
|
55
|
+
if (nullChecks.isNil(number)) {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
var prefix = "".concat(number).startsWith("+") ? "+" : "";
|
|
59
|
+
return prefix + numeral(number).format(format);
|
|
60
|
+
}
|
|
61
|
+
function makeDuration(value) {
|
|
62
|
+
var fmt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "HH:mm:ss.SSS";
|
|
63
|
+
if (!isNaN(value)) {
|
|
64
|
+
var days = dateFns.differenceInDays(value, 0);
|
|
65
|
+
var prefix = days > 0 ? "".concat(days, "d:") : "";
|
|
66
|
+
var time = dateFns.format(dateFns.parseISO(new Date(value).toISOString().replace("Z", "")), fmt);
|
|
67
|
+
if (!prefix) time = time.replace(/^00:/, "");
|
|
68
|
+
return "".concat(prefix).concat(time);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Format phone number with country flag or emoji.
|
|
74
|
+
* It takes a phone number string, a country code, and a boolean to indicate whether to use CSS classes for flags.
|
|
75
|
+
* If the phone number is empty, less than 6 characters, or does not match the regex for valid phone numbers,
|
|
76
|
+
* it returns the original value.
|
|
77
|
+
* If the phone number is valid, it formats the phone number using `libphonenumber-js` and returns it with the country flag or emoji.
|
|
78
|
+
* The country flag is represented as a CSS class, and the emoji is obtained from the `Countries` module.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} value - The phone number to format.
|
|
81
|
+
* @param {string} country - The country code to use for formatting.
|
|
82
|
+
* @param {boolean} useCss - Whether to use CSS classes for flags.
|
|
83
|
+
* @returns {string} The formatted phone number with country flag or emoji.
|
|
84
|
+
*/
|
|
85
|
+
function phone(value) {
|
|
86
|
+
var _phone$country;
|
|
87
|
+
var country = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "AE";
|
|
88
|
+
var useCss = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
89
|
+
if (isEmpty.isEmpty(value) || value.length < 6 || !/^[\d+\s\-()]+$/.test(value)) return value;
|
|
90
|
+
var phone = getPhone(value, country);
|
|
91
|
+
/* istanbul ignore next */
|
|
92
|
+
return "".concat(useCss ? "<span class=\"iconify-color circle-flags--".concat(phone.country, "\"></span>") : countries.emoji((_phone$country = phone.country) !== null && _phone$country !== void 0 ? _phone$country : ""), " ").concat(phone.formatInternational());
|
|
93
|
+
}
|
|
94
|
+
_Format.phone = phone;
|
|
95
|
+
function number(number, format) {
|
|
96
|
+
return numberFormat(number, format);
|
|
97
|
+
}
|
|
98
|
+
_Format.number = number;
|
|
99
|
+
function bytes(number) {
|
|
100
|
+
return numberFormat(number, "0,0[.]00b");
|
|
101
|
+
}
|
|
102
|
+
_Format.bytes = bytes;
|
|
103
|
+
function percent(number) {
|
|
104
|
+
return numberFormat(number, "0,0[.]00%");
|
|
105
|
+
}
|
|
106
|
+
_Format.percent = percent;
|
|
107
|
+
function date(date) {
|
|
108
|
+
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "d-M-y";
|
|
109
|
+
return date ? dateFns.format(new Date(date), format) : "";
|
|
110
|
+
}
|
|
111
|
+
_Format.date = date;
|
|
112
|
+
function duration(number, isFraction) {
|
|
113
|
+
var _makeDuration;
|
|
114
|
+
if (nullChecks.isNil(number)) {
|
|
115
|
+
return "00:00.000";
|
|
116
|
+
}
|
|
117
|
+
if (number === Infinity) {
|
|
118
|
+
return "∞";
|
|
119
|
+
}
|
|
120
|
+
var value = parseFloat("".concat(number)) * (isFraction ? 1000 : 1);
|
|
121
|
+
return (_makeDuration = makeDuration(value)) !== null && _makeDuration !== void 0 ? _makeDuration : "00:00.000";
|
|
122
|
+
}
|
|
123
|
+
_Format.duration = duration;
|
|
124
|
+
function durationSeconds(number, isFraction) {
|
|
125
|
+
var _makeDuration2;
|
|
126
|
+
if (nullChecks.isNil(number)) {
|
|
127
|
+
return "00:00";
|
|
128
|
+
}
|
|
129
|
+
if (number === Infinity) {
|
|
130
|
+
return "∞";
|
|
131
|
+
}
|
|
132
|
+
var value = parseFloat("".concat(number)) * (isFraction ? 1000 : 1);
|
|
133
|
+
return (_makeDuration2 = makeDuration(value, "HH:mm:ss")) !== null && _makeDuration2 !== void 0 ? _makeDuration2 : "00:00";
|
|
134
|
+
}
|
|
135
|
+
_Format.durationSeconds = durationSeconds;
|
|
136
|
+
})(exports.Format || (exports.Format = {}));
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @license MIT
|
|
9
|
+
* @copyright 2024 Adarsh Pastakia
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
* in the Software without restriction, including without limitation the rights
|
|
14
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
* furnished to do so, subject to the following conditions:
|
|
17
|
+
*
|
|
18
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
* copies or substantial portions of the Software.
|
|
20
|
+
*
|
|
21
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
* SOFTWARE.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/* istanbul ignore file */
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Debounce function to limit the rate at which a function can fire.
|
|
34
|
+
* It will delay the execution of the function until after a specified timeout
|
|
35
|
+
* has elapsed since the last time the function was invoked.
|
|
36
|
+
*
|
|
37
|
+
* @param fn - The function to debounce.
|
|
38
|
+
* @param timeout - The number of milliseconds to wait before invoking the function.
|
|
39
|
+
* @returns A debounced version of the function that can be called with any arguments.
|
|
40
|
+
* The debounced function also has a `cancel` method to clear the timeout.
|
|
41
|
+
*/
|
|
42
|
+
function debounce(fn) {
|
|
43
|
+
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
|
|
44
|
+
/** ***************** create debounce timer id using callback hash *******************/
|
|
45
|
+
var _timer;
|
|
46
|
+
|
|
47
|
+
/** ***************** return debounced function *******************/
|
|
48
|
+
var cb = function cb() {
|
|
49
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
50
|
+
args[_key] = arguments[_key];
|
|
51
|
+
}
|
|
52
|
+
clearTimeout(_timer);
|
|
53
|
+
if (typeof window !== "undefined") _timer = window.setTimeout(function () {
|
|
54
|
+
return fn === null || fn === void 0 ? void 0 : fn.apply(void 0, _toConsumableArray(args));
|
|
55
|
+
}, timeout);
|
|
56
|
+
};
|
|
57
|
+
cb.cancel = function () {
|
|
58
|
+
return clearTimeout(_timer);
|
|
59
|
+
};
|
|
60
|
+
return cb;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.debounce = debounce;
|