Comparing version 4.0.3 to 4.0.4
@@ -65,2 +65,36 @@ /** | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
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 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __spreadArrays() { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
} | ||
/** | ||
@@ -78,3 +112,3 @@ * Appends to an actual list of ranges a new match. This will only increment | ||
if (lastRange && lastRange.stop === sourcePos) { | ||
return ranges.slice(0, -1).concat([ | ||
return __spreadArrays(ranges.slice(0, -1), [ | ||
{ | ||
@@ -87,3 +121,3 @@ start: lastRange.start, | ||
else { | ||
return ranges.concat([{ start: sourcePos, stop: sourcePos + 1 }]); | ||
return __spreadArrays(ranges, [{ start: sourcePos, stop: sourcePos + 1 }]); | ||
} | ||
@@ -233,28 +267,2 @@ }; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
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 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
/** | ||
@@ -264,3 +272,7 @@ * @ignore | ||
var get = function (source, accessor) { | ||
return typeof accessor === 'function' ? accessor(source) : source; | ||
if (typeof accessor === 'function') | ||
return accessor(source); | ||
if (typeof source === 'string') | ||
return source; | ||
throw new TypeError("Unexpected array of " + typeof source + ". Use an accessor to return a string"); | ||
}; | ||
@@ -296,3 +308,3 @@ /** | ||
if (options === void 0) { options = {}; } | ||
var matchOptions = __assign({}, options, { withRanges: false, withScore: true }); | ||
var matchOptions = __assign(__assign({}, options), { withRanges: false, withScore: true }); | ||
if (!options.idAccessor) { | ||
@@ -299,0 +311,0 @@ return function (leftSource, rightSource) { |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = global || self, factory(global.fuzzyjs = {})); | ||
}(this, function (exports) { 'use strict'; | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -72,2 +72,36 @@ /** | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
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 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __spreadArrays() { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
} | ||
/** | ||
@@ -85,3 +119,3 @@ * Appends to an actual list of ranges a new match. This will only increment | ||
if (lastRange && lastRange.stop === sourcePos) { | ||
return ranges.slice(0, -1).concat([ | ||
return __spreadArrays(ranges.slice(0, -1), [ | ||
{ | ||
@@ -94,3 +128,3 @@ start: lastRange.start, | ||
else { | ||
return ranges.concat([{ start: sourcePos, stop: sourcePos + 1 }]); | ||
return __spreadArrays(ranges, [{ start: sourcePos, stop: sourcePos + 1 }]); | ||
} | ||
@@ -240,28 +274,2 @@ }; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
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 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
/** | ||
@@ -271,3 +279,7 @@ * @ignore | ||
var get = function (source, accessor) { | ||
return typeof accessor === 'function' ? accessor(source) : source; | ||
if (typeof accessor === 'function') | ||
return accessor(source); | ||
if (typeof source === 'string') | ||
return source; | ||
throw new TypeError("Unexpected array of " + typeof source + ". Use an accessor to return a string"); | ||
}; | ||
@@ -303,3 +315,3 @@ /** | ||
if (options === void 0) { options = {}; } | ||
var matchOptions = __assign({}, options, { withRanges: false, withScore: true }); | ||
var matchOptions = __assign(__assign({}, options), { withRanges: false, withScore: true }); | ||
if (!options.idAccessor) { | ||
@@ -381,3 +393,3 @@ return function (leftSource, rightSource) { | ||
})); | ||
}))); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -20,3 +20,7 @@ "use strict"; | ||
var get = function (source, accessor) { | ||
return typeof accessor === 'function' ? accessor(source) : source; | ||
if (typeof accessor === 'function') | ||
return accessor(source); | ||
if (typeof source === 'string') | ||
return source; | ||
throw new TypeError("Unexpected array of " + typeof source + ". Use an accessor to return a string"); | ||
}; | ||
@@ -52,3 +56,3 @@ /** | ||
if (options === void 0) { options = {}; } | ||
var matchOptions = __assign({}, options, { withRanges: false, withScore: true }); | ||
var matchOptions = __assign(__assign({}, options), { withRanges: false, withScore: true }); | ||
if (!options.idAccessor) { | ||
@@ -55,0 +59,0 @@ return function (leftSource, rightSource) { |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,3 +22,3 @@ /** | ||
if (lastRange && lastRange.stop === sourcePos) { | ||
return ranges.slice(0, -1).concat([ | ||
return __spreadArrays(ranges.slice(0, -1), [ | ||
{ | ||
@@ -24,5 +31,5 @@ start: lastRange.start, | ||
else { | ||
return ranges.concat([{ start: sourcePos, stop: sourcePos + 1 }]); | ||
return __spreadArrays(ranges, [{ start: sourcePos, stop: sourcePos + 1 }]); | ||
} | ||
}; | ||
//# sourceMappingURL=range.js.map |
@@ -6,3 +6,3 @@ import { TestOptions } from './test'; | ||
*/ | ||
export declare type Accessor = (source: any) => string; | ||
export declare type Accessor<T> = (source: T) => string; | ||
/** | ||
@@ -13,4 +13,4 @@ * This represents filter util options. It is based on [[TestOptions]] (as | ||
*/ | ||
export interface FilterOptions extends TestOptions { | ||
sourceAccessor?: Accessor; | ||
export interface FilterOptions<T> extends TestOptions { | ||
sourceAccessor?: Accessor<T>; | ||
} | ||
@@ -23,5 +23,5 @@ /** | ||
*/ | ||
export interface SortOptions extends MatchOptions { | ||
sourceAccessor?: Accessor; | ||
idAccessor?: Accessor; | ||
export interface SortOptions<T> extends MatchOptions { | ||
sourceAccessor?: Accessor<T>; | ||
idAccessor?: Accessor<T>; | ||
} | ||
@@ -38,3 +38,3 @@ /** | ||
*/ | ||
export declare const filter: (query: string, options?: FilterOptions) => (source: any) => boolean; | ||
export declare const filter: <T>(query: string, options?: FilterOptions<T>) => (source: T) => boolean; | ||
/** | ||
@@ -51,2 +51,2 @@ * This array helper can be used as an `Array.prototype.sort` callback as it | ||
*/ | ||
export declare const sort: (query: string, options?: SortOptions) => (leftSource: any, rightSource: any) => 0 | 1 | -1; | ||
export declare const sort: <T>(query: string, options?: SortOptions<T>) => (leftSource: T, rightSource: T) => 0 | 1 | -1; |
{ | ||
"name": "fuzzyjs", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"description": "Fuzzy matching in Javascript", | ||
@@ -92,25 +92,25 @@ "keywords": [ | ||
"@types/benchmark": "^1.0.31", | ||
"@types/jest": "^24.0.14", | ||
"@types/node": "^12.0.8", | ||
"@types/jest": "^25.1.4", | ||
"@types/node": "^13.1.1", | ||
"benchmark": "^2.1.4", | ||
"colors": "^1.3.2", | ||
"coveralls": "^3.0.2", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"husky": "^2.4.1", | ||
"jest": "^24.8.0", | ||
"jest-config": "^24.8.0", | ||
"lint-staged": "^8.2.1", | ||
"cz-conventional-changelog": "^3.1.0", | ||
"husky": "^4.2.3", | ||
"jest": "^25.1.0", | ||
"jest-config": "^25.1.0", | ||
"lint-staged": "^10.0.8", | ||
"lodash.camelcase": "^4.3.0", | ||
"prettier": "^1.14.3", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^1.15.5", | ||
"rollup-plugin-commonjs": "^10.0.0", | ||
"rimraf": "^3.0.0", | ||
"rollup": "^2.0.6", | ||
"rollup-plugin-commonjs": "^10.0.2", | ||
"rollup-plugin-json": "^4.0.0", | ||
"rollup-plugin-node-resolve": "^5.0.2", | ||
"rollup-plugin-sourcemaps": "^0.4.2", | ||
"rollup-plugin-typescript2": "^0.21.1", | ||
"ts-jest": "^24.0.2", | ||
"rollup-plugin-sourcemaps": "^0.5.0", | ||
"rollup-plugin-typescript2": "^0.26.0", | ||
"ts-jest": "^25.2.1", | ||
"ts-node": "^8.3.0", | ||
"typedoc": "^0.14.2", | ||
"typescript": "^3.5.2" | ||
"typedoc": "^0.16.11", | ||
"typescript": "^3.8.3" | ||
}, | ||
@@ -117,0 +117,0 @@ "dependencies": {}, |
import { test, TestOptions } from './test' | ||
import { match, ScoreStrategy, MatchOptions } from './match' | ||
import { match, MatchOptions } from './match' | ||
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export type Accessor = (source: any) => string | ||
export type Accessor<T> = (source: T) => string | ||
@@ -15,4 +15,4 @@ /** | ||
*/ | ||
export interface FilterOptions extends TestOptions { | ||
sourceAccessor?: Accessor | ||
export interface FilterOptions<T> extends TestOptions { | ||
sourceAccessor?: Accessor<T> | ||
} | ||
@@ -26,5 +26,5 @@ | ||
*/ | ||
export interface SortOptions extends MatchOptions { | ||
sourceAccessor?: Accessor | ||
idAccessor?: Accessor | ||
export interface SortOptions<T> extends MatchOptions { | ||
sourceAccessor?: Accessor<T> | ||
idAccessor?: Accessor<T> | ||
} | ||
@@ -35,4 +35,7 @@ | ||
*/ | ||
const get = (source: any, accessor?: Accessor): string => { | ||
return typeof accessor === 'function' ? accessor(source) : source | ||
const get = <T>(source: T, accessor?: Accessor<T>): string => { | ||
if (typeof accessor === 'function') return accessor(source) | ||
if (typeof source === 'string') return source | ||
throw new TypeError(`Unexpected array of ${typeof source}. Use an accessor to return a string`) | ||
} | ||
@@ -50,3 +53,3 @@ | ||
*/ | ||
export const filter = (query: string, options: FilterOptions = {}) => (source: any) => | ||
export const filter = <T>(query: string, options: FilterOptions<T> = {}) => (source: T) => | ||
test(query, get(source, options.sourceAccessor), options) | ||
@@ -65,3 +68,3 @@ | ||
*/ | ||
export const sort = (query: string, options: SortOptions = {}) => { | ||
export const sort = <T>(query: string, options: SortOptions<T> = {}) => { | ||
const matchOptions: MatchOptions = { | ||
@@ -74,3 +77,3 @@ ...options, | ||
if (!options.idAccessor) { | ||
return (leftSource: any, rightSource: any) => { | ||
return (leftSource: T, rightSource: T) => { | ||
const leftScore = match(query, get(leftSource, options.sourceAccessor), matchOptions).score! | ||
@@ -87,4 +90,4 @@ const rightScore = match(query, get(rightSource, options.sourceAccessor), matchOptions).score! | ||
return (leftSource: any, rightSource: any) => { | ||
const leftId = get(leftSource, options.idAccessor) as string | ||
const rightId = get(rightSource, options.idAccessor) as string | ||
const leftId = get(leftSource, options.idAccessor) | ||
const rightId = get(rightSource, options.idAccessor) | ||
@@ -91,0 +94,0 @@ const leftScore: number = memo.hasOwnProperty(leftId) |
@@ -103,7 +103,13 @@ import { match } from '../src' | ||
match: true, | ||
ranges: [{ start: 0, stop: 1 }, { start: 7, stop: 8 }] | ||
ranges: [ | ||
{ start: 0, stop: 1 }, | ||
{ start: 7, stop: 8 } | ||
] | ||
}) | ||
expect(match('anaba', 'Ananas Banana Caramel', { withRanges: true })).toMatchObject({ | ||
match: true, | ||
ranges: [{ start: 0, stop: 3 }, { start: 7, stop: 9 }] | ||
ranges: [ | ||
{ start: 0, stop: 3 }, | ||
{ start: 7, stop: 9 } | ||
] | ||
}) | ||
@@ -110,0 +116,0 @@ }) |
@@ -37,3 +37,6 @@ import { surround } from '../src/surround' | ||
result: { | ||
ranges: [{ start: 0, stop: 1 }, { start: 4, stop: 6 }] | ||
ranges: [ | ||
{ start: 0, stop: 1 }, | ||
{ start: 4, stop: 6 } | ||
] | ||
}, | ||
@@ -48,3 +51,6 @@ prefix: '<strong>', | ||
result: { | ||
ranges: [{ start: 0, stop: 1 }, { start: 4, stop: 6 }] | ||
ranges: [ | ||
{ start: 0, stop: 1 }, | ||
{ start: 4, stop: 6 } | ||
] | ||
}, | ||
@@ -58,3 +64,6 @@ prefix: '*' | ||
result: { | ||
ranges: [{ start: 0, stop: 1 }, { start: 4, stop: 6 }] | ||
ranges: [ | ||
{ start: 0, stop: 1 }, | ||
{ start: 4, stop: 6 } | ||
] | ||
}, | ||
@@ -61,0 +70,0 @@ suffix: '*' |
@@ -19,3 +19,6 @@ import { pushRange } from '../src/utils/range' | ||
expect(result).toMatchObject([{ start: 0, stop: 1 }, { start: 5, stop: 6 }]) | ||
expect(result).toMatchObject([ | ||
{ start: 0, stop: 1 }, | ||
{ start: 5, stop: 6 } | ||
]) | ||
}) | ||
@@ -22,0 +25,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26243
514116
63