Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

leven

v0.86.0arrow_drop_down
v0.86.0
v0.85.0
v0.84.0
STATUS
Passing
DOWNLOADS
19,854
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
9 months ago
SIZE
479 B
1 contributor
Use leven in your project ?
Copied
npm i @bit/semantic-org.semantic-ui-react.utils.leven
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Files
leven.js
48 Lines(34 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copy of sindre's leven, wrapped in dead code elimination for production
// https://github.com/sindresorhus/leven/blob/master/index.js
/* eslint-disable complexity, import/no-mutable-exports, no-multi-assign, no-nested-ternary, no-plusplus */

let leven = () => 0

if (process.env.NODE_ENV !== 'production') {
  const arr = []
  const charCodeCache = []

  leven = (a, b) => {
    if (a === b) return 0

    const aLen = a.length
    const bLen = b.length

    if (aLen === 0) return bLen
    if (bLen === 0) return aLen

    let bCharCode
    let ret
    let tmp
    let tmp2
    let i = 0
    let j = 0

    while (i < aLen) {
      charCodeCache[i] = a.charCodeAt(i)
      arr[i] = ++i
    }

    while (j < bLen) {
      bCharCode = b.charCodeAt(j)
      tmp = j++
      ret = j

      for (i = 0; i < aLen; i++) {
        tmp2 = bCharCode === charCodeCache[i] ? tmp : tmp + 1
        tmp = arr[i]
        ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2
      }
    }

    return ret
  }
}

export default leven