Skip to content

Commit

Permalink
chore: build v.2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
axules committed Jul 28, 2022
1 parent 1b681f5 commit e81e1aa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
6 changes: 3 additions & 3 deletions dist/matchList.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ function isValidRate(rate) {
}

function matchList(what, whereList, options) {
if (!what || !whereList || !Array.isArray(whereList) && !(0, _utils.isObject)(whereList) || whereList.length == 0) {
var isArray = Array.isArray(whereList);

if (!what || !whereList || !isArray && !(0, _utils.isObject)(whereList) || whereList.length == 0) {
return null;
}

var isArray = Array.isArray(whereList);

var _defaultOptions = (0, _utils.defaultOptions)(options),
withScore = _defaultOptions.withScore,
rates = _defaultOptions.rates;
Expand Down
24 changes: 20 additions & 4 deletions dist/matchString.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ function matchString(what, where, options) {
withWrapper = _defaultOptions.withWrapper,
withRanges = _defaultOptions.withRanges;

var preparedWhat = caseSensitive ? String(what) : String(what).toLocaleLowerCase();
var isWords = Array.isArray(what);
if (isWords && what.length == 0) return null;
var preparedWhat = caseSensitive ? isWords ? what : String(what) : isWords ? what.map(function (it) {
return String(it).toLocaleLowerCase();
}) : String(what).toLocaleLowerCase();
var originalWhere = String(where);
if (!preparedWhat || !originalWhere || preparedWhat.length > originalWhere.length) return null; // preparedWhere will be undefined if caseSensitive is true, it is needed to save memory

if (!preparedWhat || !originalWhere || !isWords && preparedWhat.length > originalWhere.length) {
return null;
} // preparedWhere will be undefined if caseSensitive is true, it is needed to save memory


var preparedWhere = caseSensitive ? undefined : originalWhere.toLocaleLowerCase();
var wrapped = null;
Expand Down Expand Up @@ -70,8 +78,16 @@ function matchString(what, where, options) {
var pos = -1;

for (var i = 0; i < preparedWhat.length; i++) {
var nextPos = (preparedWhere || originalWhere).indexOf(preparedWhat.charAt(i), pos + 1);
if (nextPos < 0 || nextPos >= originalWhere.length) return null;
var chunk = isWords ? preparedWhat[i] : preparedWhat.charAt(i);
var nextPos = (preparedWhere || originalWhere).indexOf(chunk, pos + 1);
if (nextPos < 0) return null;

if (isWords && chunk.length > 1) {
wordAction(pos, nextPos);
nextPos = nextPos + chunk.length - 1;
pos = nextPos - 1;
}

wordAction(pos, nextPos);
pos = nextPos;
}
Expand Down
12 changes: 1 addition & 11 deletions dist/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,7 @@ var DEFAULT_OPTIONS = {
};

function defaultOptions(options) {
var deprecationOverride = {};

if (options && Object.prototype.hasOwnProperty.call(options, 'caseInsensitive')) {
console.warn('fuzzy-tools: `caseInsensitive` is deprecated, use `caseSensitive` instead of `caseInsensitive`');

if (!Object.prototype.hasOwnProperty.call(options, 'caseSensitive')) {
deprecationOverride.caseSensitive = !options.caseInsensitive;
}
}

return options ? Object.assign({}, DEFAULT_OPTIONS, options, deprecationOverride) : DEFAULT_OPTIONS;
return options ? Object.assign({}, DEFAULT_OPTIONS, options) : DEFAULT_OPTIONS;
}

function isFunction(value) {
Expand Down

0 comments on commit e81e1aa

Please sign in to comment.