@kcuf/helper-data 0.5.1 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.6.0 2026/04/03 @驳是
4
+
5
+ * FEAT 新增 `localSearchCompare`
6
+
3
7
  ## 0.5.0 2025/12/24 @驳是
4
8
 
5
9
  * FEAT 移除 `toTreeList`,请用 `@kcuf/helper-tree`
@@ -10,6 +10,12 @@ Object.defineProperty(exports, "isEmptyPagedList", {
10
10
  return _isEmptyPagedList.default;
11
11
  }
12
12
  });
13
+ Object.defineProperty(exports, "localSearchCompare", {
14
+ enumerable: true,
15
+ get: function get() {
16
+ return _localSearchCompare.default;
17
+ }
18
+ });
13
19
  Object.defineProperty(exports, "normalizeBoolean", {
14
20
  enumerable: true,
15
21
  get: function get() {
@@ -59,4 +65,5 @@ var _normalizeEnum = _interopRequireDefault(require("./normalize-enum"));
59
65
  var _normalizeTime = _interopRequireDefault(require("./normalize-time"));
60
66
  var _normalizePagedList = _interopRequireDefault(require("./normalize-paged-list"));
61
67
  var _normalizePagedListUncertain = _interopRequireDefault(require("./normalize-paged-list-uncertain"));
62
- var _isEmptyPagedList = _interopRequireDefault(require("./is-empty-paged-list"));
68
+ var _isEmptyPagedList = _interopRequireDefault(require("./is-empty-paged-list"));
69
+ var _localSearchCompare = _interopRequireDefault(require("./local-search-compare"));
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = localSearchCompare;
7
+ function normalizeStrForCompare(str, ignoreWhitespace) {
8
+ var strLower = str.trim().toLowerCase();
9
+ return strLower.replace(/\s+/g, ignoreWhitespace ? '' : ' ');
10
+ }
11
+
12
+ /**
13
+ * 本地搜索时的比较方法,使用 keyword 匹配可选的字符串数组,注意当 keyword 为空时,返回 true
14
+ */
15
+ function localSearchCompare(keyword, candidateValues) {
16
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
17
+ var _options$ignoreWhites = options.ignoreWhitespace,
18
+ ignoreWhitespace = _options$ignoreWhites === void 0 ? true : _options$ignoreWhites,
19
+ _options$bothWay = options.bothWay,
20
+ bothWay = _options$bothWay === void 0 ? true : _options$bothWay;
21
+ var kw = normalizeStrForCompare(keyword, ignoreWhitespace);
22
+ if (!kw) {
23
+ return true;
24
+ }
25
+ return candidateValues.some(function (v) {
26
+ var candidate = normalizeStrForCompare(v, ignoreWhitespace);
27
+ return candidate.includes(kw) || (bothWay ? kw.includes(candidate) : kw.includes(candidate));
28
+ });
29
+ }
@@ -6,4 +6,5 @@ export { default as normalizeTime } from './normalize-time';
6
6
  export { default as normalizePagedList } from './normalize-paged-list';
7
7
  export { default as normalizePagedListUncertain } from './normalize-paged-list-uncertain';
8
8
  export { default as isEmptyPagedList } from './is-empty-paged-list';
9
+ export { default as localSearchCompare } from './local-search-compare';
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default","normalizeId","normalizeBoolean","normalizeNumber","normalizeEnum","normalizeTime","normalizePagedList","normalizePagedListUncertain","isEmptyPagedList"],"sources":["../../../src/helper/index.ts"],"sourcesContent":["export { default as normalizeId } from './normalize-id';\nexport { default as normalizeBoolean } from './normalize-boolean';\nexport { default as normalizeNumber } from './normalize-number';\nexport { default as normalizeEnum } from './normalize-enum';\nexport { default as normalizeTime } from './normalize-time';\nexport { default as normalizePagedList } from './normalize-paged-list';\nexport { default as normalizePagedListUncertain } from './normalize-paged-list-uncertain';\n\nexport { default as isEmptyPagedList } from './is-empty-paged-list';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAAW,QAAQ,gBAAgB;AACvD,SAASD,OAAO,IAAIE,gBAAgB,QAAQ,qBAAqB;AACjE,SAASF,OAAO,IAAIG,eAAe,QAAQ,oBAAoB;AAC/D,SAASH,OAAO,IAAII,aAAa,QAAQ,kBAAkB;AAC3D,SAASJ,OAAO,IAAIK,aAAa,QAAQ,kBAAkB;AAC3D,SAASL,OAAO,IAAIM,kBAAkB,QAAQ,wBAAwB;AACtE,SAASN,OAAO,IAAIO,2BAA2B,QAAQ,kCAAkC;AAEzF,SAASP,OAAO,IAAIQ,gBAAgB,QAAQ,uBAAuB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["default","normalizeId","normalizeBoolean","normalizeNumber","normalizeEnum","normalizeTime","normalizePagedList","normalizePagedListUncertain","isEmptyPagedList","localSearchCompare"],"sources":["../../../src/helper/index.ts"],"sourcesContent":["export { default as normalizeId } from './normalize-id';\nexport { default as normalizeBoolean } from './normalize-boolean';\nexport { default as normalizeNumber } from './normalize-number';\nexport { default as normalizeEnum } from './normalize-enum';\nexport { default as normalizeTime } from './normalize-time';\nexport { default as normalizePagedList } from './normalize-paged-list';\nexport { default as normalizePagedListUncertain } from './normalize-paged-list-uncertain';\n\nexport { default as isEmptyPagedList } from './is-empty-paged-list';\nexport { default as localSearchCompare } from './local-search-compare';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAAW,QAAQ,gBAAgB;AACvD,SAASD,OAAO,IAAIE,gBAAgB,QAAQ,qBAAqB;AACjE,SAASF,OAAO,IAAIG,eAAe,QAAQ,oBAAoB;AAC/D,SAASH,OAAO,IAAII,aAAa,QAAQ,kBAAkB;AAC3D,SAASJ,OAAO,IAAIK,aAAa,QAAQ,kBAAkB;AAC3D,SAASL,OAAO,IAAIM,kBAAkB,QAAQ,wBAAwB;AACtE,SAASN,OAAO,IAAIO,2BAA2B,QAAQ,kCAAkC;AAEzF,SAASP,OAAO,IAAIQ,gBAAgB,QAAQ,uBAAuB;AACnE,SAASR,OAAO,IAAIS,kBAAkB,QAAQ,wBAAwB","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ function normalizeStrForCompare(str, ignoreWhitespace) {
2
+ var strLower = str.trim().toLowerCase();
3
+ return strLower.replace(/\s+/g, ignoreWhitespace ? '' : ' ');
4
+ }
5
+
6
+ /**
7
+ * 本地搜索时的比较方法,使用 keyword 匹配可选的字符串数组,注意当 keyword 为空时,返回 true
8
+ */
9
+ export default function localSearchCompare(keyword, candidateValues) {
10
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11
+ var _options$ignoreWhites = options.ignoreWhitespace,
12
+ ignoreWhitespace = _options$ignoreWhites === void 0 ? true : _options$ignoreWhites,
13
+ _options$bothWay = options.bothWay,
14
+ bothWay = _options$bothWay === void 0 ? true : _options$bothWay;
15
+ var kw = normalizeStrForCompare(keyword, ignoreWhitespace);
16
+ if (!kw) {
17
+ return true;
18
+ }
19
+ return candidateValues.some(function (v) {
20
+ var candidate = normalizeStrForCompare(v, ignoreWhitespace);
21
+ return candidate.includes(kw) || (bothWay ? kw.includes(candidate) : kw.includes(candidate));
22
+ });
23
+ }
24
+ //# sourceMappingURL=local-search-compare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-search-compare.js","names":["normalizeStrForCompare","str","ignoreWhitespace","strLower","trim","toLowerCase","replace","localSearchCompare","keyword","candidateValues","options","arguments","length","undefined","_options$ignoreWhites","_options$bothWay","bothWay","kw","some","v","candidate","includes"],"sources":["../../../src/helper/local-search-compare.ts"],"sourcesContent":["interface IOptions {\n /**\n * 是否忽略中间的空格,默认 true,当 false 时,也会去除两端的空格,并且将连续的空格转成单个空格\n */\n ignoreWhitespace?: boolean;\n /**\n * 是否判断反向包含,默认 true\n *\n * | bothWay | 关键字 | 候选项 | 结果 |\n * | --- | --- | --- | --- |\n * | `false` | AB | ABC | `true` |\n * | `false` | ABC | AB | `false` |\n * | `true` | AB | ABC | `true` |\n * | `true` | ABC | AB | `true` |\n */\n bothWay?: boolean;\n}\n\nfunction normalizeStrForCompare(str: string, ignoreWhitespace: boolean): string {\n const strLower = str.trim().toLowerCase();\n \n return strLower.replace(/\\s+/g, ignoreWhitespace ? '' : ' ');\n}\n\n/**\n * 本地搜索时的比较方法,使用 keyword 匹配可选的字符串数组,注意当 keyword 为空时,返回 true\n */\nexport default function localSearchCompare(keyword: string, candidateValues: string[], options: IOptions = {}): boolean {\n const {\n ignoreWhitespace = true,\n bothWay = true\n } = options;\n const kw = normalizeStrForCompare(keyword, ignoreWhitespace);\n \n if (!kw) {\n return true;\n }\n \n return candidateValues.some(v => {\n const candidate = normalizeStrForCompare(v, ignoreWhitespace);\n \n return candidate.includes(kw) || (bothWay ? kw.includes(candidate) : kw.includes(candidate));\n });\n}\n"],"mappings":"AAkBA,SAASA,sBAAsBA,CAACC,GAAW,EAAEC,gBAAyB,EAAU;EAC9E,IAAMC,QAAQ,GAAGF,GAAG,CAACG,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC;EAEzC,OAAOF,QAAQ,CAACG,OAAO,CAAC,MAAM,EAAEJ,gBAAgB,GAAG,EAAE,GAAG,GAAG,CAAC;AAC9D;;AAEA;AACA;AACA;AACA,eAAe,SAASK,kBAAkBA,CAACC,OAAe,EAAEC,eAAyB,EAAmC;EAAA,IAAjCC,OAAiB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC3G,IAAAG,qBAAA,GAGIJ,OAAO,CAFTR,gBAAgB;IAAhBA,gBAAgB,GAAAY,qBAAA,cAAG,IAAI,GAAAA,qBAAA;IAAAC,gBAAA,GAErBL,OAAO,CADTM,OAAO;IAAPA,OAAO,GAAAD,gBAAA,cAAG,IAAI,GAAAA,gBAAA;EAEhB,IAAME,EAAE,GAAGjB,sBAAsB,CAACQ,OAAO,EAAEN,gBAAgB,CAAC;EAE5D,IAAI,CAACe,EAAE,EAAE;IACP,OAAO,IAAI;EACb;EAEA,OAAOR,eAAe,CAACS,IAAI,CAAC,UAAAC,CAAC,EAAI;IAC/B,IAAMC,SAAS,GAAGpB,sBAAsB,CAACmB,CAAC,EAAEjB,gBAAgB,CAAC;IAE7D,OAAOkB,SAAS,CAACC,QAAQ,CAACJ,EAAE,CAAC,KAAKD,OAAO,GAAGC,EAAE,CAACI,QAAQ,CAACD,SAAS,CAAC,GAAGH,EAAE,CAACI,QAAQ,CAACD,SAAS,CAAC,CAAC;EAC9F,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -6,3 +6,4 @@ export { default as normalizeTime } from './normalize-time';
6
6
  export { default as normalizePagedList } from './normalize-paged-list';
7
7
  export { default as normalizePagedListUncertain } from './normalize-paged-list-uncertain';
8
8
  export { default as isEmptyPagedList } from './is-empty-paged-list';
9
+ export { default as localSearchCompare } from './local-search-compare';
@@ -0,0 +1,22 @@
1
+ interface IOptions {
2
+ /**
3
+ * 是否忽略中间的空格,默认 true,当 false 时,也会去除两端的空格,并且将连续的空格转成单个空格
4
+ */
5
+ ignoreWhitespace?: boolean;
6
+ /**
7
+ * 是否判断反向包含,默认 true
8
+ *
9
+ * | bothWay | 关键字 | 候选项 | 结果 |
10
+ * | --- | --- | --- | --- |
11
+ * | `false` | AB | ABC | `true` |
12
+ * | `false` | ABC | AB | `false` |
13
+ * | `true` | AB | ABC | `true` |
14
+ * | `true` | ABC | AB | `true` |
15
+ */
16
+ bothWay?: boolean;
17
+ }
18
+ /**
19
+ * 本地搜索时的比较方法,使用 keyword 匹配可选的字符串数组,注意当 keyword 为空时,返回 true
20
+ */
21
+ export default function localSearchCompare(keyword: string, candidateValues: string[], options?: IOptions): boolean;
22
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kcuf/helper-data",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Data normalizer helpers and loading stuff to make all frontend data processing sane.",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -22,14 +22,14 @@
22
22
  "access": "public"
23
23
  },
24
24
  "devDependencies": {
25
- "@babel/cli": "^7.28.3",
26
- "@babel/core": "^7.28.5",
27
- "@babel/plugin-transform-runtime": "^7.28.5",
28
- "@babel/preset-env": "^7.28.5",
25
+ "@babel/cli": "^7.28.6",
26
+ "@babel/core": "^7.29.0",
27
+ "@babel/plugin-transform-runtime": "^7.29.0",
28
+ "@babel/preset-env": "^7.29.2",
29
29
  "@babel/preset-typescript": "^7.28.5",
30
- "rimraf": "^6.1.2",
31
- "typescript": "^5.9.3",
32
- "@kcuf/ts-config": "^0.1.0"
30
+ "rimraf": "^6.1.3",
31
+ "typescript": "^6.0.2",
32
+ "@kcuf/ts-config": "^0.2.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@babel/runtime": ">=7.0.0"