@orchidjs/sifter 1.0.3 → 1.2.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/README.md +8 -10
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/sifter.d.ts +72 -0
- package/dist/cjs/sifter.js +275 -1101
- package/dist/cjs/sifter.js.map +1 -1
- package/dist/cjs/types.d.ts +58 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.d.ts +48 -0
- package/dist/cjs/utils.js +104 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/sifter.d.ts +72 -0
- package/dist/esm/sifter.js +266 -330
- package/dist/esm/sifter.js.map +1 -1
- package/dist/esm/types.d.ts +58 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.d.ts +48 -0
- package/dist/esm/utils.js +56 -56
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/sifter.d.ts +5 -4
- package/dist/types/types.d.ts +13 -12
- package/dist/types/utils.d.ts +2 -2
- package/dist/umd/package.json +1 -0
- package/dist/umd/sifter.js +808 -1037
- package/dist/umd/sifter.js.map +1 -1
- package/dist/umd/sifter.min.js +66 -66
- package/dist/umd/sifter.min.js.map +1 -1
- package/lib/sifter.ts +9 -9
- package/lib/types.ts +4 -2
- package/lib/utils.ts +4 -2
- package/package.json +31 -21
- package/dist/esm/lib/sifter.js +0 -368
- package/dist/esm/lib/sifter.js.map +0 -1
- package/dist/esm/lib/utils.js +0 -95
- package/dist/esm/lib/utils.js.map +0 -1
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/index.js +0 -547
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/index.js.map +0 -1
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/regex.js +0 -113
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/regex.js.map +0 -1
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/strings.js +0 -29
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/strings.js.map +0 -1
package/dist/esm/sifter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sifter.js","sources":["../../lib/sifter.ts"],"sourcesContent":["/**\n * sifter.js\n * Copyright (c) 2013–2020 Brian Reavis & contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n * @author Brian Reavis <brian@thirdroute.com>\n */\n\nimport { scoreValue, getAttr, getAttrNesting, propToArray, iterate, cmp } from './utils';\nimport { getPattern, escape_regex } from '@orchidjs/unicode-variants';\nimport * as T from './types';\n\nclass Sifter{\n\n\tpublic items: any; // []|{};\n\tpublic settings: T.Settings;\n\n\t/**\n\t * Textually searches arrays and hashes of objects\n\t * by property (or multiple properties). Designed\n\t * specifically for autocomplete.\n\t *\n\t */\n\tconstructor(items:any, settings:T.Settings) {\n\t\tthis.items = items;\n\t\tthis.settings = settings || {diacritics: true};\n\t};\n\n\t/**\n\t * Splits a search string into an array of individual\n\t * regexps to be used to match results.\n\t *\n\t */\n\ttokenize(query:string, respect_word_boundaries?:boolean, weights?:T.Weights ):T.Token[] {\n\t\tif (!query || !query.length) return [];\n\n\t\tconst tokens:T.Token[]\t= [];\n\t\tconst words\t\t\t\t= query.split(/\\s+/);\n\t\tvar field_regex:RegExp;\n\n\t\tif( weights ){\n\t\t\tfield_regex = new RegExp( '^('+ Object.keys(weights).map(escape_regex).join('|')+')\\:(.*)$');\n\t\t}\n\n\t\twords.forEach((word:string) => {\n\t\t\tlet field_match;\n\t\t\tlet field:null|string\t= null;\n\t\t\tlet regex:null|string\t= null;\n\n\t\t\t// look for \"field:query\" tokens\n\t\t\tif( field_regex && (field_match = word.match(field_regex)) ){\n\t\t\t\tfield\t= field_match[1]!;\n\t\t\t\tword\t= field_match[2]!;\n\t\t\t}\n\n\t\t\tif( word.length > 0 ){\n\t\t\t\tif( this.settings.diacritics ){\n\t\t\t\t\tregex = getPattern(word) || null;\n\t\t\t\t}else{\n\t\t\t\t\tregex = escape_regex(word);\n\t\t\t\t}\n\t\t\t\tif( regex && respect_word_boundaries ) regex = \"\\\\b\"+regex;\n\t\t\t}\n\n\t\t\ttokens.push({\n\t\t\t\tstring : word,\n\t\t\t\tregex : regex ? new RegExp(regex,'iu') : null,\n\t\t\t\tfield : field,\n\t\t\t});\n\t\t});\n\n\t\treturn tokens;\n\t};\n\n\n\t/**\n\t * Returns a function to be used to score individual results.\n\t *\n\t * Good matches will have a higher score than poor matches.\n\t * If an item is not a match, 0 will be returned by the function.\n\t *\n\t * @returns {T.ScoreFn}\n\t */\n\tgetScoreFunction(query:string, options:T.Options ){\n\t\tvar search = this.prepareSearch(query, options);\n\t\treturn this._getScoreFunction(search);\n\t}\n\n\t/**\n\t * @returns {T.ScoreFn}\n\t *\n\t */\n\t_getScoreFunction(search:T.PrepareObj ){\n\t\tconst tokens\t\t= search.tokens,\n\t\ttoken_count\t\t\t= tokens.length;\n\n\t\tif (!token_count) {\n\t\t\treturn function() { return 0; };\n\t\t}\n\n\t\tconst fields\t= search.options.fields,\n\t\tweights\t\t\t= search.weights,\n\t\tfield_count\t\t= fields.length,\n\t\tgetAttrFn\t\t= search.getAttrFn;\n\n\t\tif (!field_count) {\n\t\t\treturn function() { return 1; };\n\t\t}\n\n\n\t\t/**\n\t\t * Calculates the score of an object\n\t\t * against the search query.\n\t\t *\n\t\t */\n\t\tconst scoreObject = (function() {\n\n\n\t\t\tif (field_count === 1) {\n\t\t\t\treturn function(token:T.Token, data:{}) {\n\t\t\t\t\tconst field = fields[0]!.field;\n\t\t\t\t\treturn scoreValue(getAttrFn(data, field), token, weights[field]||1);\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn function(token:T.Token, data:{}) {\n\t\t\t\tvar sum = 0;\n\n\t\t\t\t// is the token specific to a field?\n\t\t\t\tif( token.field ){\n\n\t\t\t\t\tconst value = getAttrFn(data, token.field);\n\n\t\t\t\t\tif( !token.regex && value ){\n\t\t\t\t\t\tsum += (1/field_count);\n\t\t\t\t\t}else{\n\t\t\t\t\t\tsum += scoreValue(value, token, 1);\n\t\t\t\t\t}\n\n\n\n\t\t\t\t}else{\n\t\t\t\t\titerate(weights, (weight:number, field:string) => {\n\t\t\t\t\t\tsum += scoreValue(getAttrFn(data, field), token, weight);\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\treturn sum / field_count;\n\t\t\t};\n\t\t})();\n\n\t\tif (token_count === 1) {\n\t\t\treturn function(data:{}) {\n\t\t\t\treturn scoreObject(tokens[0]!, data);\n\t\t\t};\n\t\t}\n\n\t\tif (search.options.conjunction === 'and') {\n\t\t\treturn function(data:{}) {\n\t\t\t\tvar score, sum = 0;\n\t\t\t\tfor( let token of tokens){\n\t\t\t\t\tscore = scoreObject(token, data);\n\t\t\t\t\tif (score <= 0) return 0;\n\t\t\t\t\tsum += score;\n\t\t\t\t}\n\t\t\t\treturn sum / token_count;\n\t\t\t};\n\t\t} else {\n\t\t\treturn function(data:{}) {\n\t\t\t\tvar sum = 0;\n\t\t\t\titerate(tokens,(token:T.Token)=>{\n\t\t\t\t\tsum += scoreObject(token, data);\n\t\t\t\t});\n\t\t\t\treturn sum / token_count;\n\t\t\t};\n\t\t}\n\t};\n\n\t/**\n\t * Returns a function that can be used to compare two\n\t * results, for sorting purposes. If no sorting should\n\t * be performed, `null` will be returned.\n\t *\n\t * @return function(a,b)\n\t */\n\tgetSortFunction(query:string, options:Partial<T.Options>) {\n\t\tvar search = this.prepareSearch(query, options);\n\t\treturn this._getSortFunction(search);\n\t}\n\n\t_getSortFunction(search:T.PrepareObj){\n\t\tvar implicit_score,\n\t\tsort_flds:T.Sort[]\t= [];\n\n\t\tconst self\t= this,\n\t\toptions\t\t= search.options,\n\t\tsort\t\t= (!search.query && options.sort_empty) ? options.sort_empty : options.sort;\n\n\n\t\tif( typeof sort == 'function' ){\n\t\t\treturn sort.bind(this);\n\t\t}\n\n\t\t/**\n\t\t * Fetches the specified sort field value\n\t\t * from a search result item.\n\t\t *\n\t\t */\n\t\tconst get_field = function(name:string, result:T.ResultItem):string|number {\n\t\t\tif (name === '$score') return result.score;\n\t\t\treturn search.getAttrFn(self.items[result.id], name);\n\t\t};\n\n\t\t// parse options\n\t\tif (sort) {\n\t\t\tfor( let s of sort ){\n\t\t\t\tif (search.query || s.field !== '$score') {\n\t\t\t\t\tsort_flds.push(s);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// the \"$score\" field is implied to be the primary\n\t\t// sort field, unless it's manually specified\n\t\tif (search.query) {\n\t\t\timplicit_score = true;\n\t\t\tfor( let fld of sort_flds ){\n\t\t\t\tif( fld.field === '$score' ){\n\t\t\t\t\timplicit_score = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (implicit_score) {\n\t\t\t\tsort_flds.unshift({field: '$score', direction: 'desc'});\n\t\t\t}\n\n\t\t// without a search.query, all items will have the same score\n\t\t} else {\n\t\t\tsort_flds = sort_flds.filter((fld) => fld.field !== '$score' );\n\t\t}\n\n\n\t\t// build function\n\t\tconst sort_flds_count = sort_flds.length;\n\t\tif (!sort_flds_count) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn function(a:T.ResultItem, b:T.ResultItem) {\n\t\t\tvar result, field;\n\t\t\tfor( let sort_fld of sort_flds ){\n\t\t\t\tfield = sort_fld.field;\n\n\t\t\t\tlet\tmultiplier = sort_fld.direction === 'desc' ? -1 : 1;\n\n\t\t\t\tresult = multiplier * cmp(\n\t\t\t\t\tget_field(field, a),\n\t\t\t\t\tget_field(field, b)\n\t\t\t\t);\n\t\t\t\tif (result) return result;\n\t\t\t}\n\t\t\treturn 0;\n\t\t};\n\n\t};\n\n\t/**\n\t * Parses a search query and returns an object\n\t * with tokens and fields ready to be populated\n\t * with results.\n\t *\n\t */\n\tprepareSearch(query:string, optsUser:Partial<T.Options>):T.PrepareObj {\n\t\tconst weights:T.Weights = {};\n\t\tvar options\t\t= Object.assign({},optsUser) as T.Options;\n\n\t\tpropToArray(options,'sort');\n\t\tpropToArray(options,'sort_empty');\n\n\t\t// convert fields to new format\n\t\tif( options.fields ){\n\t\t\tpropToArray(options,'fields');\n\t\t\tconst fields:T.Field[] = [];\n\t\t\toptions.fields.forEach((field:string|T.Field) => {\n\t\t\t\tif( typeof field == 'string' ){\n\t\t\t\t\tfield = {field:field,weight:1};\n\t\t\t\t}\n\t\t\t\tfields.push(field);\n\t\t\t\tweights[field.field] = ('weight' in field) ? field.weight : 1;\n\t\t\t});\n\t\t\toptions.fields = fields;\n\t\t}\n\n\n\t\treturn {\n\t\t\toptions\t\t: options as T.Options,\n\t\t\tquery\t\t: query.toLowerCase().trim(),\n\t\t\ttokens\t\t: this.tokenize(query, options.respect_word_boundaries, weights),\n\t\t\ttotal\t\t: 0,\n\t\t\titems\t\t: [],\n\t\t\tweights\t\t: weights,\n\t\t\tgetAttrFn\t: (options.nesting) ? getAttrNesting : getAttr,\n\t\t};\n\t};\n\n\t/**\n\t * Searches through all items and returns a sorted array of matches.\n\t *\n\t */\n\tsearch(query:string, options:T.Options) : T.PrepareObj {\n\t\tvar self = this, score, search: T.PrepareObj;\n\n\t\tsearch = this.prepareSearch(query, options);\n\t\toptions = search.options;\n\t\tquery = search.query;\n\n\t\t// generate result scoring function\n\t\tconst fn_score:T.ScoreFn = options.score || self._getScoreFunction(search);\n\n\t\t// perform search and sort\n\t\tif (query.length) {\n\t\t\titerate(self.items, (item:T.ResultItem, id:string|number) => {\n\t\t\t\tscore = fn_score(item);\n\t\t\t\tif (options.filter === false || score > 0) {\n\t\t\t\t\tsearch.items.push({'score': score, 'id': id});\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\titerate(self.items, (_:T.ResultItem, id:string|number) => {\n\t\t\t\tsearch.items.push({'score': 1, 'id': id});\n\t\t\t});\n\t\t}\n\n\t\tconst fn_sort = self._getSortFunction(search);\n\t\tif (fn_sort) search.items.sort(fn_sort);\n\n\t\t// apply limits\n\t\tsearch.total = search.items.length;\n\t\tif (typeof options.limit === 'number') {\n\t\t\tsearch.items = search.items.slice(0, options.limit);\n\t\t}\n\n\t\treturn search;\n\t};\n}\n\nexport { Sifter, scoreValue, getAttr, getAttrNesting, propToArray, iterate, cmp, getPattern }\n"],"names":["Sifter","constructor","items","settings","diacritics","tokenize","query","respect_word_boundaries","weights","length","tokens","words","split","field_regex","RegExp","Object","keys","map","escape_regex","join","forEach","word","field_match","field","regex","match","getPattern","push","string","getScoreFunction","options","search","prepareSearch","_getScoreFunction","token_count","fields","field_count","getAttrFn","scoreObject","token","data","scoreValue","sum","value","iterate","weight","conjunction","score","getSortFunction","_getSortFunction","implicit_score","sort_flds","self","sort","sort_empty","bind","get_field","name","result","id","s","fld","unshift","direction","filter","sort_flds_count","a","b","sort_fld","multiplier","cmp","optsUser","assign","propToArray","toLowerCase","trim","total","nesting","getAttrNesting","getAttr","fn_score","item","_","fn_sort","limit","slice"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,MAAMA,MAAN,CAAY;AAEQ;;AAGnB;AACD;AACA;AACA;AACA;AACA;AACCC,EAAAA,WAAW,CAACC,KAAD,EAAYC,QAAZ,EAAiC;AAAA,SATrCD,KASqC;AAAA,SARrCC,QAQqC;AAC3C,SAAKD,KAAL,GAAaA,KAAb;AACA,SAAKC,QAAL,GAAgBA,QAAQ,IAAI;AAACC,MAAAA,UAAU,EAAE;AAAb,KAA5B;AACA;;AAED;AACD;AACA;AACA;AACA;AACCC,EAAAA,QAAQ,CAAC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B,EAAE,EAAE;gBAClD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAC,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,OAAO;YAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAExC,eAAe;QACf,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QACnC,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvC,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAAA,CAAC;CACF;AAED,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Sifter } from './sifter.ts';
|
|
2
|
+
export type Field = {
|
|
3
|
+
field: string;
|
|
4
|
+
weight: number;
|
|
5
|
+
};
|
|
6
|
+
export type Sort = {
|
|
7
|
+
field: string;
|
|
8
|
+
direction?: string;
|
|
9
|
+
};
|
|
10
|
+
export type SortFn = (this: Sifter, a: ResultItem, b: ResultItem) => number;
|
|
11
|
+
export type UserOptions = {
|
|
12
|
+
fields: string[] | Field[];
|
|
13
|
+
conjunction: string;
|
|
14
|
+
sort: string | SortFn | Sort[];
|
|
15
|
+
nesting?: boolean;
|
|
16
|
+
score?: ScoreFn;
|
|
17
|
+
filter?: boolean;
|
|
18
|
+
sort_empty?: SortFn | Sort[];
|
|
19
|
+
respect_word_boundaries?: boolean;
|
|
20
|
+
limit?: number;
|
|
21
|
+
};
|
|
22
|
+
export type Options = {
|
|
23
|
+
fields: Field[];
|
|
24
|
+
conjunction: string;
|
|
25
|
+
sort: SortFn | Sort[];
|
|
26
|
+
nesting?: boolean;
|
|
27
|
+
score?: ScoreFn;
|
|
28
|
+
filter?: boolean;
|
|
29
|
+
sort_empty?: SortFn | Sort[];
|
|
30
|
+
respect_word_boundaries?: boolean;
|
|
31
|
+
limit?: number;
|
|
32
|
+
};
|
|
33
|
+
export type Token = {
|
|
34
|
+
string: string;
|
|
35
|
+
regex: RegExp | null;
|
|
36
|
+
field: string | null;
|
|
37
|
+
};
|
|
38
|
+
export type Weights = {
|
|
39
|
+
[key: string]: number;
|
|
40
|
+
};
|
|
41
|
+
export type PrepareObj = {
|
|
42
|
+
options: Options;
|
|
43
|
+
query: string;
|
|
44
|
+
tokens: Token[];
|
|
45
|
+
total: number;
|
|
46
|
+
items: ResultItem[];
|
|
47
|
+
weights: Weights;
|
|
48
|
+
getAttrFn: (data: any, field: string) => any;
|
|
49
|
+
};
|
|
50
|
+
export type Settings = {
|
|
51
|
+
diacritics: boolean;
|
|
52
|
+
};
|
|
53
|
+
export type ResultItem<T = any> = {
|
|
54
|
+
score: number;
|
|
55
|
+
id: number | string;
|
|
56
|
+
item: T;
|
|
57
|
+
};
|
|
58
|
+
export type ScoreFn = (item: ResultItem) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type * as T from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* A property getter resolving dot-notation
|
|
4
|
+
* @param {Object} obj The root object to fetch property on
|
|
5
|
+
* @param {String} name The optionally dotted property name to fetch
|
|
6
|
+
* @return {Object} The resolved property value
|
|
7
|
+
*/
|
|
8
|
+
export declare const getAttr: (obj: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}, name: string) => any;
|
|
11
|
+
/**
|
|
12
|
+
* A property getter resolving dot-notation
|
|
13
|
+
* @param {Object} obj The root object to fetch property on
|
|
14
|
+
* @param {String} name The optionally dotted property name to fetch
|
|
15
|
+
* @return {Object} The resolved property value
|
|
16
|
+
*/
|
|
17
|
+
export declare const getAttrNesting: (obj: {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}, name: string) => {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
} | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Calculates how close of a match the
|
|
24
|
+
* given value is against a search token.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
export declare const scoreValue: (value: string, token: T.Token, weight: number) => number;
|
|
28
|
+
/**
|
|
29
|
+
* Cast object property to an array if it exists and has a value
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
export declare const propToArray: (obj: {
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}, key: string) => any;
|
|
35
|
+
/**
|
|
36
|
+
* Iterates over arrays and hashes.
|
|
37
|
+
*
|
|
38
|
+
* ```
|
|
39
|
+
* iterate(this.items, function(item, id) {
|
|
40
|
+
* // invoked for each item
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
export declare const iterate: (object: [] | {
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}, callback: (value: any, key: any) => any) => void;
|
|
48
|
+
export declare const cmp: (a: number | string, b: number | string) => 0 | 1 | -1;
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
/*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */
|
|
2
1
|
import { asciifold } from '@orchidjs/unicode-variants';
|
|
3
|
-
|
|
4
2
|
/**
|
|
5
3
|
* A property getter resolving dot-notation
|
|
6
4
|
* @param {Object} obj The root object to fetch property on
|
|
7
5
|
* @param {String} name The optionally dotted property name to fetch
|
|
8
6
|
* @return {Object} The resolved property value
|
|
9
7
|
*/
|
|
10
|
-
const getAttr = (obj, name) => {
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export const getAttr = (obj, name) => {
|
|
9
|
+
if (!obj)
|
|
10
|
+
return;
|
|
11
|
+
return obj[name];
|
|
13
12
|
};
|
|
14
13
|
/**
|
|
15
14
|
* A property getter resolving dot-notation
|
|
@@ -17,45 +16,45 @@ const getAttr = (obj, name) => {
|
|
|
17
16
|
* @param {String} name The optionally dotted property name to fetch
|
|
18
17
|
* @return {Object} The resolved property value
|
|
19
18
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return obj;
|
|
19
|
+
export const getAttrNesting = (obj, name) => {
|
|
20
|
+
if (!obj)
|
|
21
|
+
return;
|
|
22
|
+
var part, names = name.split(".");
|
|
23
|
+
while ((part = names.shift()) && (obj = obj[part]))
|
|
24
|
+
;
|
|
25
|
+
return obj;
|
|
29
26
|
};
|
|
30
27
|
/**
|
|
31
28
|
* Calculates how close of a match the
|
|
32
29
|
* given value is against a search token.
|
|
33
30
|
*
|
|
34
31
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
export const scoreValue = (value, token, weight) => {
|
|
33
|
+
var score, pos;
|
|
34
|
+
if (!value)
|
|
35
|
+
return 0;
|
|
36
|
+
value = value + '';
|
|
37
|
+
if (token.regex == null)
|
|
38
|
+
return 0;
|
|
39
|
+
pos = value.search(token.regex);
|
|
40
|
+
if (pos === -1)
|
|
41
|
+
return 0;
|
|
42
|
+
score = token.string.length / value.length;
|
|
43
|
+
if (pos === 0)
|
|
44
|
+
score += 0.5;
|
|
45
|
+
return score * weight;
|
|
46
46
|
};
|
|
47
47
|
/**
|
|
48
48
|
* Cast object property to an array if it exists and has a value
|
|
49
49
|
*
|
|
50
50
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
51
|
+
export const propToArray = (obj, key) => {
|
|
52
|
+
var value = obj[key];
|
|
53
|
+
if (typeof value == 'function')
|
|
54
|
+
return value;
|
|
55
|
+
if (value && !Array.isArray(value)) {
|
|
56
|
+
obj[key] = [value];
|
|
57
|
+
}
|
|
59
58
|
};
|
|
60
59
|
/**
|
|
61
60
|
* Iterates over arrays and hashes.
|
|
@@ -67,29 +66,30 @@ const propToArray = (obj, key) => {
|
|
|
67
66
|
* ```
|
|
68
67
|
*
|
|
69
68
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
export const iterate = (object, callback) => {
|
|
70
|
+
if (Array.isArray(object)) {
|
|
71
|
+
object.forEach(callback);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
for (var key in object) {
|
|
75
|
+
// do not call object.hasOwnProperty() directly: the object may have
|
|
76
|
+
// its own "hasOwnProperty" key (e.g. an item with that id)
|
|
77
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
78
|
+
callback(object[key], key);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
79
81
|
}
|
|
80
|
-
}
|
|
81
82
|
};
|
|
82
|
-
const cmp = (a, b) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
export const cmp = (a, b) => {
|
|
84
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
85
|
+
return a > b ? 1 : (a < b ? -1 : 0);
|
|
86
|
+
}
|
|
87
|
+
a = asciifold(a + '').toLowerCase();
|
|
88
|
+
b = asciifold(b + '').toLowerCase();
|
|
89
|
+
if (a > b)
|
|
90
|
+
return 1;
|
|
91
|
+
if (b > a)
|
|
92
|
+
return -1;
|
|
93
|
+
return 0;
|
|
92
94
|
};
|
|
93
|
-
|
|
94
|
-
export { cmp, getAttr, getAttrNesting, iterate, propToArray, scoreValue };
|
|
95
|
-
//# sourceMappingURL=utils.js.map
|
|
95
|
+
//# sourceMappingURL=utils.js.map
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../lib/utils.ts"],"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAsB,EAAE,IAAW,EAAG,EAAE;IAC5D,IAAI,CAAC,GAAG;QAAG,OAAO;IAClB,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAsB,EAAE,IAAW,EAAG,EAAE;IACnE,IAAI,CAAC,GAAG;QAAG,OAAO;IAClB,IAAI,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QAAC,CAAC;IACjD,OAAO,GAAG,CAAC;AACf,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAY,EAAE,KAAa,EAAE,MAAa,EAAU,EAAE;IAChF,IAAI,KAAK,EAAE,GAAG,CAAC;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AE,GAAG,CAAC,EAAE,CAAC;gBACvD,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;YAC5B,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC,CAAC;AAIF,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAe,EAAE,CAAe,EAAE,EAAE;IACvD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IACD,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACpC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACpC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC;IACrB,OAAO,CAAC,CAAC;AACV,CAAC,CAAC"}
|
package/dist/types/sifter.d.ts
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @author Brian Reavis <brian@thirdroute.com>
|
|
15
15
|
*/
|
|
16
|
-
import { scoreValue, getAttr, getAttrNesting, propToArray, iterate, cmp } from './utils';
|
|
16
|
+
import { scoreValue, getAttr, getAttrNesting, propToArray, iterate, cmp } from './utils.ts';
|
|
17
17
|
import { getPattern } from '@orchidjs/unicode-variants';
|
|
18
|
-
import * as T from './types';
|
|
18
|
+
import type * as T from './types.ts';
|
|
19
19
|
declare class Sifter {
|
|
20
20
|
items: any;
|
|
21
21
|
settings: T.Settings;
|
|
@@ -53,8 +53,8 @@ declare class Sifter {
|
|
|
53
53
|
*
|
|
54
54
|
* @return function(a,b)
|
|
55
55
|
*/
|
|
56
|
-
getSortFunction(query: string, options: T.UserOptions): ((a: T.ResultItem
|
|
57
|
-
_getSortFunction(search: T.PrepareObj): ((a: T.ResultItem
|
|
56
|
+
getSortFunction(query: string, options: T.UserOptions): ((a: T.ResultItem<any>, b: T.ResultItem<any>) => number) | null;
|
|
57
|
+
_getSortFunction(search: T.PrepareObj): ((a: T.ResultItem<any>, b: T.ResultItem<any>) => number) | null;
|
|
58
58
|
/**
|
|
59
59
|
* Parses a search query and returns an object
|
|
60
60
|
* with tokens and fields ready to be populated
|
|
@@ -69,3 +69,4 @@ declare class Sifter {
|
|
|
69
69
|
search(query: string, options: T.UserOptions): T.PrepareObj;
|
|
70
70
|
}
|
|
71
71
|
export { Sifter, scoreValue, getAttr, getAttrNesting, propToArray, iterate, cmp, getPattern };
|
|
72
|
+
export type * from './types.ts';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Sifter } from './sifter';
|
|
2
|
-
export
|
|
1
|
+
import { Sifter } from './sifter.ts';
|
|
2
|
+
export type Field = {
|
|
3
3
|
field: string;
|
|
4
4
|
weight: number;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type Sort = {
|
|
7
7
|
field: string;
|
|
8
8
|
direction?: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
11
|
-
export
|
|
10
|
+
export type SortFn = (this: Sifter, a: ResultItem, b: ResultItem) => number;
|
|
11
|
+
export type UserOptions = {
|
|
12
12
|
fields: string[] | Field[];
|
|
13
13
|
conjunction: string;
|
|
14
14
|
sort: string | SortFn | Sort[];
|
|
@@ -19,7 +19,7 @@ export declare type UserOptions = {
|
|
|
19
19
|
respect_word_boundaries?: boolean;
|
|
20
20
|
limit?: number;
|
|
21
21
|
};
|
|
22
|
-
export
|
|
22
|
+
export type Options = {
|
|
23
23
|
fields: Field[];
|
|
24
24
|
conjunction: string;
|
|
25
25
|
sort: SortFn | Sort[];
|
|
@@ -30,15 +30,15 @@ export declare type Options = {
|
|
|
30
30
|
respect_word_boundaries?: boolean;
|
|
31
31
|
limit?: number;
|
|
32
32
|
};
|
|
33
|
-
export
|
|
33
|
+
export type Token = {
|
|
34
34
|
string: string;
|
|
35
35
|
regex: RegExp | null;
|
|
36
36
|
field: string | null;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export type Weights = {
|
|
39
39
|
[key: string]: number;
|
|
40
40
|
};
|
|
41
|
-
export
|
|
41
|
+
export type PrepareObj = {
|
|
42
42
|
options: Options;
|
|
43
43
|
query: string;
|
|
44
44
|
tokens: Token[];
|
|
@@ -47,11 +47,12 @@ export declare type PrepareObj = {
|
|
|
47
47
|
weights: Weights;
|
|
48
48
|
getAttrFn: (data: any, field: string) => any;
|
|
49
49
|
};
|
|
50
|
-
export
|
|
50
|
+
export type Settings = {
|
|
51
51
|
diacritics: boolean;
|
|
52
52
|
};
|
|
53
|
-
export
|
|
53
|
+
export type ResultItem<T = any> = {
|
|
54
54
|
score: number;
|
|
55
55
|
id: number | string;
|
|
56
|
+
item: T;
|
|
56
57
|
};
|
|
57
|
-
export
|
|
58
|
+
export type ScoreFn = (item: ResultItem) => number;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as T from './types';
|
|
1
|
+
import type * as T from './types.ts';
|
|
2
2
|
/**
|
|
3
3
|
* A property getter resolving dot-notation
|
|
4
4
|
* @param {Object} obj The root object to fetch property on
|
|
@@ -45,4 +45,4 @@ export declare const propToArray: (obj: {
|
|
|
45
45
|
export declare const iterate: (object: [] | {
|
|
46
46
|
[key: string]: any;
|
|
47
47
|
}, callback: (value: any, key: any) => any) => void;
|
|
48
|
-
export declare const cmp: (a: number | string, b: number | string) =>
|
|
48
|
+
export declare const cmp: (a: number | string, b: number | string) => 0 | 1 | -1;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|