mogh_ui 0.2.1 → 0.4.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/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +22 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +3 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +19 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ __reExport(index_exports, require("./color"), module.exports);
|
|
|
20
20
|
__reExport(index_exports, require("./formatting"), module.exports);
|
|
21
21
|
__reExport(index_exports, require("./hooks"), module.exports);
|
|
22
22
|
__reExport(index_exports, require("./theme"), module.exports);
|
|
23
|
+
__reExport(index_exports, require("./utils"), module.exports);
|
|
23
24
|
__reExport(index_exports, require("./components/config"), module.exports);
|
|
24
25
|
__reExport(index_exports, require("./components/divided-children"), module.exports);
|
|
25
26
|
__reExport(index_exports, require("./components/fancy-card"), module.exports);
|
|
@@ -62,6 +63,7 @@ __reExport(index_exports, require("./components/theme-toggle"), module.exports);
|
|
|
62
63
|
...require("./formatting"),
|
|
63
64
|
...require("./hooks"),
|
|
64
65
|
...require("./theme"),
|
|
66
|
+
...require("./utils"),
|
|
65
67
|
...require("./components/config"),
|
|
66
68
|
...require("./components/divided-children"),
|
|
67
69
|
...require("./components/fancy-card"),
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./auth\";\nexport * from \"./color\";\nexport * from \"./formatting\";\nexport * from \"./hooks\";\nexport * from \"./theme\";\nexport * from \"./components/config\";\nexport * from \"./components/divided-children\";\nexport * from \"./components/fancy-card\";\nexport * from \"./components/monaco\";\nexport * from \"./components/back-button\";\nexport * from \"./components/confirm-button\";\nexport * from \"./components/confirm-icon\";\nexport * from \"./components/confirm-modal\";\nexport * from \"./components/copy-button\";\nexport * from \"./components/copy-text\";\nexport * from \"./components/create-modal\";\nexport * from \"./components/data-table\";\nexport * from \"./components/enable-switch\";\nexport * from \"./components/entity-header\";\nexport * from \"./components/entity-page\";\nexport * from \"./components/hover-error\";\nexport * from \"./components/info-card\";\nexport * from \"./components/input-list\";\nexport * from \"./components/labelled-switch\";\nexport * from \"./components/labels-group\";\nexport * from \"./components/loading-screen\";\nexport * from \"./components/mobile-friendly-tabs\";\nexport * from \"./components/page-guard\";\nexport * from \"./components/page\";\nexport * from \"./components/search-input\";\nexport * from \"./components/section\";\nexport * from \"./components/shared-text-update\";\nexport * from \"./components/show-hide-button\";\nexport * from \"./components/stat-bar\";\nexport * from \"./components/stat-cell\";\nexport * from \"./components/status-badge\";\nexport * from \"./components/tabbed-page\";\nexport * from \"./components/table-skeleton\";\nexport * from \"./components/text-update-modal\";\nexport * from \"./components/theme-toggle\";\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,mBAAd;AACA,0BAAc,oBADd;AAEA,0BAAc,yBAFd;AAGA,0BAAc,oBAHd;AAIA,0BAAc,oBAJd;AAKA,0BAAc,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./auth\";\nexport * from \"./color\";\nexport * from \"./formatting\";\nexport * from \"./hooks\";\nexport * from \"./theme\";\nexport * from \"./utils\";\nexport * from \"./components/config\";\nexport * from \"./components/divided-children\";\nexport * from \"./components/fancy-card\";\nexport * from \"./components/monaco\";\nexport * from \"./components/back-button\";\nexport * from \"./components/confirm-button\";\nexport * from \"./components/confirm-icon\";\nexport * from \"./components/confirm-modal\";\nexport * from \"./components/copy-button\";\nexport * from \"./components/copy-text\";\nexport * from \"./components/create-modal\";\nexport * from \"./components/data-table\";\nexport * from \"./components/enable-switch\";\nexport * from \"./components/entity-header\";\nexport * from \"./components/entity-page\";\nexport * from \"./components/hover-error\";\nexport * from \"./components/info-card\";\nexport * from \"./components/input-list\";\nexport * from \"./components/labelled-switch\";\nexport * from \"./components/labels-group\";\nexport * from \"./components/loading-screen\";\nexport * from \"./components/mobile-friendly-tabs\";\nexport * from \"./components/page-guard\";\nexport * from \"./components/page\";\nexport * from \"./components/search-input\";\nexport * from \"./components/section\";\nexport * from \"./components/shared-text-update\";\nexport * from \"./components/show-hide-button\";\nexport * from \"./components/stat-bar\";\nexport * from \"./components/stat-cell\";\nexport * from \"./components/status-badge\";\nexport * from \"./components/tabbed-page\";\nexport * from \"./components/table-skeleton\";\nexport * from \"./components/text-update-modal\";\nexport * from \"./components/theme-toggle\";\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,mBAAd;AACA,0BAAc,oBADd;AAEA,0BAAc,yBAFd;AAGA,0BAAc,oBAHd;AAIA,0BAAc,oBAJd;AAKA,0BAAc,oBALd;AAMA,0BAAc,gCANd;AAOA,0BAAc,0CAPd;AAQA,0BAAc,oCARd;AASA,0BAAc,gCATd;AAUA,0BAAc,qCAVd;AAWA,0BAAc,wCAXd;AAYA,0BAAc,sCAZd;AAaA,0BAAc,uCAbd;AAcA,0BAAc,qCAdd;AAeA,0BAAc,mCAfd;AAgBA,0BAAc,sCAhBd;AAiBA,0BAAc,oCAjBd;AAkBA,0BAAc,uCAlBd;AAmBA,0BAAc,uCAnBd;AAoBA,0BAAc,qCApBd;AAqBA,0BAAc,qCArBd;AAsBA,0BAAc,mCAtBd;AAuBA,0BAAc,oCAvBd;AAwBA,0BAAc,yCAxBd;AAyBA,0BAAc,sCAzBd;AA0BA,0BAAc,wCA1Bd;AA2BA,0BAAc,8CA3Bd;AA4BA,0BAAc,oCA5Bd;AA6BA,0BAAc,8BA7Bd;AA8BA,0BAAc,sCA9Bd;AA+BA,0BAAc,iCA/Bd;AAgCA,0BAAc,4CAhCd;AAiCA,0BAAc,0CAjCd;AAkCA,0BAAc,kCAlCd;AAmCA,0BAAc,mCAnCd;AAoCA,0BAAc,sCApCd;AAqCA,0BAAc,qCArCd;AAsCA,0BAAc,wCAtCd;AAuCA,0BAAc,2CAvCd;AAwCA,0BAAc,sCAxCd;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,7 @@ export { ColorIntention, colorByIntention, hexColorByIntention } from './color.c
|
|
|
3
3
|
export { BYTES_PER_GB, BYTES_PER_KB, BYTES_PER_MB, fmtDate, fmtDateWithMinutes, fmtDuration, fmtMonth, fmtRateBytes, fmtSizeBytes, fmtSnakeCaseToUpperSpaceCase, fmtUpperCamelcase, fmtUtcDate } from './formatting.cjs';
|
|
4
4
|
export { Dimensions, useCtrlKeyListener, useDebounce, useKeyListener, useSearchCombobox, useShiftKeyListener, useWindowDimensions } from './hooks.cjs';
|
|
5
5
|
export { AdditionalColors, DARK_BODY, LIGHT_BODY, ThemeProvider, ThemeProviderProps, functionColorsTuple, opacityColorsTuple } from './theme.cjs';
|
|
6
|
+
export { deepCompare, filterBySplit, filterMultitermBySplit } from './utils.cjs';
|
|
6
7
|
export { Config, ConfigFieldArgs, ConfigGroup, ConfigGroupArgs, ConfigProps } from './components/config/index.cjs';
|
|
7
8
|
export { DividedChildren } from './components/divided-children/index.cjs';
|
|
8
9
|
export { FancyCard } from './components/fancy-card/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { ColorIntention, colorByIntention, hexColorByIntention } from './color.j
|
|
|
3
3
|
export { BYTES_PER_GB, BYTES_PER_KB, BYTES_PER_MB, fmtDate, fmtDateWithMinutes, fmtDuration, fmtMonth, fmtRateBytes, fmtSizeBytes, fmtSnakeCaseToUpperSpaceCase, fmtUpperCamelcase, fmtUtcDate } from './formatting.js';
|
|
4
4
|
export { Dimensions, useCtrlKeyListener, useDebounce, useKeyListener, useSearchCombobox, useShiftKeyListener, useWindowDimensions } from './hooks.js';
|
|
5
5
|
export { AdditionalColors, DARK_BODY, LIGHT_BODY, ThemeProvider, ThemeProviderProps, functionColorsTuple, opacityColorsTuple } from './theme.js';
|
|
6
|
+
export { deepCompare, filterBySplit, filterMultitermBySplit } from './utils.js';
|
|
6
7
|
export { Config, ConfigFieldArgs, ConfigGroup, ConfigGroupArgs, ConfigProps } from './components/config/index.js';
|
|
7
8
|
export { DividedChildren } from './components/divided-children/index.js';
|
|
8
9
|
export { FancyCard } from './components/fancy-card/index.js';
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./auth\";\nexport * from \"./color\";\nexport * from \"./formatting\";\nexport * from \"./hooks\";\nexport * from \"./theme\";\nexport * from \"./components/config\";\nexport * from \"./components/divided-children\";\nexport * from \"./components/fancy-card\";\nexport * from \"./components/monaco\";\nexport * from \"./components/back-button\";\nexport * from \"./components/confirm-button\";\nexport * from \"./components/confirm-icon\";\nexport * from \"./components/confirm-modal\";\nexport * from \"./components/copy-button\";\nexport * from \"./components/copy-text\";\nexport * from \"./components/create-modal\";\nexport * from \"./components/data-table\";\nexport * from \"./components/enable-switch\";\nexport * from \"./components/entity-header\";\nexport * from \"./components/entity-page\";\nexport * from \"./components/hover-error\";\nexport * from \"./components/info-card\";\nexport * from \"./components/input-list\";\nexport * from \"./components/labelled-switch\";\nexport * from \"./components/labels-group\";\nexport * from \"./components/loading-screen\";\nexport * from \"./components/mobile-friendly-tabs\";\nexport * from \"./components/page-guard\";\nexport * from \"./components/page\";\nexport * from \"./components/search-input\";\nexport * from \"./components/section\";\nexport * from \"./components/shared-text-update\";\nexport * from \"./components/show-hide-button\";\nexport * from \"./components/stat-bar\";\nexport * from \"./components/stat-cell\";\nexport * from \"./components/status-badge\";\nexport * from \"./components/tabbed-page\";\nexport * from \"./components/table-skeleton\";\nexport * from \"./components/text-update-modal\";\nexport * from \"./components/theme-toggle\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./auth\";\nexport * from \"./color\";\nexport * from \"./formatting\";\nexport * from \"./hooks\";\nexport * from \"./theme\";\nexport * from \"./utils\";\nexport * from \"./components/config\";\nexport * from \"./components/divided-children\";\nexport * from \"./components/fancy-card\";\nexport * from \"./components/monaco\";\nexport * from \"./components/back-button\";\nexport * from \"./components/confirm-button\";\nexport * from \"./components/confirm-icon\";\nexport * from \"./components/confirm-modal\";\nexport * from \"./components/copy-button\";\nexport * from \"./components/copy-text\";\nexport * from \"./components/create-modal\";\nexport * from \"./components/data-table\";\nexport * from \"./components/enable-switch\";\nexport * from \"./components/entity-header\";\nexport * from \"./components/entity-page\";\nexport * from \"./components/hover-error\";\nexport * from \"./components/info-card\";\nexport * from \"./components/input-list\";\nexport * from \"./components/labelled-switch\";\nexport * from \"./components/labels-group\";\nexport * from \"./components/loading-screen\";\nexport * from \"./components/mobile-friendly-tabs\";\nexport * from \"./components/page-guard\";\nexport * from \"./components/page\";\nexport * from \"./components/search-input\";\nexport * from \"./components/section\";\nexport * from \"./components/shared-text-update\";\nexport * from \"./components/show-hide-button\";\nexport * from \"./components/stat-bar\";\nexport * from \"./components/stat-cell\";\nexport * from \"./components/status-badge\";\nexport * from \"./components/tabbed-page\";\nexport * from \"./components/table-skeleton\";\nexport * from \"./components/text-update-modal\";\nexport * from \"./components/theme-toggle\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
package/dist/utils.cjs
CHANGED
|
@@ -18,7 +18,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
|
-
deepCompare: () => deepCompare
|
|
21
|
+
deepCompare: () => deepCompare,
|
|
22
|
+
filterBySplit: () => filterBySplit,
|
|
23
|
+
filterMultitermBySplit: () => filterMultitermBySplit
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(utils_exports);
|
|
24
26
|
function deepCompare(a, b) {
|
|
@@ -41,8 +43,26 @@ function deepCompare(a, b) {
|
|
|
41
43
|
}
|
|
42
44
|
return a === b;
|
|
43
45
|
}
|
|
46
|
+
function filterBySplit(items, search, extract) {
|
|
47
|
+
const split = search.toLowerCase().split(" ");
|
|
48
|
+
return (split.length ? items?.filter((item) => {
|
|
49
|
+
const target = extract(item).toLowerCase();
|
|
50
|
+
return split.every((term) => target.includes(term));
|
|
51
|
+
}) : items) ?? [];
|
|
52
|
+
}
|
|
53
|
+
function filterMultitermBySplit(items, search, extract) {
|
|
54
|
+
const split = search.toLowerCase().split(" ");
|
|
55
|
+
return (split.length ? items?.filter((item) => {
|
|
56
|
+
const target = extract(item).filter((str) => str).map((str) => str.toLowerCase());
|
|
57
|
+
return split.every(
|
|
58
|
+
(term) => target.findIndex((t) => t.includes(term)) !== -1
|
|
59
|
+
);
|
|
60
|
+
}) : items) ?? [];
|
|
61
|
+
}
|
|
44
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
63
|
0 && (module.exports = {
|
|
46
|
-
deepCompare
|
|
64
|
+
deepCompare,
|
|
65
|
+
filterBySplit,
|
|
66
|
+
filterMultitermBySplit
|
|
47
67
|
});
|
|
48
68
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Does deep compare of 2 items, returning `true` if equal.\n *\n * - Functions: Always `true`\n * - Primitives: Returns direct `a === b`\n * - Arrays: Returns same items and ordering (recursive)\n * - Objects: Returns same keys / values (recursive)\n *\n * @param a Item a\n * @param b Item b\n * @returns a === b\n */\nexport function deepCompare(a: any, b: any) {\n // Short path for falsy. Important to catch typeof null === \"object\" edge case.\n if (!a || !b) {\n return a === b;\n }\n\n const ta = typeof a;\n const tb = typeof b;\n\n if (ta !== tb) return false;\n\n if (ta === \"function\") return true;\n\n if (ta === \"object\") {\n const ea = Object.entries(a);\n const kb = Object.keys(b);\n\n // Length not equal -> false\n if (ea.length !== kb.length) return false;\n\n for (const [key, va] of ea) {\n const vb = b[key];\n\n // Early return when any not equal\n if (!deepCompare(va, vb)) return false;\n }\n\n // If it gets through all, it's equal\n return true;\n }\n\n return a === b;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,YAAY,GAAQ,GAAQ;AAE1C,MAAI,CAAC,KAAK,CAAC,GAAG;AACZ,WAAO,MAAM;AAAA,EACf;AAEA,QAAM,KAAK,OAAO;AAClB,QAAM,KAAK,OAAO;AAElB,MAAI,OAAO,GAAI,QAAO;AAEtB,MAAI,OAAO,WAAY,QAAO;AAE9B,MAAI,OAAO,UAAU;AACnB,UAAM,KAAK,OAAO,QAAQ,CAAC;AAC3B,UAAM,KAAK,OAAO,KAAK,CAAC;AAGxB,QAAI,GAAG,WAAW,GAAG,OAAQ,QAAO;AAEpC,eAAW,CAAC,KAAK,EAAE,KAAK,IAAI;AAC1B,YAAM,KAAK,EAAE,GAAG;AAGhB,UAAI,CAAC,YAAY,IAAI,EAAE,EAAG,QAAO;AAAA,IACnC;AAGA,WAAO;AAAA,EACT;AAEA,SAAO,MAAM;AACf;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Does deep compare of 2 items, returning `true` if equal.\n *\n * - Functions: Always `true`\n * - Primitives: Returns direct `a === b`\n * - Arrays: Returns same items and ordering (recursive)\n * - Objects: Returns same keys / values (recursive)\n *\n * @param a Item a\n * @param b Item b\n * @returns a === b\n */\nexport function deepCompare(a: any, b: any) {\n // Short path for falsy. Important to catch typeof null === \"object\" edge case.\n if (!a || !b) {\n return a === b;\n }\n\n const ta = typeof a;\n const tb = typeof b;\n\n if (ta !== tb) return false;\n\n if (ta === \"function\") return true;\n\n if (ta === \"object\") {\n const ea = Object.entries(a);\n const kb = Object.keys(b);\n\n // Length not equal -> false\n if (ea.length !== kb.length) return false;\n\n for (const [key, va] of ea) {\n const vb = b[key];\n\n // Early return when any not equal\n if (!deepCompare(va, vb)) return false;\n }\n\n // If it gets through all, it's equal\n return true;\n }\n\n return a === b;\n}\n\nexport function filterBySplit<T>(\n items: T[] | undefined,\n search: string,\n extract: (item: T) => string,\n) {\n const split = search.toLowerCase().split(\" \");\n return (\n (split.length\n ? items?.filter((item) => {\n const target = extract(item).toLowerCase();\n return split.every((term) => target.includes(term));\n })\n : items) ?? []\n );\n}\n\nexport function filterMultitermBySplit<T>(\n items: T[] | undefined,\n search: string,\n extract: (item: T) => (string | undefined)[],\n) {\n const split = search.toLowerCase().split(\" \");\n return (\n (split.length\n ? items?.filter((item) => {\n const target = extract(item)\n .filter((str) => str)\n .map((str) => str!.toLowerCase());\n return split.every(\n (term) => target.findIndex((t) => t.includes(term)) !== -1,\n );\n })\n : items) ?? []\n );\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,YAAY,GAAQ,GAAQ;AAE1C,MAAI,CAAC,KAAK,CAAC,GAAG;AACZ,WAAO,MAAM;AAAA,EACf;AAEA,QAAM,KAAK,OAAO;AAClB,QAAM,KAAK,OAAO;AAElB,MAAI,OAAO,GAAI,QAAO;AAEtB,MAAI,OAAO,WAAY,QAAO;AAE9B,MAAI,OAAO,UAAU;AACnB,UAAM,KAAK,OAAO,QAAQ,CAAC;AAC3B,UAAM,KAAK,OAAO,KAAK,CAAC;AAGxB,QAAI,GAAG,WAAW,GAAG,OAAQ,QAAO;AAEpC,eAAW,CAAC,KAAK,EAAE,KAAK,IAAI;AAC1B,YAAM,KAAK,EAAE,GAAG;AAGhB,UAAI,CAAC,YAAY,IAAI,EAAE,EAAG,QAAO;AAAA,IACnC;AAGA,WAAO;AAAA,EACT;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,cACd,OACA,QACA,SACA;AACA,QAAM,QAAQ,OAAO,YAAY,EAAE,MAAM,GAAG;AAC5C,UACG,MAAM,SACH,OAAO,OAAO,CAAC,SAAS;AACtB,UAAM,SAAS,QAAQ,IAAI,EAAE,YAAY;AACzC,WAAO,MAAM,MAAM,CAAC,SAAS,OAAO,SAAS,IAAI,CAAC;AAAA,EACpD,CAAC,IACD,UAAU,CAAC;AAEnB;AAEO,SAAS,uBACd,OACA,QACA,SACA;AACA,QAAM,QAAQ,OAAO,YAAY,EAAE,MAAM,GAAG;AAC5C,UACG,MAAM,SACH,OAAO,OAAO,CAAC,SAAS;AACtB,UAAM,SAAS,QAAQ,IAAI,EACxB,OAAO,CAAC,QAAQ,GAAG,EACnB,IAAI,CAAC,QAAQ,IAAK,YAAY,CAAC;AAClC,WAAO,MAAM;AAAA,MACX,CAAC,SAAS,OAAO,UAAU,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,MAAM;AAAA,IAC1D;AAAA,EACF,CAAC,IACD,UAAU,CAAC;AAEnB;","names":[]}
|
package/dist/utils.d.cts
CHANGED
|
@@ -11,5 +11,7 @@
|
|
|
11
11
|
* @returns a === b
|
|
12
12
|
*/
|
|
13
13
|
declare function deepCompare(a: any, b: any): boolean;
|
|
14
|
+
declare function filterBySplit<T>(items: T[] | undefined, search: string, extract: (item: T) => string): T[];
|
|
15
|
+
declare function filterMultitermBySplit<T>(items: T[] | undefined, search: string, extract: (item: T) => (string | undefined)[]): T[];
|
|
14
16
|
|
|
15
|
-
export { deepCompare };
|
|
17
|
+
export { deepCompare, filterBySplit, filterMultitermBySplit };
|
package/dist/utils.d.ts
CHANGED
|
@@ -11,5 +11,7 @@
|
|
|
11
11
|
* @returns a === b
|
|
12
12
|
*/
|
|
13
13
|
declare function deepCompare(a: any, b: any): boolean;
|
|
14
|
+
declare function filterBySplit<T>(items: T[] | undefined, search: string, extract: (item: T) => string): T[];
|
|
15
|
+
declare function filterMultitermBySplit<T>(items: T[] | undefined, search: string, extract: (item: T) => (string | undefined)[]): T[];
|
|
14
16
|
|
|
15
|
-
export { deepCompare };
|
|
17
|
+
export { deepCompare, filterBySplit, filterMultitermBySplit };
|
package/dist/utils.js
CHANGED
|
@@ -18,7 +18,25 @@ function deepCompare(a, b) {
|
|
|
18
18
|
}
|
|
19
19
|
return a === b;
|
|
20
20
|
}
|
|
21
|
+
function filterBySplit(items, search, extract) {
|
|
22
|
+
const split = search.toLowerCase().split(" ");
|
|
23
|
+
return (split.length ? items?.filter((item) => {
|
|
24
|
+
const target = extract(item).toLowerCase();
|
|
25
|
+
return split.every((term) => target.includes(term));
|
|
26
|
+
}) : items) ?? [];
|
|
27
|
+
}
|
|
28
|
+
function filterMultitermBySplit(items, search, extract) {
|
|
29
|
+
const split = search.toLowerCase().split(" ");
|
|
30
|
+
return (split.length ? items?.filter((item) => {
|
|
31
|
+
const target = extract(item).filter((str) => str).map((str) => str.toLowerCase());
|
|
32
|
+
return split.every(
|
|
33
|
+
(term) => target.findIndex((t) => t.includes(term)) !== -1
|
|
34
|
+
);
|
|
35
|
+
}) : items) ?? [];
|
|
36
|
+
}
|
|
21
37
|
export {
|
|
22
|
-
deepCompare
|
|
38
|
+
deepCompare,
|
|
39
|
+
filterBySplit,
|
|
40
|
+
filterMultitermBySplit
|
|
23
41
|
};
|
|
24
42
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Does deep compare of 2 items, returning `true` if equal.\n *\n * - Functions: Always `true`\n * - Primitives: Returns direct `a === b`\n * - Arrays: Returns same items and ordering (recursive)\n * - Objects: Returns same keys / values (recursive)\n *\n * @param a Item a\n * @param b Item b\n * @returns a === b\n */\nexport function deepCompare(a: any, b: any) {\n // Short path for falsy. Important to catch typeof null === \"object\" edge case.\n if (!a || !b) {\n return a === b;\n }\n\n const ta = typeof a;\n const tb = typeof b;\n\n if (ta !== tb) return false;\n\n if (ta === \"function\") return true;\n\n if (ta === \"object\") {\n const ea = Object.entries(a);\n const kb = Object.keys(b);\n\n // Length not equal -> false\n if (ea.length !== kb.length) return false;\n\n for (const [key, va] of ea) {\n const vb = b[key];\n\n // Early return when any not equal\n if (!deepCompare(va, vb)) return false;\n }\n\n // If it gets through all, it's equal\n return true;\n }\n\n return a === b;\n}\n"],"mappings":"AAYO,SAAS,YAAY,GAAQ,GAAQ;AAE1C,MAAI,CAAC,KAAK,CAAC,GAAG;AACZ,WAAO,MAAM;AAAA,EACf;AAEA,QAAM,KAAK,OAAO;AAClB,QAAM,KAAK,OAAO;AAElB,MAAI,OAAO,GAAI,QAAO;AAEtB,MAAI,OAAO,WAAY,QAAO;AAE9B,MAAI,OAAO,UAAU;AACnB,UAAM,KAAK,OAAO,QAAQ,CAAC;AAC3B,UAAM,KAAK,OAAO,KAAK,CAAC;AAGxB,QAAI,GAAG,WAAW,GAAG,OAAQ,QAAO;AAEpC,eAAW,CAAC,KAAK,EAAE,KAAK,IAAI;AAC1B,YAAM,KAAK,EAAE,GAAG;AAGhB,UAAI,CAAC,YAAY,IAAI,EAAE,EAAG,QAAO;AAAA,IACnC;AAGA,WAAO;AAAA,EACT;AAEA,SAAO,MAAM;AACf;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Does deep compare of 2 items, returning `true` if equal.\n *\n * - Functions: Always `true`\n * - Primitives: Returns direct `a === b`\n * - Arrays: Returns same items and ordering (recursive)\n * - Objects: Returns same keys / values (recursive)\n *\n * @param a Item a\n * @param b Item b\n * @returns a === b\n */\nexport function deepCompare(a: any, b: any) {\n // Short path for falsy. Important to catch typeof null === \"object\" edge case.\n if (!a || !b) {\n return a === b;\n }\n\n const ta = typeof a;\n const tb = typeof b;\n\n if (ta !== tb) return false;\n\n if (ta === \"function\") return true;\n\n if (ta === \"object\") {\n const ea = Object.entries(a);\n const kb = Object.keys(b);\n\n // Length not equal -> false\n if (ea.length !== kb.length) return false;\n\n for (const [key, va] of ea) {\n const vb = b[key];\n\n // Early return when any not equal\n if (!deepCompare(va, vb)) return false;\n }\n\n // If it gets through all, it's equal\n return true;\n }\n\n return a === b;\n}\n\nexport function filterBySplit<T>(\n items: T[] | undefined,\n search: string,\n extract: (item: T) => string,\n) {\n const split = search.toLowerCase().split(\" \");\n return (\n (split.length\n ? items?.filter((item) => {\n const target = extract(item).toLowerCase();\n return split.every((term) => target.includes(term));\n })\n : items) ?? []\n );\n}\n\nexport function filterMultitermBySplit<T>(\n items: T[] | undefined,\n search: string,\n extract: (item: T) => (string | undefined)[],\n) {\n const split = search.toLowerCase().split(\" \");\n return (\n (split.length\n ? items?.filter((item) => {\n const target = extract(item)\n .filter((str) => str)\n .map((str) => str!.toLowerCase());\n return split.every(\n (term) => target.findIndex((t) => t.includes(term)) !== -1,\n );\n })\n : items) ?? []\n );\n}"],"mappings":"AAYO,SAAS,YAAY,GAAQ,GAAQ;AAE1C,MAAI,CAAC,KAAK,CAAC,GAAG;AACZ,WAAO,MAAM;AAAA,EACf;AAEA,QAAM,KAAK,OAAO;AAClB,QAAM,KAAK,OAAO;AAElB,MAAI,OAAO,GAAI,QAAO;AAEtB,MAAI,OAAO,WAAY,QAAO;AAE9B,MAAI,OAAO,UAAU;AACnB,UAAM,KAAK,OAAO,QAAQ,CAAC;AAC3B,UAAM,KAAK,OAAO,KAAK,CAAC;AAGxB,QAAI,GAAG,WAAW,GAAG,OAAQ,QAAO;AAEpC,eAAW,CAAC,KAAK,EAAE,KAAK,IAAI;AAC1B,YAAM,KAAK,EAAE,GAAG;AAGhB,UAAI,CAAC,YAAY,IAAI,EAAE,EAAG,QAAO;AAAA,IACnC;AAGA,WAAO;AAAA,EACT;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,cACd,OACA,QACA,SACA;AACA,QAAM,QAAQ,OAAO,YAAY,EAAE,MAAM,GAAG;AAC5C,UACG,MAAM,SACH,OAAO,OAAO,CAAC,SAAS;AACtB,UAAM,SAAS,QAAQ,IAAI,EAAE,YAAY;AACzC,WAAO,MAAM,MAAM,CAAC,SAAS,OAAO,SAAS,IAAI,CAAC;AAAA,EACpD,CAAC,IACD,UAAU,CAAC;AAEnB;AAEO,SAAS,uBACd,OACA,QACA,SACA;AACA,QAAM,QAAQ,OAAO,YAAY,EAAE,MAAM,GAAG;AAC5C,UACG,MAAM,SACH,OAAO,OAAO,CAAC,SAAS;AACtB,UAAM,SAAS,QAAQ,IAAI,EACxB,OAAO,CAAC,QAAQ,GAAG,EACnB,IAAI,CAAC,QAAQ,IAAK,YAAY,CAAC;AAClC,WAAO,MAAM;AAAA,MACX,CAAC,SAAS,OAAO,UAAU,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,MAAM;AAAA,IAC1D;AAAA,EACF,CAAC,IACD,UAAU,CAAC;AAEnB;","names":[]}
|