You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

stringsoup

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stringsoup

A package to help finding the best known string match amongst a soup of input strings

1.0.0
Source
npmnpm
Version published
Maintainers
1
Created
Source

StringSoup

Use a variety of string similarity functions to find the best string in a group of strings.

Example Usage

import { StringSoup } from 'stringsoup';

const stringSoup = new StringSoup([
  'London',
  'Washington',
  'Mumbai',
  'Sydney',
  'Tokyo',
  'Moscow',
  'Neverland',
]);

const result = stringSoup.matchSoup('wshng');
/*
 {
  best: {
    token: 'wshng',
    match: { knownString: 'Washington', score: 0.7333333333333334 }
  },
  all: [
    {
      token: 'wshng',
      match: { knownString: 'Washington', score: 0.7333333333333334 }
    }
  ]
}
 */

const result = stringSoup.matchSoup(
  'I like to visit lndon, but I live elsewhere'
);
/*
{
  best: {
    token: 'lndon,',
    match: { knownString: 'London', score: 0.6527777777777778 }
  },
  all: [
    {
      token: 'lndon,',
      match: { knownString: 'London', score: 0.6527777777777778 }
    },
    {
      token: 'to',
      match: { knownString: 'Tokyo', score: 0.5666666666666667 }
    },
    {
      token: 'elsewhere',
      match: { knownString: 'Neverland', score: 0.5555555555555555 }
    },
    {
      token: 'visit',
      match: { knownString: 'Washington', score: 0.5222222222222221 }
    },
    { token: 'but', match: { knownString: 'Mumbai', score: 0.5 } },
    {
      token: 'like',
      match: { knownString: 'Tokyo', score: 0.48333333333333334 }
    },
    {
      token: 'live',
      match: { knownString: 'Sydney', score: 0.47222222222222215 }
    },
    { token: 'I', match: { knownString: 'London', score: 0 } },
    { token: 'I', match: { knownString: 'London', score: 0 } }
  ]
}
*/

TODO

  • Add options to sanitize
    • Charset transformations
    • Ignored characters
    • Replaced characters
  • Add options to tokenize
    • Specify delimiters
  • Add different distance functions
    • Currently only https://www.npmjs.com/package/jaro-winkler

Keywords

strings

FAQs

Package last updated on 14 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts