🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

levenshtein

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

levenshtein - npm Package Compare versions

Comparing version

to
1.0.2

bower.json

142

lib/levenshtein.js

@@ -1,78 +0,90 @@

// Generics
if ( ! Array.forEach ) {
Array.forEach = function forEach ( array, iterator, context ) {
iterator = context
? iterator.bind( context )
: iterator
Array.prototype.forEach.call( array, iterator )
(function(root, factory){
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
define(function(){
return factory(root);
});
} else if (typeof module == 'object' && module && module.exports) {
module.exports = factory(root);
} else {
root.Levenshtein = factory(root);
}
}
}(this, function(root){
// Levenshtein distance
function Levenshtein( str_m, str_n ) { var previous, current, matrix
// Instance methods
this.valueOf = function() {
return this.distance
var forEach;
// Generics
if ( ! Array.forEach ) {
forEach = function ( array, iterator, context ) {
iterator = context
? iterator.bind( context )
: iterator
Array.prototype.forEach.call( array, iterator )
}
} else {
forEach = Array.forEach;
}
this.toString = this.inspect = function inspect ( no_print ) { var max, buff, sep, rows
max = matrix.reduce( function( m, o ) {
return Math.max( m, o.reduce( Math.max, 0 ) )
}, 0 )
buff = Array( ( max + '' ).length ).join( ' ' )
// Levenshtein distance
return function Levenshtein( str_m, str_n ) { var previous, current, matrix
// Instance methods
this.valueOf = function() {
return this.distance
}
sep = []
while ( sep.length < (matrix[0] && matrix[0].length || 0) )
sep[ sep.length ] = Array( buff.length + 1 ).join( '-' )
sep = sep.join( '-+' ) + '-'
this.toString = this.inspect = function inspect ( no_print ) { var max, buff, sep, rows
max = matrix.reduce( function( m, o ) {
return Math.max( m, o.reduce( Math.max, 0 ) )
}, 0 )
buff = Array( ( max + '' ).length ).join( ' ' )
rows = matrix.map( function( row ) { var cells
cells = row.map( function( cell ) {
return ( buff + cell ).slice( - buff.length )
sep = []
while ( sep.length < (matrix[0] && matrix[0].length || 0) )
sep[ sep.length ] = Array( buff.length + 1 ).join( '-' )
sep = sep.join( '-+' ) + '-'
rows = matrix.map( function( row ) { var cells
cells = row.map( function( cell ) {
return ( buff + cell ).slice( - buff.length )
})
return cells.join( ' |' ) + ' '
})
return cells.join( ' |' ) + ' '
})
return rows.join( "\n" + sep + "\n" )
}
return rows.join( "\n" + sep + "\n" )
}
// Constructor
matrix = []
// Constructor
matrix = []
// Sanity checks
if ( str_m == str_n )
return this.distance = 0
else if ( str_m == '' )
return this.distance = str_n.length
else if ( str_n == '' )
return this.distance = str_m.length
else {
// Danger Will Robinson
previous = [ 0 ]
Array.forEach( str_m, function( v, i ) { i++, previous[ i ] = i } )
// Sanity checks
if ( str_m == str_n )
return this.distance = 0
else if ( str_m == '' )
return this.distance = str_n.length
else if ( str_n == '' )
return this.distance = str_m.length
else {
// Danger Will Robinson
previous = [ 0 ]
forEach( str_m, function( v, i ) { i++, previous[ i ] = i } )
matrix[0] = previous
Array.forEach( str_n, function( n_val, n_idx ) {
current = [ ++n_idx ]
Array.forEach( str_m, function( m_val, m_idx ) {
m_idx++
if ( str_m.charAt( m_idx - 1 ) == str_n.charAt( n_idx - 1 ) )
current[ m_idx ] = previous[ m_idx - 1 ]
else
current[ m_idx ] = Math.min
( previous[ m_idx ] + 1 // Deletion
, current[ m_idx - 1 ] + 1 // Insertion
, previous[ m_idx - 1 ] + 1 // Subtraction
)
matrix[0] = previous
forEach( str_n, function( n_val, n_idx ) {
current = [ ++n_idx ]
forEach( str_m, function( m_val, m_idx ) {
m_idx++
if ( str_m.charAt( m_idx - 1 ) == str_n.charAt( n_idx - 1 ) )
current[ m_idx ] = previous[ m_idx - 1 ]
else
current[ m_idx ] = Math.min
( previous[ m_idx ] + 1 // Deletion
, current[ m_idx - 1 ] + 1 // Insertion
, previous[ m_idx - 1 ] + 1 // Subtraction
)
})
previous = current
matrix[ matrix.length ] = previous
})
previous = current
matrix[ matrix.length ] = previous
})
return this.distance = current[ current.length - 1 ]
return this.distance = current[ current.length - 1 ]
}
}
}
// Export
module.exports = Levenshtein
}));

@@ -1,15 +0,24 @@

{ "name" : "levenshtein"
, "description" : "Javascript implementation of the L-diggity."
, "author" : "Gianni Chiappetta <gianni@runlevel6.org> (http://gf3.ca)"
, "version" : "1.0.1"
, "main" : "./lib/levenshtein"
, "engines" : [ "node >=0.2.0" ]
, "repository" :
{ "type" : "git"
, "url" : "http://github.com/gf3/Levenshtein.git"
{
"name": "levenshtein",
"description": "Javascript implementation of the L-diggity.",
"author": "Gianni Chiappetta <gianni@runlevel6.org> (http://gf3.ca)",
"version": "1.0.2",
"main": "./lib/levenshtein",
"engines": [
"node >=0.2.0"
],
"repository": {
"type": "git",
"url": "http://github.com/gf3/Levenshtein.git"
},
"license": {
"type": "Public Domain",
"url": "http://github.com/gf3/Levenshtein/raw/master/UNLICENSE"
},
"devDependencies": {
"expresso": "~0.9.2"
},
"scripts": {
"test": "expresso test"
}
, "license" :
{ "type" : "Public Domain"
, "url" : "http://github.com/gf3/Levenshtein/raw/master/UNLICENSE"
}
}

@@ -7,3 +7,5 @@ # Levenshtein

`Levenshtein` also does some neat things like coerce to a number and string approproately. So you can compare Levenshtein objects directly! Not to mention it has specs!
`Levenshtein` also does some neat things like coerce to a number and string
approproately. So you can compare Levenshtein objects directly! Not to mention
it has specs!

@@ -10,0 +12,0 @@ ## API