Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@platform/util.string

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@platform/util.string - npm Package Compare versions

Comparing version 0.0.29 to 0.0.30

2

lib/fuzzy/fuzzy.d.ts

@@ -9,3 +9,3 @@ export declare type IFuzzyMatch = {

export declare function match(pattern: string, input: string): IFuzzyMatch | undefined;
export declare function isMatch(pattern: string, input: string): boolean;
export declare function isMatch(pattern: string, input: string | string[]): boolean;
export declare function filter(pattern: string, inputs: string[]): IFuzzyFilterMatch[];

@@ -10,3 +10,4 @@ "use strict";

function isMatch(pattern, input) {
return Boolean(match(pattern, input));
input = Array.isArray(input) ? input : [input];
return input.some(function (value) { return Boolean(match(pattern, value)); });
}

@@ -13,0 +14,0 @@ exports.isMatch = isMatch;

@@ -5,2 +5,3 @@ "use strict";

var __1 = require("..");
var ramda_1 = require("ramda");
describe('fuzzy', function () {

@@ -18,3 +19,3 @@ describe('match', function () {

});
describe('isMatch', function () {
describe('isMatch (single value)', function () {
it('true', function () {

@@ -29,5 +30,16 @@ var res = __1.str.fuzzy.isMatch('bcn', 'bacon');

});
describe('isMatch (within list)', function () {
var list = ['get', 'watch', 'put'];
it('true', function () {
var res = __1.str.fuzzy.isMatch('t', list);
chai_1.expect(res).to.eql(true);
});
it('false', function () {
var res = __1.str.fuzzy.isMatch('z', list);
chai_1.expect(res).to.eql(false);
});
});
describe('filter', function () {
var list = ['baconing', 'narwhal', 'a mighty bear canoe'];
it('list of results', function () {
var list = ['baconing', 'narwhal', 'a mighty bear canoe'];
var res = __1.str.fuzzy.filter('bcn', list);

@@ -39,7 +51,22 @@ chai_1.expect(res.length).to.eql(2);

it('no results', function () {
var list = ['baconing', 'narwhal', 'a mighty bear canoe'];
var res = __1.str.fuzzy.filter('zz', list);
chai_1.expect(res).to.eql([]);
});
it('returns all values when no (empty) pattern is given', function () {
var res = __1.str.fuzzy.filter('', list);
chai_1.expect(res.length).to.eql(3);
chai_1.expect(res[0].index).to.eql(0);
chai_1.expect(res[1].index).to.eql(1);
chai_1.expect(res[2].index).to.eql(2);
chai_1.expect(res[0].score).to.eql(0);
chai_1.expect(res[1].score).to.eql(0);
chai_1.expect(res[2].score).to.eql(0);
});
it('curries', function () {
var filter = ramda_1.curry(__1.str.fuzzy.filter);
var bcn = filter('bcn');
var res = bcn(list);
chai_1.expect(res.length).to.eql(2);
});
});
});
{
"name": "@platform/util.string",
"version": "0.0.29",
"version": "0.0.30",
"description": "String helpers.",

@@ -5,0 +5,0 @@ "main": "lib/index",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc