Skip to content

Commit

Permalink
*.d.ts in dist/types
Browse files Browse the repository at this point in the history
  • Loading branch information
oyejorge committed Jul 23, 2021
1 parent 8fdee04 commit c21e188
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

"declaration": true,
"declarationDir": "../dist/types",

"isolatedModules": true,
"moduleResolution": "node"
},
}
51 changes: 51 additions & 0 deletions dist/types/diacritics.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
declare type TDiacraticList = {
[key: string]: string;
};
export declare const DIACRITICS: TDiacraticList;
/**
* Remove accents
* via https://github.com/krisk/Fuse/issues/133#issuecomment-318692703
*
*/
export declare const asciifold: (str: string) => string;
/**
* Generate a list of diacritics from the list of code points
*
*/
export declare const generateDiacritics: () => TDiacraticList;
export declare const diacriticRegexPoints: (regex: string) => string;
export {};
/**
* Expand a regular expression pattern to include diacritics
* eg /a/ becomes /aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑAⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ/
*
* rollup will bundle this function (and the DIACRITICS constant) unless commented out
*
var diacriticRegex = (function() {
var list = [];
for( let letter in DIACRITICS ){
if( letter.toLowerCase() != letter && letter.toLowerCase() in DIACRITICS ){
continue;
}
if( DIACRITICS.hasOwnProperty(letter) ){
var replace = letter + DIACRITICS[letter];
if( letter.toUpperCase() in DIACRITICS ){
replace += letter.toUpperCase() + DIACRITICS[letter.toUpperCase()];
}
list.push({let:letter,pat:'['+replace+']'});
}
}
return function(regex:string):string{
list.forEach((item)=>{
regex = regex.replace( new RegExp(item.let,'g'),item.pat);
});
return regex;
}
})();
*/
64 changes: 64 additions & 0 deletions dist/types/sifter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* sifter.js
* Copyright (c) 2013–2020 Brian Reavis & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
* @author Brian Reavis <[email protected]>
*/
import * as T from 'types.ts';
export default class Sifter {
items: any;
settings: T.Settings;
/**
* Textually searches arrays and hashes of objects
* by property (or multiple properties). Designed
* specifically for autocomplete.
*
*/
constructor(items: any, settings: T.Settings);
/**
* Splits a search string into an array of individual
* regexps to be used to match results.
*
*/
tokenize(query: string, respect_word_boundaries?: boolean, weights?: T.Weights): T.Token[];
/**
* Returns a function to be used to score individual results.
*
* Good matches will have a higher score than poor matches.
* If an item is not a match, 0 will be returned by the function.
*
* @returns {function}
*/
getScoreFunction(query: string, options: T.Options): (data: {}) => any;
_getScoreFunction(search: T.PrepareObj): (data: {}) => any;
/**
* Returns a function that can be used to compare two
* results, for sorting purposes. If no sorting should
* be performed, `null` will be returned.
*
* @return function(a,b)
*/
getSortFunction(query: string, options: T.Options): ((a: any, b: any) => number) | null;
_getSortFunction(search: T.PrepareObj): ((a: any, b: any) => number) | null;
/**
* Parses a search query and returns an object
* with tokens and fields ready to be populated
* with results.
*
*/
prepareSearch(query: string, optsUser: T.Options): T.PrepareObj;
/**
* Searches through all items and returns a sorted array of matches.
*
*/
search(query: string, options: T.Options): T.PrepareObj;
}
43 changes: 43 additions & 0 deletions dist/types/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export declare type Field = {
field: string;
weight: number;
};
export declare type Sort = {
field: string;
direction?: string;
};
export declare type Options = {
fields: Field[];
sort: Sort[];
score?: () => any;
filter?: boolean;
limit?: number;
sort_empty?: Sort[];
nesting?: boolean;
respect_word_boundaries?: boolean;
conjunction?: string;
};
export declare type Token = {
string: string;
regex: RegExp | null;
field: string | null;
};
export declare type Weights = {
[key: string]: number;
};
export declare type PrepareObj = {
options: Options;
query: string;
tokens: Token[];
total: number;
items: ResultItem[];
weights: Weights;
getAttrFn: (data: any, field: string) => any;
};
export declare type Settings = {
diacritics: boolean;
};
export declare type ResultItem = {
score: number;
id: number | string;
};
48 changes: 48 additions & 0 deletions dist/types/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* A property getter resolving dot-notation
* @param {Object} obj The root object to fetch property on
* @param {String} name The optionally dotted property name to fetch
* @return {Object} The resolved property value
*/
export declare const getAttr: (obj: {
[key: string]: any;
}, name: string) => any;
/**
* A property getter resolving dot-notation
* @param {Object} obj The root object to fetch property on
* @param {String} name The optionally dotted property name to fetch
* @return {Object} The resolved property value
*/
export declare const getAttrNesting: (obj: {
[key: string]: any;
}, name: string) => {
[key: string]: any;
} | undefined;
/**
* Calculates how close of a match the
* given value is against a search token.
*
*/
export declare const scoreValue: (value: string, token: any, weight: number) => number;
export declare const escape_regex: (str: string) => string;
/**
* Cast object property to an array if it exists and has a value
*
*/
export declare const propToArray: (obj: {
[key: string]: any;
}, key: string) => void;
/**
* Iterates over arrays and hashes.
*
* ```
* iterate(this.items, function(item, id) {
* // invoked for each item
* });
* ```
*
*/
export declare const iterate: (object: [] | {
[key: string]: any;
}, callback: (value: any, key: number | string) => any) => void;
export declare const cmp: (a: number | string, b: number | string) => 1 | -1 | 0;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"main": "dist/umd/sifter.js",
"browser": "dist/umd/sifter.js",
"module": "dist/esm/sifter.js",
"types": "lib/sifter.ts",
"types": "dist/types/sifter.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/orchidjs/sifter.js.git"
Expand All @@ -28,6 +28,7 @@
"pretest": "npm run build",
"benchmark": "node --expose-gc benchmark/index.js",
"build": "npx rollup -c .config/rollup.config.js",
"build:types": "tsc -p .config --emitDeclarationOnly",
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls"
},
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ if ! cp -r build/* dist; then
fi


# make sure types are up-to-date
if ! npm run build:types; then
echo 'types not generated'
exit
fi


# prompt before finalizing
if ! ask "Version $VERSION is ready for release. Are you sure?"; then
echo 'release aborted'
Expand Down

0 comments on commit c21e188

Please sign in to comment.