├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE.txt ├── README.md ├── benchmark.js ├── cjs └── index.js ├── coverage ├── coverage.json ├── lcov-report │ ├── base.css │ ├── index.html │ ├── majinbuu │ │ ├── cjs │ │ │ ├── index.html │ │ │ └── index.js.html │ │ ├── index.html │ │ └── test.js.html │ ├── prettify.css │ ├── prettify.js │ ├── sort-arrow-sprite.png │ └── sorter.js └── lcov.info ├── esm └── index.js ├── index.js ├── levenstein.c ├── min.js ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | levenstein 4 | package-lock.json -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | coverage/* 2 | node_modules/* 3 | .gitignore 4 | .travis.yml 5 | benchmark.js 6 | levenstein 7 | levenstein.* 8 | test.js 9 | package-lock.json -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 8 4 | git: 5 | depth: 1 6 | branches: 7 | only: 8 | - master 9 | after_success: 10 | - "npm run coveralls" 11 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2017, Andrea Giammarchi, @WebReflection 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Majin Buu 2 | 3 | [![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](https://opensource.org/licenses/ISC) [![Build Status](https://travis-ci.org/WebReflection/majinbuu.svg?branch=master)](https://travis-ci.org/WebReflection/majinbuu) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/majinbuu/badge.svg?branch=master)](https://coveralls.io/github/WebReflection/majinbuu?branch=master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/WebReflection/donate) 4 | 5 | 6 | Apply the [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) to transform / morph an Array into another, performing the least amount of needed `.splice(...)` operations. 7 | 8 | ```js 9 | const abra = ['a', 'b', 'r', 'a']; 10 | majinbuu(abra, ['c', 'a', 'd', 'a', 'b', 'r', 'a']); 11 | 12 | abra; // now ['c', 'a', 'd', 'a', 'b', 'r', 'a'] 13 | ``` 14 | 15 | It is also possible to intercept all splice calls using an `aura`, 16 | which augments the `splice` method of the list, 17 | delegating the interceptor one. 18 | ```js 19 | const abra = ['a', 'b', 'r', 'a']; 20 | const interceptor = { 21 | splice(index, removal, ...items) { 22 | console.log(index, removal, ...items); 23 | abra.splice.apply(abra, arguments); 24 | } 25 | }; 26 | const aura = majinbuu.aura(interceptor, abra); 27 | 28 | majinbuu(aura, ['c', 'a', 'd', 'a', 'b', 'r', 'a']); 29 | // 0 0 "c" 30 | // 2 0 "d" "a" 31 | ``` 32 | 33 | The optional third argument avoid processing grids that are too big (comparing lists with too many items). 34 | ```js 35 | const noMoreThan1K = 1000; 36 | majinbuu(list1, list2, noMoreThan1K); 37 | ``` 38 | If the square of the `list1` and `list2` product is higher than `noMoreThan1K`, 39 | the splice operation will remove all `list1` items and push all `list2`. 40 | 41 | ### Compatibility 42 | 43 | Every. JavaScript. Engine. 44 | -------------------------------------------------------------------------------- /benchmark.js: -------------------------------------------------------------------------------- 1 | var times = process.argv.length < 3 ? 10 : parseFloat(process.argv[2]); 2 | 3 | var log = require('tressa').log; 4 | var majinbuu = require('./index.js'); 5 | var a1 = Array(times + 1).join('.').split('.').map(Math.random); 6 | var a2 = a1.slice(); 7 | var b = Array(times + 1).join('.').split('.').map(Math.random); 8 | 9 | log(''); 10 | log('# Majin Buu'); 11 | log('size: **' + times + '**'); 12 | console.time('time'); 13 | majinbuu(a1, b); 14 | console.timeEnd('time'); 15 | console.assert(a1.join('') === b.join('')); 16 | console.time('aura time'); 17 | majinbuu( 18 | majinbuu.aura( 19 | { 20 | splice: function () { 21 | a2.splice.apply(a2, arguments); 22 | } 23 | }, 24 | a2 25 | ), 26 | b 27 | ); 28 | console.timeEnd('aura time'); 29 | console.assert(a2.join('') === b.join('')); 30 | 31 | log('- - -'); 32 | var crypto = require("crypto"); 33 | var a = crypto.randomBytes(Math.ceil(times / 2)).toString('hex'); 34 | var b = crypto.randomBytes(Math.ceil(times / 2)).toString('hex'); 35 | console.time('C time'); 36 | var ls = require('child_process').spawnSync('./levenstein', [a, b]); 37 | console.timeEnd('C time'); 38 | log('C distance: ' + ls.stdout.toString()); 39 | -------------------------------------------------------------------------------- /cjs/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /*! Copyright (c) 2017, Andrea Giammarchi, @WebReflection */ 3 | 4 | // grid operations 5 | const DELETE = 'del'; 6 | const INSERT = 'ins'; 7 | const SUBSTITUTE = 'sub'; 8 | 9 | // typed Array 10 | const TypedArray = typeof Int32Array === 'function' ? Int32Array : Array; 11 | 12 | // shortcuts 13 | const { min, sqrt } = Math; 14 | 15 | const majinbuu = function ( 16 | from, to, 17 | fromStart, fromEnd, fromLength, 18 | toStart, toEnd, toLength, 19 | SIZE 20 | ) { 21 | 22 | if(from === to) { 23 | //# same arrays. Do nothing 24 | return; 25 | } 26 | 27 | if (arguments.length < 4) { 28 | SIZE = fromStart || Infinity; 29 | fromLength = from.length; 30 | fromStart = 0; 31 | fromEnd = fromLength; 32 | toLength = to.length; 33 | toStart = 0; 34 | toEnd = toLength; 35 | } else { 36 | SIZE = SIZE || Infinity; 37 | } 38 | 39 | const TOO_MANY = SIZE !== Infinity && 40 | SIZE < sqrt( 41 | ((fromEnd - fromStart) || 1) * 42 | ((toEnd - toStart) || 1) 43 | ); 44 | 45 | if (TOO_MANY || fromLength < 1) { 46 | if (TOO_MANY || toLength) { 47 | from.splice.apply(from, [0, fromLength].concat(to)); 48 | } 49 | return; 50 | } 51 | if (toLength < 1) { 52 | from.splice(0); 53 | return; 54 | } 55 | const minLength = min(fromLength, toLength); 56 | let beginIndex = fromStart; 57 | while(beginIndex < minLength && from[beginIndex] === to[beginIndex]) { 58 | beginIndex += 1; 59 | } 60 | if(beginIndex == fromLength && fromLength == toLength) { 61 | // content of { from } and { to } are equal. Do nothing 62 | return; 63 | } 64 | else { 65 | // relative from both ends { from } and { to }. { -1 } is last element, 66 | // { -2 } is { to[to.length - 2] } and { from[fromLength - 2] } etc 67 | let endRelIndex = 0; 68 | const fromLengthMinus1 = fromEnd - 1; 69 | const toLengthMinus1 = toEnd - 1; 70 | while( 71 | beginIndex < (minLength + endRelIndex) && 72 | from[fromLengthMinus1 + endRelIndex] === to[toLengthMinus1 + endRelIndex] 73 | ) { 74 | endRelIndex--; 75 | } 76 | performOperations( 77 | from, 78 | getOperations( 79 | levenstein( 80 | from, beginIndex, fromLength, 81 | to, endRelIndex, toLength 82 | ), 83 | from, beginIndex, fromLength, 84 | to, endRelIndex, toLength 85 | ) 86 | ); 87 | } 88 | }; 89 | 90 | // given an object that would like to intercept 91 | // all splice operations performed through a list, 92 | // wraps the list.splice method to delegate such object 93 | // and it puts back original splice right before every invocation. 94 | // Note: do not use the same list in two different aura 95 | const aura = (splicer, list) => { 96 | const splice = list.splice; 97 | function $splice() { 98 | list.splice = splice; 99 | const result = splicer.splice.apply(splicer, arguments); 100 | list.splice = $splice; 101 | return result; 102 | } 103 | list.splice = $splice; 104 | return list; 105 | }; 106 | 107 | // Helpers - - - - - - - - - - - - - - - - - - - - - - 108 | 109 | // originally readapted from: 110 | // http://webreflection.blogspot.co.uk/2009/02/levenshtein-algorithm-revisited-25.html 111 | // then rewritten in C for Emscripten (see levenstein.c) 112 | // then "screw you ASM" due no much gain but very bloated code 113 | const levenstein = (from, beginIndex, fromLength, to, endRelIndex, toLength) => { 114 | const fLength = fromLength + 1 - beginIndex + endRelIndex; 115 | const tLength = toLength + 1 - beginIndex + endRelIndex; 116 | const size = fLength * tLength; 117 | const grid = new TypedArray(size); 118 | let x = 0; 119 | let y = 0; 120 | let X = 0; 121 | let Y = 0; 122 | let crow = 0; 123 | let prow = 0; 124 | let del, ins, sub; 125 | grid[0] = 0; 126 | while (++x < tLength) grid[x] = x; 127 | while (++y < fLength) { 128 | X = x = 0; 129 | prow = crow; 130 | crow = y * tLength; 131 | grid[crow + x] = y; 132 | while (++x < tLength) { 133 | del = grid[prow + x] + 1; 134 | ins = grid[crow + X] + 1; 135 | sub = grid[prow + X] + (from[Y + beginIndex] == to[X + beginIndex] ? 0 : 1); 136 | grid[crow + x] = del < ins ? 137 | (del < sub ? 138 | del : sub) : 139 | (ins < sub ? 140 | ins : sub); 141 | ++X; 142 | }; 143 | Y = y; 144 | } 145 | return grid; 146 | }; 147 | 148 | // add operations (in reversed order) 149 | const addOperation = (list, type, x, y, count, items) => { 150 | list.unshift({type, x, y, count, items}); 151 | }; 152 | 153 | // walk the Levenshtein grid bottom -> up 154 | const getOperations = (grid, Y, beginIndex, YLength, X, endRelIndex, XLength) => { 155 | const list = []; 156 | const YL = YLength + 1 - beginIndex + endRelIndex; 157 | const XL = XLength + 1 - beginIndex + endRelIndex; 158 | let y = YL - 1; 159 | let x = XL - 1; 160 | let cell, 161 | top, left, diagonal, 162 | crow, prow; 163 | while (x && y) { 164 | crow = y * XL + x; 165 | prow = crow - XL; 166 | cell = grid[crow]; 167 | top = grid[prow]; 168 | left = grid[crow - 1]; 169 | diagonal = grid[prow - 1]; 170 | if (diagonal <= left && diagonal <= top && diagonal <= cell) { 171 | x--; 172 | y--; 173 | if (diagonal < cell) { 174 | addOperation(list, SUBSTITUTE, x + beginIndex, y + beginIndex, 1, [X[x + beginIndex]]); 175 | } 176 | } 177 | else if (left <= top && left <= cell) { 178 | x--; 179 | addOperation(list, INSERT, x + beginIndex, y + beginIndex, 0, [X[x + beginIndex]]); 180 | } 181 | else { 182 | y--; 183 | addOperation(list, DELETE, x + beginIndex, y + beginIndex, 1, []); 184 | } 185 | } 186 | while (x--) { 187 | addOperation(list, INSERT, x + beginIndex, y + beginIndex, 0, [X[x + beginIndex]]); 188 | } 189 | while (y--) { 190 | addOperation(list, DELETE, x + beginIndex, y + beginIndex, 1, []); 191 | } 192 | return list; 193 | }; 194 | 195 | /* grouped operations */ 196 | const performOperations = (target, operations) => { 197 | const length = operations.length; 198 | let diff = 0; 199 | let i = 1; 200 | let curr, prev, op; 201 | op = (prev = operations[0]); 202 | while (i < length) { 203 | curr = operations[i++]; 204 | if (prev.type === curr.type && (curr.x - prev.x) <= 1 && (curr.y - prev.y) <= 1) { 205 | op.count += curr.count; 206 | op.items = op.items.concat(curr.items); 207 | } else { 208 | target.splice.apply(target, [op.y + diff, op.count].concat(op.items)); 209 | diff += op.type === INSERT ? 210 | op.items.length : (op.type === DELETE ? 211 | -op.count : 0); 212 | op = curr; 213 | } 214 | prev = curr; 215 | } 216 | target.splice.apply(target, [op.y + diff, op.count].concat(op.items)); 217 | }; 218 | 219 | majinbuu.aura = aura; 220 | 221 | Object.defineProperty(exports, '__esModule', {value: true}).default = majinbuu; 222 | exports.aura = aura; 223 | exports.majinbuu = majinbuu; 224 | -------------------------------------------------------------------------------- /coverage/coverage.json: -------------------------------------------------------------------------------- 1 | {"/home/webreflection/code/majinbuu/test.js":{"path":"/home/webreflection/code/majinbuu/test.js","s":{"1":1,"2":1,"3":1,"4":1,"5":9,"6":1,"7":26,"8":26,"9":9,"10":9,"11":9,"12":9,"13":9,"14":9,"15":9,"16":7,"17":7,"18":7,"19":7,"20":7,"21":7,"22":1,"23":1,"24":1,"25":1,"26":1,"27":1,"28":1,"29":1,"30":1,"31":1,"32":1,"33":1,"34":1,"35":1,"36":1,"37":1,"38":1,"39":3,"40":3,"41":1,"42":1,"43":1,"44":1,"45":1,"46":1,"47":1,"48":1,"49":1,"50":1,"51":1,"52":1,"53":1,"54":1,"55":1,"56":1},"b":{"1":[9,1],"2":[9,2],"3":[7,2],"4":[7,1],"5":[1,1,1]},"f":{"1":9,"2":26,"3":3,"4":1},"fnMap":{"1":{"name":"test","line":6,"loc":{"start":{"line":6,"column":0},"end":{"line":6,"column":20}}},"2":{"name":"splice","line":8,"loc":{"start":{"line":8,"column":2},"end":{"line":8,"column":20}}},"3":{"name":"(anonymous_3)","line":48,"loc":{"start":{"line":48,"column":10},"end":{"line":48,"column":22}}},"4":{"name":"(anonymous_4)","line":70,"loc":{"start":{"line":70,"column":12},"end":{"line":70,"column":35}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":40}},"3":{"start":{"line":4,"column":0},"end":{"line":4,"column":19}},"4":{"start":{"line":6,"column":0},"end":{"line":26,"column":1}},"5":{"start":{"line":7,"column":2},"end":{"line":7,"column":12}},"6":{"start":{"line":8,"column":2},"end":{"line":11,"column":3}},"7":{"start":{"line":9,"column":4},"end":{"line":9,"column":12}},"8":{"start":{"line":10,"column":4},"end":{"line":10,"column":44}},"9":{"start":{"line":12,"column":2},"end":{"line":12,"column":24}},"10":{"start":{"line":13,"column":2},"end":{"line":13,"column":24}},"11":{"start":{"line":14,"column":2},"end":{"line":14,"column":12}},"12":{"start":{"line":15,"column":2},"end":{"line":15,"column":22}},"13":{"start":{"line":16,"column":2},"end":{"line":16,"column":25}},"14":{"start":{"line":17,"column":2},"end":{"line":17,"column":108}},"15":{"start":{"line":18,"column":2},"end":{"line":25,"column":3}},"16":{"start":{"line":19,"column":4},"end":{"line":19,"column":22}},"17":{"start":{"line":20,"column":4},"end":{"line":20,"column":22}},"18":{"start":{"line":21,"column":4},"end":{"line":21,"column":14}},"19":{"start":{"line":22,"column":4},"end":{"line":22,"column":24}},"20":{"start":{"line":23,"column":4},"end":{"line":23,"column":23}},"21":{"start":{"line":24,"column":4},"end":{"line":24,"column":97}},"22":{"start":{"line":28,"column":0},"end":{"line":28,"column":19}},"23":{"start":{"line":28,"column":20},"end":{"line":28,"column":51}},"24":{"start":{"line":30,"column":0},"end":{"line":30,"column":13}},"25":{"start":{"line":31,"column":0},"end":{"line":31,"column":21}},"26":{"start":{"line":32,"column":0},"end":{"line":32,"column":31}},"27":{"start":{"line":33,"column":0},"end":{"line":33,"column":26}},"28":{"start":{"line":34,"column":0},"end":{"line":34,"column":16}},"29":{"start":{"line":35,"column":0},"end":{"line":35,"column":21}},"30":{"start":{"line":36,"column":0},"end":{"line":36,"column":24}},"31":{"start":{"line":37,"column":0},"end":{"line":37,"column":26}},"32":{"start":{"line":38,"column":0},"end":{"line":38,"column":31}},"33":{"start":{"line":40,"column":0},"end":{"line":40,"column":25}},"34":{"start":{"line":41,"column":0},"end":{"line":41,"column":47}},"35":{"start":{"line":42,"column":0},"end":{"line":42,"column":40}},"36":{"start":{"line":44,"column":0},"end":{"line":44,"column":24}},"37":{"start":{"line":45,"column":0},"end":{"line":45,"column":28}},"38":{"start":{"line":46,"column":0},"end":{"line":52,"column":2}},"39":{"start":{"line":49,"column":4},"end":{"line":49,"column":24}},"40":{"start":{"line":50,"column":4},"end":{"line":50,"column":53}},"41":{"start":{"line":54,"column":0},"end":{"line":54,"column":37}},"42":{"start":{"line":56,"column":0},"end":{"line":56,"column":36}},"43":{"start":{"line":57,"column":0},"end":{"line":57,"column":57}},"44":{"start":{"line":58,"column":0},"end":{"line":58,"column":62}},"45":{"start":{"line":59,"column":0},"end":{"line":59,"column":58}},"46":{"start":{"line":61,"column":0},"end":{"line":61,"column":14}},"47":{"start":{"line":62,"column":0},"end":{"line":62,"column":33}},"48":{"start":{"line":63,"column":0},"end":{"line":63,"column":27}},"49":{"start":{"line":64,"column":0},"end":{"line":64,"column":57}},"50":{"start":{"line":66,"column":0},"end":{"line":66,"column":30}},"51":{"start":{"line":67,"column":0},"end":{"line":67,"column":21}},"52":{"start":{"line":68,"column":0},"end":{"line":81,"column":2}},"53":{"start":{"line":71,"column":6},"end":{"line":76,"column":8}},"54":{"start":{"line":83,"column":0},"end":{"line":83,"column":34}},"55":{"start":{"line":84,"column":0},"end":{"line":90,"column":2}},"56":{"start":{"line":92,"column":0},"end":{"line":92,"column":75}}},"branchMap":{"1":{"line":17,"type":"binary-expr","locations":[{"start":{"line":17,"column":69},"end":{"line":17,"column":70}},{"start":{"line":17,"column":74},"end":{"line":17,"column":83}}]},"2":{"line":17,"type":"binary-expr","locations":[{"start":{"line":17,"column":90},"end":{"line":17,"column":91}},{"start":{"line":17,"column":95},"end":{"line":17,"column":104}}]},"3":{"line":18,"type":"if","locations":[{"start":{"line":18,"column":2},"end":{"line":18,"column":2}},{"start":{"line":18,"column":2},"end":{"line":18,"column":2}}]},"4":{"line":24,"type":"binary-expr","locations":[{"start":{"line":24,"column":71},"end":{"line":24,"column":72}},{"start":{"line":24,"column":76},"end":{"line":24,"column":85}}]},"5":{"line":72,"type":"binary-expr","locations":[{"start":{"line":72,"column":8},"end":{"line":72,"column":19}},{"start":{"line":73,"column":8},"end":{"line":73,"column":28}},{"start":{"line":74,"column":8},"end":{"line":74,"column":55}}]}}},"/home/webreflection/code/majinbuu/cjs/index.js":{"path":"/home/webreflection/code/majinbuu/cjs/index.js","s":{"1":2,"2":2,"3":2,"4":2,"5":2,"6":2,"7":21,"8":1,"9":20,"10":19,"11":19,"12":19,"13":19,"14":19,"15":19,"16":19,"17":1,"18":20,"19":20,"20":3,"21":2,"22":3,"23":17,"24":1,"25":1,"26":16,"27":16,"28":16,"29":16,"30":16,"31":1,"32":15,"33":15,"34":15,"35":15,"36":13,"37":15,"38":2,"39":3,"40":1,"41":4,"42":4,"43":4,"44":4,"45":3,"46":3,"47":2,"48":15,"49":15,"50":15,"51":15,"52":15,"53":15,"54":15,"55":15,"56":15,"57":15,"58":15,"59":15,"60":15,"61":72,"62":15,"63":65,"64":65,"65":65,"66":65,"67":65,"68":380,"69":380,"70":380,"71":380,"72":380,"73":65,"74":15,"75":2,"76":66,"77":2,"78":15,"79":15,"80":15,"81":15,"82":15,"83":15,"84":15,"85":60,"86":60,"87":60,"88":60,"89":60,"90":60,"91":60,"92":48,"93":48,"94":48,"95":25,"96":12,"97":7,"98":7,"99":5,"100":5,"101":15,"102":17,"103":15,"104":12,"105":15,"106":2,"107":15,"108":15,"109":15,"110":15,"111":15,"112":15,"113":51,"114":51,"115":37,"116":37,"117":14,"118":14,"119":14,"120":51,"121":15,"122":2,"123":2,"124":2,"125":2},"b":{"1":[1,1],"2":[1,20],"3":[19,1],"4":[19,9],"5":[1,1],"6":[20,10],"7":[10,1],"8":[10,2],"9":[3,17],"10":[20,19],"11":[2,1],"12":[3,2],"13":[1,16],"14":[32,29],"15":[1,15],"16":[16,2],"17":[28,23],"18":[42,338],"19":[150,230],"20":[47,103],"21":[51,179],"22":[75,66],"23":[48,12],"24":[60,53,48],"25":[25,23],"26":[7,5],"27":[12,7],"28":[37,14],"29":[51,42,37],"30":[4,10],"31":[2,8]},"f":{"1":21,"2":4},"fnMap":{"1":{"name":"(anonymous_1)","line":15,"loc":{"start":{"line":15,"column":17},"end":{"line":20,"column":2}}},"2":{"name":"$splice","line":97,"loc":{"start":{"line":97,"column":2},"end":{"line":97,"column":21}}}},"statementMap":{"1":{"start":{"line":5,"column":0},"end":{"line":5,"column":21}},"2":{"start":{"line":6,"column":0},"end":{"line":6,"column":21}},"3":{"start":{"line":7,"column":0},"end":{"line":7,"column":25}},"4":{"start":{"line":10,"column":0},"end":{"line":10,"column":73}},"5":{"start":{"line":13,"column":0},"end":{"line":13,"column":27}},"6":{"start":{"line":15,"column":0},"end":{"line":88,"column":2}},"7":{"start":{"line":22,"column":2},"end":{"line":25,"column":3}},"8":{"start":{"line":24,"column":4},"end":{"line":24,"column":11}},"9":{"start":{"line":27,"column":2},"end":{"line":37,"column":3}},"10":{"start":{"line":28,"column":4},"end":{"line":28,"column":33}},"11":{"start":{"line":29,"column":4},"end":{"line":29,"column":29}},"12":{"start":{"line":30,"column":4},"end":{"line":30,"column":18}},"13":{"start":{"line":31,"column":4},"end":{"line":31,"column":25}},"14":{"start":{"line":32,"column":4},"end":{"line":32,"column":25}},"15":{"start":{"line":33,"column":4},"end":{"line":33,"column":16}},"16":{"start":{"line":34,"column":4},"end":{"line":34,"column":21}},"17":{"start":{"line":36,"column":4},"end":{"line":36,"column":28}},"18":{"start":{"line":39,"column":2},"end":{"line":43,"column":22}},"19":{"start":{"line":45,"column":2},"end":{"line":50,"column":3}},"20":{"start":{"line":46,"column":4},"end":{"line":48,"column":5}},"21":{"start":{"line":47,"column":6},"end":{"line":47,"column":58}},"22":{"start":{"line":49,"column":4},"end":{"line":49,"column":11}},"23":{"start":{"line":51,"column":2},"end":{"line":54,"column":3}},"24":{"start":{"line":52,"column":4},"end":{"line":52,"column":19}},"25":{"start":{"line":53,"column":4},"end":{"line":53,"column":11}},"26":{"start":{"line":55,"column":2},"end":{"line":55,"column":46}},"27":{"start":{"line":56,"column":2},"end":{"line":56,"column":29}},"28":{"start":{"line":57,"column":2},"end":{"line":59,"column":3}},"29":{"start":{"line":58,"column":4},"end":{"line":58,"column":20}},"30":{"start":{"line":60,"column":2},"end":{"line":87,"column":3}},"31":{"start":{"line":62,"column":4},"end":{"line":62,"column":11}},"32":{"start":{"line":67,"column":4},"end":{"line":67,"column":24}},"33":{"start":{"line":68,"column":4},"end":{"line":68,"column":41}},"34":{"start":{"line":69,"column":4},"end":{"line":69,"column":37}},"35":{"start":{"line":70,"column":4},"end":{"line":75,"column":5}},"36":{"start":{"line":74,"column":6},"end":{"line":74,"column":20}},"37":{"start":{"line":76,"column":4},"end":{"line":86,"column":6}},"38":{"start":{"line":95,"column":0},"end":{"line":105,"column":2}},"39":{"start":{"line":96,"column":2},"end":{"line":96,"column":29}},"40":{"start":{"line":97,"column":2},"end":{"line":102,"column":3}},"41":{"start":{"line":98,"column":4},"end":{"line":98,"column":25}},"42":{"start":{"line":99,"column":4},"end":{"line":99,"column":60}},"43":{"start":{"line":100,"column":4},"end":{"line":100,"column":26}},"44":{"start":{"line":101,"column":4},"end":{"line":101,"column":18}},"45":{"start":{"line":103,"column":2},"end":{"line":103,"column":24}},"46":{"start":{"line":104,"column":2},"end":{"line":104,"column":14}},"47":{"start":{"line":113,"column":0},"end":{"line":146,"column":2}},"48":{"start":{"line":114,"column":2},"end":{"line":114,"column":60}},"49":{"start":{"line":115,"column":2},"end":{"line":115,"column":58}},"50":{"start":{"line":116,"column":2},"end":{"line":116,"column":33}},"51":{"start":{"line":117,"column":2},"end":{"line":117,"column":36}},"52":{"start":{"line":118,"column":2},"end":{"line":118,"column":12}},"53":{"start":{"line":119,"column":2},"end":{"line":119,"column":12}},"54":{"start":{"line":120,"column":2},"end":{"line":120,"column":12}},"55":{"start":{"line":121,"column":2},"end":{"line":121,"column":12}},"56":{"start":{"line":122,"column":2},"end":{"line":122,"column":15}},"57":{"start":{"line":123,"column":2},"end":{"line":123,"column":15}},"58":{"start":{"line":124,"column":2},"end":{"line":124,"column":20}},"59":{"start":{"line":125,"column":2},"end":{"line":125,"column":14}},"60":{"start":{"line":126,"column":2},"end":{"line":126,"column":36}},"61":{"start":{"line":126,"column":24},"end":{"line":126,"column":36}},"62":{"start":{"line":127,"column":2},"end":{"line":144,"column":3}},"63":{"start":{"line":128,"column":4},"end":{"line":128,"column":14}},"64":{"start":{"line":129,"column":4},"end":{"line":129,"column":16}},"65":{"start":{"line":130,"column":4},"end":{"line":130,"column":23}},"66":{"start":{"line":131,"column":4},"end":{"line":131,"column":23}},"67":{"start":{"line":132,"column":4},"end":{"line":142,"column":5}},"68":{"start":{"line":133,"column":6},"end":{"line":133,"column":31}},"69":{"start":{"line":134,"column":6},"end":{"line":134,"column":31}},"70":{"start":{"line":135,"column":6},"end":{"line":135,"column":82}},"71":{"start":{"line":136,"column":6},"end":{"line":140,"column":37}},"72":{"start":{"line":141,"column":6},"end":{"line":141,"column":10}},"73":{"start":{"line":143,"column":4},"end":{"line":143,"column":10}},"74":{"start":{"line":145,"column":2},"end":{"line":145,"column":14}},"75":{"start":{"line":149,"column":0},"end":{"line":151,"column":2}},"76":{"start":{"line":150,"column":2},"end":{"line":150,"column":43}},"77":{"start":{"line":154,"column":0},"end":{"line":193,"column":2}},"78":{"start":{"line":155,"column":2},"end":{"line":155,"column":18}},"79":{"start":{"line":156,"column":2},"end":{"line":156,"column":52}},"80":{"start":{"line":157,"column":2},"end":{"line":157,"column":52}},"81":{"start":{"line":158,"column":2},"end":{"line":158,"column":17}},"82":{"start":{"line":159,"column":2},"end":{"line":159,"column":17}},"83":{"start":{"line":160,"column":2},"end":{"line":162,"column":17}},"84":{"start":{"line":163,"column":2},"end":{"line":185,"column":3}},"85":{"start":{"line":164,"column":4},"end":{"line":164,"column":22}},"86":{"start":{"line":165,"column":4},"end":{"line":165,"column":21}},"87":{"start":{"line":166,"column":4},"end":{"line":166,"column":22}},"88":{"start":{"line":167,"column":4},"end":{"line":167,"column":21}},"89":{"start":{"line":168,"column":4},"end":{"line":168,"column":26}},"90":{"start":{"line":169,"column":4},"end":{"line":169,"column":30}},"91":{"start":{"line":170,"column":4},"end":{"line":184,"column":5}},"92":{"start":{"line":171,"column":6},"end":{"line":171,"column":10}},"93":{"start":{"line":172,"column":6},"end":{"line":172,"column":10}},"94":{"start":{"line":173,"column":6},"end":{"line":175,"column":7}},"95":{"start":{"line":174,"column":8},"end":{"line":174,"column":95}},"96":{"start":{"line":177,"column":9},"end":{"line":184,"column":5}},"97":{"start":{"line":178,"column":6},"end":{"line":178,"column":10}},"98":{"start":{"line":179,"column":6},"end":{"line":179,"column":89}},"99":{"start":{"line":182,"column":6},"end":{"line":182,"column":10}},"100":{"start":{"line":183,"column":6},"end":{"line":183,"column":72}},"101":{"start":{"line":186,"column":2},"end":{"line":188,"column":3}},"102":{"start":{"line":187,"column":4},"end":{"line":187,"column":87}},"103":{"start":{"line":189,"column":2},"end":{"line":191,"column":3}},"104":{"start":{"line":190,"column":4},"end":{"line":190,"column":70}},"105":{"start":{"line":192,"column":2},"end":{"line":192,"column":14}},"106":{"start":{"line":196,"column":0},"end":{"line":217,"column":2}},"107":{"start":{"line":197,"column":2},"end":{"line":197,"column":35}},"108":{"start":{"line":198,"column":2},"end":{"line":198,"column":15}},"109":{"start":{"line":199,"column":2},"end":{"line":199,"column":12}},"110":{"start":{"line":200,"column":2},"end":{"line":200,"column":21}},"111":{"start":{"line":201,"column":2},"end":{"line":201,"column":30}},"112":{"start":{"line":202,"column":2},"end":{"line":215,"column":3}},"113":{"start":{"line":203,"column":4},"end":{"line":203,"column":27}},"114":{"start":{"line":204,"column":4},"end":{"line":213,"column":5}},"115":{"start":{"line":205,"column":6},"end":{"line":205,"column":29}},"116":{"start":{"line":206,"column":6},"end":{"line":206,"column":45}},"117":{"start":{"line":208,"column":6},"end":{"line":208,"column":76}},"118":{"start":{"line":209,"column":6},"end":{"line":211,"column":25}},"119":{"start":{"line":212,"column":6},"end":{"line":212,"column":16}},"120":{"start":{"line":214,"column":4},"end":{"line":214,"column":16}},"121":{"start":{"line":216,"column":2},"end":{"line":216,"column":72}},"122":{"start":{"line":219,"column":0},"end":{"line":219,"column":21}},"123":{"start":{"line":221,"column":0},"end":{"line":221,"column":79}},"124":{"start":{"line":222,"column":0},"end":{"line":222,"column":20}},"125":{"start":{"line":223,"column":0},"end":{"line":223,"column":28}}},"branchMap":{"1":{"line":10,"type":"cond-expr","locations":[{"start":{"line":10,"column":54},"end":{"line":10,"column":64}},{"start":{"line":10,"column":67},"end":{"line":10,"column":72}}]},"2":{"line":22,"type":"if","locations":[{"start":{"line":22,"column":2},"end":{"line":22,"column":2}},{"start":{"line":22,"column":2},"end":{"line":22,"column":2}}]},"3":{"line":27,"type":"if","locations":[{"start":{"line":27,"column":2},"end":{"line":27,"column":2}},{"start":{"line":27,"column":2},"end":{"line":27,"column":2}}]},"4":{"line":28,"type":"binary-expr","locations":[{"start":{"line":28,"column":11},"end":{"line":28,"column":20}},{"start":{"line":28,"column":24},"end":{"line":28,"column":32}}]},"5":{"line":36,"type":"binary-expr","locations":[{"start":{"line":36,"column":11},"end":{"line":36,"column":15}},{"start":{"line":36,"column":19},"end":{"line":36,"column":27}}]},"6":{"line":39,"type":"binary-expr","locations":[{"start":{"line":39,"column":20},"end":{"line":39,"column":37}},{"start":{"line":40,"column":20},"end":{"line":43,"column":21}}]},"7":{"line":41,"type":"binary-expr","locations":[{"start":{"line":41,"column":24},"end":{"line":41,"column":43}},{"start":{"line":41,"column":48},"end":{"line":41,"column":49}}]},"8":{"line":42,"type":"binary-expr","locations":[{"start":{"line":42,"column":24},"end":{"line":42,"column":39}},{"start":{"line":42,"column":44},"end":{"line":42,"column":45}}]},"9":{"line":45,"type":"if","locations":[{"start":{"line":45,"column":2},"end":{"line":45,"column":2}},{"start":{"line":45,"column":2},"end":{"line":45,"column":2}}]},"10":{"line":45,"type":"binary-expr","locations":[{"start":{"line":45,"column":6},"end":{"line":45,"column":14}},{"start":{"line":45,"column":18},"end":{"line":45,"column":32}}]},"11":{"line":46,"type":"if","locations":[{"start":{"line":46,"column":4},"end":{"line":46,"column":4}},{"start":{"line":46,"column":4},"end":{"line":46,"column":4}}]},"12":{"line":46,"type":"binary-expr","locations":[{"start":{"line":46,"column":8},"end":{"line":46,"column":16}},{"start":{"line":46,"column":20},"end":{"line":46,"column":28}}]},"13":{"line":51,"type":"if","locations":[{"start":{"line":51,"column":2},"end":{"line":51,"column":2}},{"start":{"line":51,"column":2},"end":{"line":51,"column":2}}]},"14":{"line":57,"type":"binary-expr","locations":[{"start":{"line":57,"column":8},"end":{"line":57,"column":30}},{"start":{"line":57,"column":34},"end":{"line":57,"column":69}}]},"15":{"line":60,"type":"if","locations":[{"start":{"line":60,"column":2},"end":{"line":60,"column":2}},{"start":{"line":60,"column":2},"end":{"line":60,"column":2}}]},"16":{"line":60,"type":"binary-expr","locations":[{"start":{"line":60,"column":5},"end":{"line":60,"column":29}},{"start":{"line":60,"column":33},"end":{"line":60,"column":55}}]},"17":{"line":71,"type":"binary-expr","locations":[{"start":{"line":71,"column":6},"end":{"line":71,"column":44}},{"start":{"line":72,"column":6},"end":{"line":72,"column":79}}]},"18":{"line":135,"type":"cond-expr","locations":[{"start":{"line":135,"column":75},"end":{"line":135,"column":76}},{"start":{"line":135,"column":79},"end":{"line":135,"column":80}}]},"19":{"line":136,"type":"cond-expr","locations":[{"start":{"line":137,"column":25},"end":{"line":138,"column":35}},{"start":{"line":139,"column":25},"end":{"line":140,"column":35}}]},"20":{"line":137,"type":"cond-expr","locations":[{"start":{"line":138,"column":26},"end":{"line":138,"column":29}},{"start":{"line":138,"column":32},"end":{"line":138,"column":35}}]},"21":{"line":139,"type":"cond-expr","locations":[{"start":{"line":140,"column":26},"end":{"line":140,"column":29}},{"start":{"line":140,"column":32},"end":{"line":140,"column":35}}]},"22":{"line":163,"type":"binary-expr","locations":[{"start":{"line":163,"column":9},"end":{"line":163,"column":10}},{"start":{"line":163,"column":14},"end":{"line":163,"column":15}}]},"23":{"line":170,"type":"if","locations":[{"start":{"line":170,"column":4},"end":{"line":170,"column":4}},{"start":{"line":170,"column":4},"end":{"line":170,"column":4}}]},"24":{"line":170,"type":"binary-expr","locations":[{"start":{"line":170,"column":8},"end":{"line":170,"column":24}},{"start":{"line":170,"column":28},"end":{"line":170,"column":43}},{"start":{"line":170,"column":47},"end":{"line":170,"column":63}}]},"25":{"line":173,"type":"if","locations":[{"start":{"line":173,"column":6},"end":{"line":173,"column":6}},{"start":{"line":173,"column":6},"end":{"line":173,"column":6}}]},"26":{"line":177,"type":"if","locations":[{"start":{"line":177,"column":9},"end":{"line":177,"column":9}},{"start":{"line":177,"column":9},"end":{"line":177,"column":9}}]},"27":{"line":177,"type":"binary-expr","locations":[{"start":{"line":177,"column":13},"end":{"line":177,"column":24}},{"start":{"line":177,"column":28},"end":{"line":177,"column":40}}]},"28":{"line":204,"type":"if","locations":[{"start":{"line":204,"column":4},"end":{"line":204,"column":4}},{"start":{"line":204,"column":4},"end":{"line":204,"column":4}}]},"29":{"line":204,"type":"binary-expr","locations":[{"start":{"line":204,"column":8},"end":{"line":204,"column":31}},{"start":{"line":204,"column":35},"end":{"line":204,"column":57}},{"start":{"line":204,"column":61},"end":{"line":204,"column":83}}]},"30":{"line":209,"type":"cond-expr","locations":[{"start":{"line":210,"column":8},"end":{"line":210,"column":23}},{"start":{"line":210,"column":27},"end":{"line":211,"column":23}}]},"31":{"line":210,"type":"cond-expr","locations":[{"start":{"line":211,"column":10},"end":{"line":211,"column":19}},{"start":{"line":211,"column":22},"end":{"line":211,"column":23}}]}}}} -------------------------------------------------------------------------------- /coverage/lcov-report/base.css: -------------------------------------------------------------------------------- 1 | body, html { 2 | margin:0; padding: 0; 3 | height: 100%; 4 | } 5 | body { 6 | font-family: Helvetica Neue, Helvetica, Arial; 7 | font-size: 14px; 8 | color:#333; 9 | } 10 | .small { font-size: 12px; } 11 | *, *:after, *:before { 12 | -webkit-box-sizing:border-box; 13 | -moz-box-sizing:border-box; 14 | box-sizing:border-box; 15 | } 16 | h1 { font-size: 20px; margin: 0;} 17 | h2 { font-size: 14px; } 18 | pre { 19 | font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace; 20 | margin: 0; 21 | padding: 0; 22 | -moz-tab-size: 2; 23 | -o-tab-size: 2; 24 | tab-size: 2; 25 | } 26 | a { color:#0074D9; text-decoration:none; } 27 | a:hover { text-decoration:underline; } 28 | .strong { font-weight: bold; } 29 | .space-top1 { padding: 10px 0 0 0; } 30 | .pad2y { padding: 20px 0; } 31 | .pad1y { padding: 10px 0; } 32 | .pad2x { padding: 0 20px; } 33 | .pad2 { padding: 20px; } 34 | .pad1 { padding: 10px; } 35 | .space-left2 { padding-left:55px; } 36 | .space-right2 { padding-right:20px; } 37 | .center { text-align:center; } 38 | .clearfix { display:block; } 39 | .clearfix:after { 40 | content:''; 41 | display:block; 42 | height:0; 43 | clear:both; 44 | visibility:hidden; 45 | } 46 | .fl { float: left; } 47 | @media only screen and (max-width:640px) { 48 | .col3 { width:100%; max-width:100%; } 49 | .hide-mobile { display:none!important; } 50 | } 51 | 52 | .quiet { 53 | color: #7f7f7f; 54 | color: rgba(0,0,0,0.5); 55 | } 56 | .quiet a { opacity: 0.7; } 57 | 58 | .fraction { 59 | font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; 60 | font-size: 10px; 61 | color: #555; 62 | background: #E8E8E8; 63 | padding: 4px 5px; 64 | border-radius: 3px; 65 | vertical-align: middle; 66 | } 67 | 68 | div.path a:link, div.path a:visited { color: #333; } 69 | table.coverage { 70 | border-collapse: collapse; 71 | margin: 10px 0 0 0; 72 | padding: 0; 73 | } 74 | 75 | table.coverage td { 76 | margin: 0; 77 | padding: 0; 78 | vertical-align: top; 79 | } 80 | table.coverage td.line-count { 81 | text-align: right; 82 | padding: 0 5px 0 20px; 83 | } 84 | table.coverage td.line-coverage { 85 | text-align: right; 86 | padding-right: 10px; 87 | min-width:20px; 88 | } 89 | 90 | table.coverage td span.cline-any { 91 | display: inline-block; 92 | padding: 0 5px; 93 | width: 100%; 94 | } 95 | .missing-if-branch { 96 | display: inline-block; 97 | margin-right: 5px; 98 | border-radius: 3px; 99 | position: relative; 100 | padding: 0 4px; 101 | background: #333; 102 | color: yellow; 103 | } 104 | 105 | .skip-if-branch { 106 | display: none; 107 | margin-right: 10px; 108 | position: relative; 109 | padding: 0 4px; 110 | background: #ccc; 111 | color: white; 112 | } 113 | .missing-if-branch .typ, .skip-if-branch .typ { 114 | color: inherit !important; 115 | } 116 | .coverage-summary { 117 | border-collapse: collapse; 118 | width: 100%; 119 | } 120 | .coverage-summary tr { border-bottom: 1px solid #bbb; } 121 | .keyline-all { border: 1px solid #ddd; } 122 | .coverage-summary td, .coverage-summary th { padding: 10px; } 123 | .coverage-summary tbody { border: 1px solid #bbb; } 124 | .coverage-summary td { border-right: 1px solid #bbb; } 125 | .coverage-summary td:last-child { border-right: none; } 126 | .coverage-summary th { 127 | text-align: left; 128 | font-weight: normal; 129 | white-space: nowrap; 130 | } 131 | .coverage-summary th.file { border-right: none !important; } 132 | .coverage-summary th.pct { } 133 | .coverage-summary th.pic, 134 | .coverage-summary th.abs, 135 | .coverage-summary td.pct, 136 | .coverage-summary td.abs { text-align: right; } 137 | .coverage-summary td.file { white-space: nowrap; } 138 | .coverage-summary td.pic { min-width: 120px !important; } 139 | .coverage-summary tfoot td { } 140 | 141 | .coverage-summary .sorter { 142 | height: 10px; 143 | width: 7px; 144 | display: inline-block; 145 | margin-left: 0.5em; 146 | background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; 147 | } 148 | .coverage-summary .sorted .sorter { 149 | background-position: 0 -20px; 150 | } 151 | .coverage-summary .sorted-desc .sorter { 152 | background-position: 0 -10px; 153 | } 154 | .status-line { height: 10px; } 155 | /* dark red */ 156 | .red.solid, .status-line.low, .low .cover-fill { background:#C21F39 } 157 | .low .chart { border:1px solid #C21F39 } 158 | /* medium red */ 159 | .cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE } 160 | /* light red */ 161 | .low, .cline-no { background:#FCE1E5 } 162 | /* light green */ 163 | .high, .cline-yes { background:rgb(230,245,208) } 164 | /* medium green */ 165 | .cstat-yes { background:rgb(161,215,106) } 166 | /* dark green */ 167 | .status-line.high, .high .cover-fill { background:rgb(77,146,33) } 168 | .high .chart { border:1px solid rgb(77,146,33) } 169 | /* dark yellow (gold) */ 170 | .medium .chart { border:1px solid #f9cd0b; } 171 | .status-line.medium, .medium .cover-fill { background: #f9cd0b; } 172 | /* light yellow */ 173 | .medium { background: #fff4c2; } 174 | /* light gray */ 175 | span.cline-neutral { background: #eaeaea; } 176 | 177 | .cbranch-no { background: yellow !important; color: #111; } 178 | 179 | .cstat-skip { background: #ddd; color: #111; } 180 | .fstat-skip { background: #ddd; color: #111 !important; } 181 | .cbranch-skip { background: #ddd !important; color: #111; } 182 | 183 | 184 | .cover-fill, .cover-empty { 185 | display:inline-block; 186 | height: 12px; 187 | } 188 | .chart { 189 | line-height: 0; 190 | } 191 | .cover-empty { 192 | background: white; 193 | } 194 | .cover-full { 195 | border-right: none !important; 196 | } 197 | pre.prettyprint { 198 | border: none !important; 199 | padding: 0 !important; 200 | margin: 0 !important; 201 | } 202 | .com { color: #999 !important; } 203 | .ignore-none { color: #999; font-weight: normal; } 204 | 205 | .wrapper { 206 | min-height: 100%; 207 | height: auto !important; 208 | height: 100%; 209 | margin: 0 auto -48px; 210 | } 211 | .footer, .push { 212 | height: 48px; 213 | } 214 | -------------------------------------------------------------------------------- /coverage/lcov-report/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for All files 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | / 20 |

21 |
22 |
23 | 100% 24 | Statements 25 | 181/181 26 |
27 |
28 | 100% 29 | Branches 30 | 75/75 31 |
32 |
33 | 100% 34 | Functions 35 | 6/6 36 |
37 |
38 | 100% 39 | Lines 40 | 179/179 41 |
42 |
43 |
44 |
45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 |
FileStatementsBranchesFunctionsLines
majinbuu/
100%56/56100%11/11100%4/4100%55/55
majinbuu/cjs/
100%125/125100%64/64100%2/2100%124/124
89 |
90 |
91 | 95 | 96 | 97 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /coverage/lcov-report/majinbuu/cjs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for majinbuu/cjs/ 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | all files majinbuu/cjs/ 20 |

21 |
22 |
23 | 100% 24 | Statements 25 | 125/125 26 |
27 |
28 | 100% 29 | Branches 30 | 64/64 31 |
32 |
33 | 100% 34 | Functions 35 | 2/2 36 |
37 |
38 | 100% 39 | Lines 40 | 124/124 41 |
42 |
43 |
44 |
45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
FileStatementsBranchesFunctionsLines
index.js
100%125/125100%64/64100%2/2100%124/124
76 |
77 |
78 | 82 | 83 | 84 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /coverage/lcov-report/majinbuu/cjs/index.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for majinbuu/cjs/index.js 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | all files / majinbuu/cjs/ index.js 20 |

21 |
22 |
23 | 100% 24 | Statements 25 | 125/125 26 |
27 |
28 | 100% 29 | Branches 30 | 64/64 31 |
32 |
33 | 100% 34 | Functions 35 | 2/2 36 |
37 |
38 | 100% 39 | Lines 40 | 124/124 41 |
42 |
43 |
44 |
45 |

 46 | 
716 | 
1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 63 | 18 64 | 19 65 | 20 66 | 21 67 | 22 68 | 23 69 | 24 70 | 25 71 | 26 72 | 27 73 | 28 74 | 29 75 | 30 76 | 31 77 | 32 78 | 33 79 | 34 80 | 35 81 | 36 82 | 37 83 | 38 84 | 39 85 | 40 86 | 41 87 | 42 88 | 43 89 | 44 90 | 45 91 | 46 92 | 47 93 | 48 94 | 49 95 | 50 96 | 51 97 | 52 98 | 53 99 | 54 100 | 55 101 | 56 102 | 57 103 | 58 104 | 59 105 | 60 106 | 61 107 | 62 108 | 63 109 | 64 110 | 65 111 | 66 112 | 67 113 | 68 114 | 69 115 | 70 116 | 71 117 | 72 118 | 73 119 | 74 120 | 75 121 | 76 122 | 77 123 | 78 124 | 79 125 | 80 126 | 81 127 | 82 128 | 83 129 | 84 130 | 85 131 | 86 132 | 87 133 | 88 134 | 89 135 | 90 136 | 91 137 | 92 138 | 93 139 | 94 140 | 95 141 | 96 142 | 97 143 | 98 144 | 99 145 | 100 146 | 101 147 | 102 148 | 103 149 | 104 150 | 105 151 | 106 152 | 107 153 | 108 154 | 109 155 | 110 156 | 111 157 | 112 158 | 113 159 | 114 160 | 115 161 | 116 162 | 117 163 | 118 164 | 119 165 | 120 166 | 121 167 | 122 168 | 123 169 | 124 170 | 125 171 | 126 172 | 127 173 | 128 174 | 129 175 | 130 176 | 131 177 | 132 178 | 133 179 | 134 180 | 135 181 | 136 182 | 137 183 | 138 184 | 139 185 | 140 186 | 141 187 | 142 188 | 143 189 | 144 190 | 145 191 | 146 192 | 147 193 | 148 194 | 149 195 | 150 196 | 151 197 | 152 198 | 153 199 | 154 200 | 155 201 | 156 202 | 157 203 | 158 204 | 159 205 | 160 206 | 161 207 | 162 208 | 163 209 | 164 210 | 165 211 | 166 212 | 167 213 | 168 214 | 169 215 | 170 216 | 171 217 | 172 218 | 173 219 | 174 220 | 175 221 | 176 222 | 177 223 | 178 224 | 179 225 | 180 226 | 181 227 | 182 228 | 183 229 | 184 230 | 185 231 | 186 232 | 187 233 | 188 234 | 189 235 | 190 236 | 191 237 | 192 238 | 193 239 | 194 240 | 195 241 | 196 242 | 197 243 | 198 244 | 199 245 | 200 246 | 201 247 | 202 248 | 203 249 | 204 250 | 205 251 | 206 252 | 207 253 | 208 254 | 209 255 | 210 256 | 211 257 | 212 258 | 213 259 | 214 260 | 215 261 | 216 262 | 217 263 | 218 264 | 219 265 | 220 266 | 221 267 | 222 268 | 223 269 | 224  270 |   271 |   272 |   273 | 274 | 275 | 276 |   277 |   278 | 279 |   280 |   281 | 282 |   283 | 284 |   285 |   286 |   287 |   288 |   289 |   290 | 21× 291 |   292 | 293 |   294 |   295 | 20× 296 | 19× 297 | 19× 298 | 19× 299 | 19× 300 | 19× 301 | 19× 302 | 19× 303 |   304 | 305 |   306 |   307 | 20× 308 |   309 |   310 |   311 |   312 |   313 | 20× 314 | 315 | 316 |   317 | 318 |   319 | 17× 320 | 321 | 322 |   323 | 16× 324 | 16× 325 | 16× 326 | 16× 327 |   328 | 16× 329 |   330 | 331 |   332 |   333 |   334 |   335 | 15× 336 | 15× 337 | 15× 338 | 15× 339 |   340 |   341 |   342 | 13× 343 |   344 | 15× 345 |   346 |   347 |   348 |   349 |   350 |   351 |   352 |   353 |   354 |   355 |   356 |   357 |   358 |   359 |   360 |   361 |   362 |   363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 |   371 | 372 | 373 |   374 |   375 |   376 |   377 |   378 |   379 |   380 |   381 | 382 | 15× 383 | 15× 384 | 15× 385 | 15× 386 | 15× 387 | 15× 388 | 15× 389 | 15× 390 | 15× 391 | 15× 392 | 15× 393 | 15× 394 | 72× 395 | 15× 396 | 65× 397 | 65× 398 | 65× 399 | 65× 400 | 65× 401 | 380× 402 | 380× 403 | 380× 404 | 380× 405 |   406 |   407 |   408 |   409 | 380× 410 |   411 | 65× 412 |   413 | 15× 414 |   415 |   416 |   417 | 418 | 66× 419 |   420 |   421 |   422 | 423 | 15× 424 | 15× 425 | 15× 426 | 15× 427 | 15× 428 | 15× 429 |   430 |   431 | 15× 432 | 60× 433 | 60× 434 | 60× 435 | 60× 436 | 60× 437 | 60× 438 | 60× 439 | 48× 440 | 48× 441 | 48× 442 | 25× 443 |   444 |   445 | 12× 446 | 447 | 448 |   449 |   450 | 451 | 452 |   453 |   454 | 15× 455 | 17× 456 |   457 | 15× 458 | 12× 459 |   460 | 15× 461 |   462 |   463 |   464 | 465 | 15× 466 | 15× 467 | 15× 468 | 15× 469 | 15× 470 | 15× 471 | 51× 472 | 51× 473 | 37× 474 | 37× 475 |   476 | 14× 477 | 14× 478 |   479 |   480 | 14× 481 |   482 | 51× 483 |   484 | 15× 485 |   486 |   487 | 488 |   489 | 490 | 491 | 492 |  
'use strict';
493 | /*! Copyright (c) 2017, Andrea Giammarchi, @WebReflection */
494 |  
495 | // grid operations
496 | const DELETE = 'del';
497 | const INSERT = 'ins';
498 | const SUBSTITUTE = 'sub';
499 |  
500 | // typed Array
501 | const TypedArray = typeof Int32Array === 'function' ? Int32Array : Array;
502 |  
503 | // shortcuts
504 | const { min, sqrt } = Math;
505 |  
506 | const majinbuu = function (
507 |   from, to,
508 |   fromStart, fromEnd, fromLength,
509 |   toStart, toEnd, toLength,
510 |   SIZE
511 | ) {
512 |  
513 |   if(from === to) {
514 |     //# same arrays. Do nothing
515 |     return;
516 |   }
517 |  
518 |   if (arguments.length < 4) {
519 |     SIZE = fromStart || Infinity;
520 |     fromLength = from.length;
521 |     fromStart = 0;
522 |     fromEnd = fromLength;
523 |     toLength = to.length;
524 |     toStart = 0;
525 |     toEnd = toLength;
526 |   } else {
527 |     SIZE = SIZE || Infinity;
528 |   }
529 |  
530 |   const TOO_MANY =  SIZE !== Infinity &&
531 |                     SIZE < sqrt(
532 |                       ((fromEnd - fromStart) || 1) *
533 |                       ((toEnd - toStart) || 1)
534 |                     );
535 |  
536 |   if (TOO_MANY || fromLength < 1) {
537 |     if (TOO_MANY || toLength) {
538 |       from.splice.apply(from, [0, fromLength].concat(to));
539 |     }
540 |     return;
541 |   }
542 |   if (toLength < 1) {
543 |     from.splice(0);
544 |     return;
545 |   }
546 |   const minLength = min(fromLength, toLength);
547 |   let beginIndex = fromStart;
548 |   while(beginIndex < minLength && from[beginIndex] === to[beginIndex]) {
549 |     beginIndex += 1;
550 |   }
551 |   if(beginIndex == fromLength && fromLength == toLength) {
552 |     // content of { from } and { to } are equal. Do nothing
553 |     return;
554 |   }
555 |   else {
556 |     // relative from both ends { from } and { to }. { -1 } is last element,
557 |     // { -2 } is { to[to.length - 2] } and { from[fromLength - 2] } etc
558 |     let endRelIndex = 0;
559 |     const fromLengthMinus1 = fromEnd - 1;
560 |     const toLengthMinus1 = toEnd - 1;  
561 |     while(
562 |       beginIndex < (minLength + endRelIndex) &&
563 |       from[fromLengthMinus1 + endRelIndex] === to[toLengthMinus1 + endRelIndex]
564 |     ) {
565 |       endRelIndex--;
566 |     }
567 |     performOperations(
568 |       from,
569 |       getOperations(
570 |         levenstein(
571 |           from, beginIndex, fromLength,
572 |           to, endRelIndex, toLength
573 |         ),
574 |         from, beginIndex, fromLength,
575 |         to, endRelIndex, toLength
576 |       )
577 |     );
578 |   }
579 | }; 
580 |  
581 | // given an object that would like to intercept
582 | // all splice operations performed through a list,
583 | // wraps the list.splice method to delegate such object
584 | // and it puts back original splice right before every invocation.
585 | // Note: do not use the same list in two different aura
586 | const aura = (splicer, list) => {
587 |   const splice = list.splice;
588 |   function $splice() {
589 |     list.splice = splice;
590 |     const result = splicer.splice.apply(splicer, arguments);
591 |     list.splice = $splice;
592 |     return result;
593 |   }
594 |   list.splice = $splice;
595 |   return list;
596 | };
597 |  
598 | // Helpers - - - - - - - - - - - - - - - - - - - - - -
599 |  
600 | // originally readapted from:
601 | // http://webreflection.blogspot.co.uk/2009/02/levenshtein-algorithm-revisited-25.html
602 | // then rewritten in C for Emscripten (see levenstein.c)
603 | // then "screw you ASM" due no much gain but very bloated code
604 | const levenstein = (from, beginIndex, fromLength, to, endRelIndex, toLength) => {
605 |   const fLength = fromLength + 1 - beginIndex + endRelIndex;
606 |   const tLength = toLength + 1 - beginIndex + endRelIndex;
607 |   const size = fLength * tLength;
608 |   const grid = new TypedArray(size);
609 |   let x = 0;
610 |   let y = 0;
611 |   let X = 0;
612 |   let Y = 0;
613 |   let crow = 0;
614 |   let prow = 0;
615 |   let del, ins, sub;
616 |   grid[0] = 0;
617 |   while (++x < tLength) grid[x] = x;
618 |   while (++y < fLength) {
619 |     X = x = 0;
620 |     prow = crow;
621 |     crow = y * tLength;
622 |     grid[crow + x] = y;
623 |     while (++x < tLength) {
624 |       del = grid[prow + x] + 1;
625 |       ins = grid[crow + X] + 1;
626 |       sub = grid[prow + X] + (from[Y + beginIndex] == to[X + beginIndex] ? 0 : 1);
627 |       grid[crow + x] = del < ins ?
628 |                         (del < sub ?
629 |                           del : sub) :
630 |                         (ins < sub ?
631 |                           ins : sub);
632 |       ++X;
633 |     };
634 |     Y = y;
635 |   }
636 |   return grid;
637 | };
638 |  
639 | // add operations (in reversed order)
640 | const addOperation = (list, type, x, y, count, items) => {
641 |   list.unshift({type, x, y, count, items});
642 | };
643 |  
644 | // walk the Levenshtein grid bottom -> up
645 | const getOperations = (grid, Y, beginIndex, YLength, X, endRelIndex, XLength) => {
646 |   const list = [];
647 |   const YL = YLength + 1 - beginIndex + endRelIndex;
648 |   const XL = XLength + 1 - beginIndex + endRelIndex;
649 |   let y = YL - 1;
650 |   let x = XL - 1;
651 |   let cell,
652 |       top, left, diagonal,
653 |       crow, prow;
654 |   while (x && y) {
655 |     crow = y * XL + x;
656 |     prow = crow - XL;
657 |     cell = grid[crow];
658 |     top = grid[prow];
659 |     left = grid[crow - 1];
660 |     diagonal = grid[prow - 1];
661 |     if (diagonal <= left && diagonal <= top && diagonal <= cell) {
662 |       x--;
663 |       y--;
664 |       if (diagonal < cell) {
665 |         addOperation(list, SUBSTITUTE, x + beginIndex, y + beginIndex, 1, [X[x + beginIndex]]);
666 |       }
667 |     }
668 |     else if (left <= top && left <= cell) {
669 |       x--;
670 |       addOperation(list, INSERT, x + beginIndex, y + beginIndex, 0, [X[x + beginIndex]]);
671 |     }
672 |     else {
673 |       y--;
674 |       addOperation(list, DELETE, x + beginIndex, y + beginIndex, 1, []);
675 |     }
676 |   }
677 |   while (x--) {
678 |     addOperation(list, INSERT, x + beginIndex, y + beginIndex, 0, [X[x + beginIndex]]);
679 |   }
680 |   while (y--) {
681 |     addOperation(list, DELETE, x + beginIndex, y + beginIndex, 1, []);
682 |   }
683 |   return list;
684 | };
685 |  
686 | /* grouped operations */
687 | const performOperations = (target, operations) => {
688 |   const length = operations.length;
689 |   let diff = 0;
690 |   let i = 1;
691 |   let curr, prev, op;
692 |   op = (prev = operations[0]);
693 |   while (i < length) {
694 |     curr = operations[i++];
695 |     if (prev.type === curr.type && (curr.x - prev.x) <= 1 && (curr.y - prev.y) <= 1) {
696 |       op.count += curr.count;
697 |       op.items = op.items.concat(curr.items);
698 |     } else {
699 |       target.splice.apply(target, [op.y + diff, op.count].concat(op.items));
700 |       diff += op.type === INSERT ?
701 |         op.items.length : (op.type === DELETE ?
702 |           -op.count : 0);
703 |       op = curr;
704 |     }
705 |     prev = curr;
706 |   }
707 |   target.splice.apply(target, [op.y + diff, op.count].concat(op.items));
708 | };
709 |  
710 | majinbuu.aura = aura;
711 |  
712 | Object.defineProperty(exports, '__esModule', {value: true}).default = majinbuu;
713 | exports.aura = aura;
714 | exports.majinbuu = majinbuu;
715 |  
717 |
718 |
719 | 723 | 724 | 725 | 732 | 733 | 734 | 735 | -------------------------------------------------------------------------------- /coverage/lcov-report/majinbuu/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for majinbuu/ 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | all files majinbuu/ 20 |

21 |
22 |
23 | 100% 24 | Statements 25 | 56/56 26 |
27 |
28 | 100% 29 | Branches 30 | 11/11 31 |
32 |
33 | 100% 34 | Functions 35 | 4/4 36 |
37 |
38 | 100% 39 | Lines 40 | 55/55 41 |
42 |
43 |
44 |
45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
FileStatementsBranchesFunctionsLines
test.js
100%56/56100%11/11100%4/4100%55/55
76 |
77 |
78 | 82 | 83 | 84 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /coverage/lcov-report/majinbuu/test.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for majinbuu/test.js 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | all files / majinbuu/ test.js 20 |

21 |
22 |
23 | 100% 24 | Statements 25 | 56/56 26 |
27 |
28 | 100% 29 | Branches 30 | 11/11 31 |
32 |
33 | 100% 34 | Functions 35 | 4/4 36 |
37 |
38 | 100% 39 | Lines 40 | 55/55 41 |
42 |
43 |
44 |
45 |

 46 | 
323 | 
1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 63 | 18 64 | 19 65 | 20 66 | 21 67 | 22 68 | 23 69 | 24 70 | 25 71 | 26 72 | 27 73 | 28 74 | 29 75 | 30 76 | 31 77 | 32 78 | 33 79 | 34 80 | 35 81 | 36 82 | 37 83 | 38 84 | 39 85 | 40 86 | 41 87 | 42 88 | 43 89 | 44 90 | 45 91 | 46 92 | 47 93 | 48 94 | 49 95 | 50 96 | 51 97 | 52 98 | 53 99 | 54 100 | 55 101 | 56 102 | 57 103 | 58 104 | 59 105 | 60 106 | 61 107 | 62 108 | 63 109 | 64 110 | 65 111 | 66 112 | 67 113 | 68 114 | 69 115 | 70 116 | 71 117 | 72 118 | 73 119 | 74 120 | 75 121 | 76 122 | 77 123 | 78 124 | 79 125 | 80 126 | 81 127 | 82 128 | 83 129 | 84 130 | 85 131 | 86 132 | 87 133 | 88 134 | 89 135 | 90 136 | 91 137 | 92 138 | 93 139 | 140 |   141 | 142 |   143 | 144 | 145 | 146 | 26× 147 | 26× 148 |   149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 |   163 |   164 |   165 | 166 |   167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 |   177 | 178 | 179 | 180 |   181 | 182 | 183 | 184 |   185 |   186 | 187 | 188 |   189 |   190 |   191 | 192 |   193 | 194 | 195 | 196 | 197 |   198 | 199 | 200 | 201 | 202 |   203 | 204 | 205 | 206 |   207 |   208 | 209 |   210 |   211 |   212 |   213 |   214 |   215 |   216 |   217 |   218 |   219 |   220 | 221 | 222 |   223 |   224 |   225 |   226 |   227 |   228 |   229 | 230 |  
var {title, assert, log} = require('tressa');
231 | var majinbuu = require('./cjs').default;
232 |  
233 | title('Majin Buu');
234 |  
235 | function test(a, b) {
236 |   var count;
237 |   function splice() {
238 |     count++;
239 |     return brr.splice.apply(arr, arguments);
240 |   }
241 |   var arr = a.split('');
242 |   var brr = b.split('');
243 |   count = 0;
244 |   arr.splice = splice;
245 |   majinbuu(arr, brr, 10);
246 |   assert(arr.join('') === brr.join(''), `\x1b[2m[${count}]\x1b[22m ${a || '<empty>'} => ${b || '<empty>'}`);
247 |   if (a !== b) {
248 |     arr = b.split('');
249 |     brr = a.split('');
250 |     count = 0;
251 |     arr.splice = splice;
252 |     majinbuu(arr, brr);
253 |     assert(arr.join('') === brr.join(''), `\x1b[2m[${count}]\x1b[22m ${b || '<empty>'} => ${a}`);
254 |   }
255 | }
256 |  
257 | let sameArray = []; majinbuu(sameArray, sameArray); //# to cover { if(from === to) return; } trivial case
258 |  
259 | test('', '');
260 | test('same', 'same');
261 | test('democrat', 'republican');
262 | test('kitten', 'sitting');
263 | test('abc', '');
264 | test('roar', 'meow');
265 | test('abra', 'cadabra');
266 | test('matrix', 'xxxmatr');
267 | test('matrix', 'matrixhasyou'); //# check that skipping of equal elements at begin works
268 |  
269 | delete global.Int32Array;
270 | delete require.cache[require.resolve('./cjs')];
271 | var majinbuu = require('./cjs').default;
272 |  
273 | log('## majinbuu.aura');
274 | var list = 'abra'.split('');
275 | var wrap = {
276 |   spliced: false,
277 |   splice: function () {
278 |     this.spliced = true;
279 |     this.result = list.splice.apply(list, arguments);
280 |   }
281 | };
282 |  
283 | var aura = majinbuu.aura(wrap, list);
284 |  
285 | majinbuu(aura, 'cadabra'.split(''));
286 | assert(wrap.spliced, 'aura invoked the wrapper instead');
287 | assert(list.join('') === 'cadabra', 'aura modified the list');
288 | assert(aura.join('') === 'cadabra', 'aura inherits list');
289 |  
290 | list = ['12'];
291 | aura = majinbuu.aura(wrap, list);
292 | majinbuu(aura, ['a', 'b']);
293 | assert(aura.join('') === 'ab', 'single to double is OK');
294 |  
295 | list = '0123456789'.split('');
296 | log('## grid limit');
297 | majinbuu(
298 |   majinbuu.aura({
299 |     splice: function (index, many) {
300 |       assert(
301 |         index === 0 &&
302 |         many === list.length &&
303 |         list.slice.call(arguments, 2).join('') === 'OK',
304 |         'max grid limit respected'
305 |       );
306 |     }
307 |   }, list),
308 |   'OK'.split(''),
309 |   3
310 | );
311 |  
312 | const abra = ['a', 'b', 'r', 'a'];
313 | majinbuu(
314 |   abra,
315 |   ['c', 'a', 'd', 'a', 'b', 'r', 'a'],
316 |   0, 1, 4,
317 |   0, 4, 7,
318 |   0
319 | );
320 |  
321 | tressa.assert(abra.join('') === 'cadabra', 'passing extra info works too');
322 |  
324 |
325 |
326 | 330 | 331 | 332 | 339 | 340 | 341 | 342 | -------------------------------------------------------------------------------- /coverage/lcov-report/prettify.css: -------------------------------------------------------------------------------- 1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} 2 | -------------------------------------------------------------------------------- /coverage/lcov-report/prettify.js: -------------------------------------------------------------------------------- 1 | window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); 2 | -------------------------------------------------------------------------------- /coverage/lcov-report/sort-arrow-sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WebReflection/majinbuu/bae5c9c41cfbe0f37aa5499cba7b5e77f958b382/coverage/lcov-report/sort-arrow-sprite.png -------------------------------------------------------------------------------- /coverage/lcov-report/sorter.js: -------------------------------------------------------------------------------- 1 | var addSorting = (function () { 2 | "use strict"; 3 | var cols, 4 | currentSort = { 5 | index: 0, 6 | desc: false 7 | }; 8 | 9 | // returns the summary table element 10 | function getTable() { return document.querySelector('.coverage-summary'); } 11 | // returns the thead element of the summary table 12 | function getTableHeader() { return getTable().querySelector('thead tr'); } 13 | // returns the tbody element of the summary table 14 | function getTableBody() { return getTable().querySelector('tbody'); } 15 | // returns the th element for nth column 16 | function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; } 17 | 18 | // loads all columns 19 | function loadColumns() { 20 | var colNodes = getTableHeader().querySelectorAll('th'), 21 | colNode, 22 | cols = [], 23 | col, 24 | i; 25 | 26 | for (i = 0; i < colNodes.length; i += 1) { 27 | colNode = colNodes[i]; 28 | col = { 29 | key: colNode.getAttribute('data-col'), 30 | sortable: !colNode.getAttribute('data-nosort'), 31 | type: colNode.getAttribute('data-type') || 'string' 32 | }; 33 | cols.push(col); 34 | if (col.sortable) { 35 | col.defaultDescSort = col.type === 'number'; 36 | colNode.innerHTML = colNode.innerHTML + ''; 37 | } 38 | } 39 | return cols; 40 | } 41 | // attaches a data attribute to every tr element with an object 42 | // of data values keyed by column name 43 | function loadRowData(tableRow) { 44 | var tableCols = tableRow.querySelectorAll('td'), 45 | colNode, 46 | col, 47 | data = {}, 48 | i, 49 | val; 50 | for (i = 0; i < tableCols.length; i += 1) { 51 | colNode = tableCols[i]; 52 | col = cols[i]; 53 | val = colNode.getAttribute('data-value'); 54 | if (col.type === 'number') { 55 | val = Number(val); 56 | } 57 | data[col.key] = val; 58 | } 59 | return data; 60 | } 61 | // loads all row data 62 | function loadData() { 63 | var rows = getTableBody().querySelectorAll('tr'), 64 | i; 65 | 66 | for (i = 0; i < rows.length; i += 1) { 67 | rows[i].data = loadRowData(rows[i]); 68 | } 69 | } 70 | // sorts the table using the data for the ith column 71 | function sortByIndex(index, desc) { 72 | var key = cols[index].key, 73 | sorter = function (a, b) { 74 | a = a.data[key]; 75 | b = b.data[key]; 76 | return a < b ? -1 : a > b ? 1 : 0; 77 | }, 78 | finalSorter = sorter, 79 | tableBody = document.querySelector('.coverage-summary tbody'), 80 | rowNodes = tableBody.querySelectorAll('tr'), 81 | rows = [], 82 | i; 83 | 84 | if (desc) { 85 | finalSorter = function (a, b) { 86 | return -1 * sorter(a, b); 87 | }; 88 | } 89 | 90 | for (i = 0; i < rowNodes.length; i += 1) { 91 | rows.push(rowNodes[i]); 92 | tableBody.removeChild(rowNodes[i]); 93 | } 94 | 95 | rows.sort(finalSorter); 96 | 97 | for (i = 0; i < rows.length; i += 1) { 98 | tableBody.appendChild(rows[i]); 99 | } 100 | } 101 | // removes sort indicators for current column being sorted 102 | function removeSortIndicators() { 103 | var col = getNthColumn(currentSort.index), 104 | cls = col.className; 105 | 106 | cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); 107 | col.className = cls; 108 | } 109 | // adds sort indicators for current column being sorted 110 | function addSortIndicators() { 111 | getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted'; 112 | } 113 | // adds event listeners for all sorter widgets 114 | function enableUI() { 115 | var i, 116 | el, 117 | ithSorter = function ithSorter(i) { 118 | var col = cols[i]; 119 | 120 | return function () { 121 | var desc = col.defaultDescSort; 122 | 123 | if (currentSort.index === i) { 124 | desc = !currentSort.desc; 125 | } 126 | sortByIndex(i, desc); 127 | removeSortIndicators(); 128 | currentSort.index = i; 129 | currentSort.desc = desc; 130 | addSortIndicators(); 131 | }; 132 | }; 133 | for (i =0 ; i < cols.length; i += 1) { 134 | if (cols[i].sortable) { 135 | // add the click event handler on the th so users 136 | // dont have to click on those tiny arrows 137 | el = getNthColumn(i).querySelector('.sorter').parentElement; 138 | if (el.addEventListener) { 139 | el.addEventListener('click', ithSorter(i)); 140 | } else { 141 | el.attachEvent('onclick', ithSorter(i)); 142 | } 143 | } 144 | } 145 | } 146 | // adds sorting functionality to the UI 147 | return function () { 148 | if (!getTable()) { 149 | return; 150 | } 151 | cols = loadColumns(); 152 | loadData(cols); 153 | addSortIndicators(); 154 | enableUI(); 155 | }; 156 | })(); 157 | 158 | window.addEventListener('load', addSorting); 159 | -------------------------------------------------------------------------------- /coverage/lcov.info: -------------------------------------------------------------------------------- 1 | TN: 2 | SF:/home/webreflection/code/majinbuu/test.js 3 | FN:6,test 4 | FN:8,splice 5 | FN:48,(anonymous_3) 6 | FN:70,(anonymous_4) 7 | FNF:4 8 | FNH:4 9 | FNDA:9,test 10 | FNDA:26,splice 11 | FNDA:3,(anonymous_3) 12 | FNDA:1,(anonymous_4) 13 | DA:1,1 14 | DA:2,1 15 | DA:4,1 16 | DA:6,1 17 | DA:7,9 18 | DA:8,1 19 | DA:9,26 20 | DA:10,26 21 | DA:12,9 22 | DA:13,9 23 | DA:14,9 24 | DA:15,9 25 | DA:16,9 26 | DA:17,9 27 | DA:18,9 28 | DA:19,7 29 | DA:20,7 30 | DA:21,7 31 | DA:22,7 32 | DA:23,7 33 | DA:24,7 34 | DA:28,1 35 | DA:30,1 36 | DA:31,1 37 | DA:32,1 38 | DA:33,1 39 | DA:34,1 40 | DA:35,1 41 | DA:36,1 42 | DA:37,1 43 | DA:38,1 44 | DA:40,1 45 | DA:41,1 46 | DA:42,1 47 | DA:44,1 48 | DA:45,1 49 | DA:46,1 50 | DA:49,3 51 | DA:50,3 52 | DA:54,1 53 | DA:56,1 54 | DA:57,1 55 | DA:58,1 56 | DA:59,1 57 | DA:61,1 58 | DA:62,1 59 | DA:63,1 60 | DA:64,1 61 | DA:66,1 62 | DA:67,1 63 | DA:68,1 64 | DA:71,1 65 | DA:83,1 66 | DA:84,1 67 | DA:92,1 68 | LF:55 69 | LH:55 70 | BRDA:17,1,0,9 71 | BRDA:17,1,1,1 72 | BRDA:17,2,0,9 73 | BRDA:17,2,1,2 74 | BRDA:18,3,0,7 75 | BRDA:18,3,1,2 76 | BRDA:24,4,0,7 77 | BRDA:24,4,1,1 78 | BRDA:72,5,0,1 79 | BRDA:72,5,1,1 80 | BRDA:72,5,2,1 81 | BRF:11 82 | BRH:11 83 | end_of_record 84 | TN: 85 | SF:/home/webreflection/code/majinbuu/cjs/index.js 86 | FN:15,(anonymous_1) 87 | FN:97,$splice 88 | FNF:2 89 | FNH:2 90 | FNDA:21,(anonymous_1) 91 | FNDA:4,$splice 92 | DA:5,2 93 | DA:6,2 94 | DA:7,2 95 | DA:10,2 96 | DA:13,2 97 | DA:15,2 98 | DA:22,21 99 | DA:24,1 100 | DA:27,20 101 | DA:28,19 102 | DA:29,19 103 | DA:30,19 104 | DA:31,19 105 | DA:32,19 106 | DA:33,19 107 | DA:34,19 108 | DA:36,1 109 | DA:39,20 110 | DA:45,20 111 | DA:46,3 112 | DA:47,2 113 | DA:49,3 114 | DA:51,17 115 | DA:52,1 116 | DA:53,1 117 | DA:55,16 118 | DA:56,16 119 | DA:57,16 120 | DA:58,16 121 | DA:60,16 122 | DA:62,1 123 | DA:67,15 124 | DA:68,15 125 | DA:69,15 126 | DA:70,15 127 | DA:74,13 128 | DA:76,15 129 | DA:95,2 130 | DA:96,3 131 | DA:97,1 132 | DA:98,4 133 | DA:99,4 134 | DA:100,4 135 | DA:101,4 136 | DA:103,3 137 | DA:104,3 138 | DA:113,2 139 | DA:114,15 140 | DA:115,15 141 | DA:116,15 142 | DA:117,15 143 | DA:118,15 144 | DA:119,15 145 | DA:120,15 146 | DA:121,15 147 | DA:122,15 148 | DA:123,15 149 | DA:124,15 150 | DA:125,15 151 | DA:126,72 152 | DA:127,15 153 | DA:128,65 154 | DA:129,65 155 | DA:130,65 156 | DA:131,65 157 | DA:132,65 158 | DA:133,380 159 | DA:134,380 160 | DA:135,380 161 | DA:136,380 162 | DA:141,380 163 | DA:143,65 164 | DA:145,15 165 | DA:149,2 166 | DA:150,66 167 | DA:154,2 168 | DA:155,15 169 | DA:156,15 170 | DA:157,15 171 | DA:158,15 172 | DA:159,15 173 | DA:160,15 174 | DA:163,15 175 | DA:164,60 176 | DA:165,60 177 | DA:166,60 178 | DA:167,60 179 | DA:168,60 180 | DA:169,60 181 | DA:170,60 182 | DA:171,48 183 | DA:172,48 184 | DA:173,48 185 | DA:174,25 186 | DA:177,12 187 | DA:178,7 188 | DA:179,7 189 | DA:182,5 190 | DA:183,5 191 | DA:186,15 192 | DA:187,17 193 | DA:189,15 194 | DA:190,12 195 | DA:192,15 196 | DA:196,2 197 | DA:197,15 198 | DA:198,15 199 | DA:199,15 200 | DA:200,15 201 | DA:201,15 202 | DA:202,15 203 | DA:203,51 204 | DA:204,51 205 | DA:205,37 206 | DA:206,37 207 | DA:208,14 208 | DA:209,14 209 | DA:212,14 210 | DA:214,51 211 | DA:216,15 212 | DA:219,2 213 | DA:221,2 214 | DA:222,2 215 | DA:223,2 216 | LF:124 217 | LH:124 218 | BRDA:10,1,0,1 219 | BRDA:10,1,1,1 220 | BRDA:22,2,0,1 221 | BRDA:22,2,1,20 222 | BRDA:27,3,0,19 223 | BRDA:27,3,1,1 224 | BRDA:28,4,0,19 225 | BRDA:28,4,1,9 226 | BRDA:36,5,0,1 227 | BRDA:36,5,1,1 228 | BRDA:39,6,0,20 229 | BRDA:39,6,1,10 230 | BRDA:41,7,0,10 231 | BRDA:41,7,1,1 232 | BRDA:42,8,0,10 233 | BRDA:42,8,1,2 234 | BRDA:45,9,0,3 235 | BRDA:45,9,1,17 236 | BRDA:45,10,0,20 237 | BRDA:45,10,1,19 238 | BRDA:46,11,0,2 239 | BRDA:46,11,1,1 240 | BRDA:46,12,0,3 241 | BRDA:46,12,1,2 242 | BRDA:51,13,0,1 243 | BRDA:51,13,1,16 244 | BRDA:57,14,0,32 245 | BRDA:57,14,1,29 246 | BRDA:60,15,0,1 247 | BRDA:60,15,1,15 248 | BRDA:60,16,0,16 249 | BRDA:60,16,1,2 250 | BRDA:71,17,0,28 251 | BRDA:71,17,1,23 252 | BRDA:135,18,0,42 253 | BRDA:135,18,1,338 254 | BRDA:136,19,0,150 255 | BRDA:136,19,1,230 256 | BRDA:137,20,0,47 257 | BRDA:137,20,1,103 258 | BRDA:139,21,0,51 259 | BRDA:139,21,1,179 260 | BRDA:163,22,0,75 261 | BRDA:163,22,1,66 262 | BRDA:170,23,0,48 263 | BRDA:170,23,1,12 264 | BRDA:170,24,0,60 265 | BRDA:170,24,1,53 266 | BRDA:170,24,2,48 267 | BRDA:173,25,0,25 268 | BRDA:173,25,1,23 269 | BRDA:177,26,0,7 270 | BRDA:177,26,1,5 271 | BRDA:177,27,0,12 272 | BRDA:177,27,1,7 273 | BRDA:204,28,0,37 274 | BRDA:204,28,1,14 275 | BRDA:204,29,0,51 276 | BRDA:204,29,1,42 277 | BRDA:204,29,2,37 278 | BRDA:209,30,0,4 279 | BRDA:209,30,1,10 280 | BRDA:210,31,0,2 281 | BRDA:210,31,1,8 282 | BRF:64 283 | BRH:64 284 | end_of_record 285 | -------------------------------------------------------------------------------- /esm/index.js: -------------------------------------------------------------------------------- 1 | /*! Copyright (c) 2017, Andrea Giammarchi, @WebReflection */ 2 | 3 | // grid operations 4 | const DELETE = 'del'; 5 | const INSERT = 'ins'; 6 | const SUBSTITUTE = 'sub'; 7 | 8 | // typed Array 9 | const TypedArray = typeof Int32Array === 'function' ? Int32Array : Array; 10 | 11 | // shortcuts 12 | const { min, sqrt } = Math; 13 | 14 | const majinbuu = function ( 15 | from, to, 16 | fromStart, fromEnd, fromLength, 17 | toStart, toEnd, toLength, 18 | SIZE 19 | ) { 20 | 21 | if(from === to) { 22 | //# same arrays. Do nothing 23 | return; 24 | } 25 | 26 | if (arguments.length < 4) { 27 | SIZE = fromStart || Infinity; 28 | fromLength = from.length; 29 | fromStart = 0; 30 | fromEnd = fromLength; 31 | toLength = to.length; 32 | toStart = 0; 33 | toEnd = toLength; 34 | } else { 35 | SIZE = SIZE || Infinity; 36 | } 37 | 38 | const TOO_MANY = SIZE !== Infinity && 39 | SIZE < sqrt( 40 | ((fromEnd - fromStart) || 1) * 41 | ((toEnd - toStart) || 1) 42 | ); 43 | 44 | if (TOO_MANY || fromLength < 1) { 45 | if (TOO_MANY || toLength) { 46 | from.splice.apply(from, [0, fromLength].concat(to)); 47 | } 48 | return; 49 | } 50 | if (toLength < 1) { 51 | from.splice(0); 52 | return; 53 | } 54 | const minLength = min(fromLength, toLength); 55 | let beginIndex = fromStart; 56 | while(beginIndex < minLength && from[beginIndex] === to[beginIndex]) { 57 | beginIndex += 1; 58 | } 59 | if(beginIndex == fromLength && fromLength == toLength) { 60 | // content of { from } and { to } are equal. Do nothing 61 | return; 62 | } 63 | else { 64 | // relative from both ends { from } and { to }. { -1 } is last element, 65 | // { -2 } is { to[to.length - 2] } and { from[fromLength - 2] } etc 66 | let endRelIndex = 0; 67 | const fromLengthMinus1 = fromEnd - 1; 68 | const toLengthMinus1 = toEnd - 1; 69 | while( 70 | beginIndex < (minLength + endRelIndex) && 71 | from[fromLengthMinus1 + endRelIndex] === to[toLengthMinus1 + endRelIndex] 72 | ) { 73 | endRelIndex--; 74 | } 75 | performOperations( 76 | from, 77 | getOperations( 78 | levenstein( 79 | from, beginIndex, fromLength, 80 | to, endRelIndex, toLength 81 | ), 82 | from, beginIndex, fromLength, 83 | to, endRelIndex, toLength 84 | ) 85 | ); 86 | } 87 | }; 88 | 89 | // given an object that would like to intercept 90 | // all splice operations performed through a list, 91 | // wraps the list.splice method to delegate such object 92 | // and it puts back original splice right before every invocation. 93 | // Note: do not use the same list in two different aura 94 | const aura = (splicer, list) => { 95 | const splice = list.splice; 96 | function $splice() { 97 | list.splice = splice; 98 | const result = splicer.splice.apply(splicer, arguments); 99 | list.splice = $splice; 100 | return result; 101 | } 102 | list.splice = $splice; 103 | return list; 104 | }; 105 | 106 | // Helpers - - - - - - - - - - - - - - - - - - - - - - 107 | 108 | // originally readapted from: 109 | // http://webreflection.blogspot.co.uk/2009/02/levenshtein-algorithm-revisited-25.html 110 | // then rewritten in C for Emscripten (see levenstein.c) 111 | // then "screw you ASM" due no much gain but very bloated code 112 | const levenstein = (from, beginIndex, fromLength, to, endRelIndex, toLength) => { 113 | const fLength = fromLength + 1 - beginIndex + endRelIndex; 114 | const tLength = toLength + 1 - beginIndex + endRelIndex; 115 | const size = fLength * tLength; 116 | const grid = new TypedArray(size); 117 | let x = 0; 118 | let y = 0; 119 | let X = 0; 120 | let Y = 0; 121 | let crow = 0; 122 | let prow = 0; 123 | let del, ins, sub; 124 | grid[0] = 0; 125 | while (++x < tLength) grid[x] = x; 126 | while (++y < fLength) { 127 | X = x = 0; 128 | prow = crow; 129 | crow = y * tLength; 130 | grid[crow + x] = y; 131 | while (++x < tLength) { 132 | del = grid[prow + x] + 1; 133 | ins = grid[crow + X] + 1; 134 | sub = grid[prow + X] + (from[Y + beginIndex] == to[X + beginIndex] ? 0 : 1); 135 | grid[crow + x] = del < ins ? 136 | (del < sub ? 137 | del : sub) : 138 | (ins < sub ? 139 | ins : sub); 140 | ++X; 141 | }; 142 | Y = y; 143 | } 144 | return grid; 145 | }; 146 | 147 | // add operations (in reversed order) 148 | const addOperation = (list, type, x, y, count, items) => { 149 | list.unshift({type, x, y, count, items}); 150 | }; 151 | 152 | // walk the Levenshtein grid bottom -> up 153 | const getOperations = (grid, Y, beginIndex, YLength, X, endRelIndex, XLength) => { 154 | const list = []; 155 | const YL = YLength + 1 - beginIndex + endRelIndex; 156 | const XL = XLength + 1 - beginIndex + endRelIndex; 157 | let y = YL - 1; 158 | let x = XL - 1; 159 | let cell, 160 | top, left, diagonal, 161 | crow, prow; 162 | while (x && y) { 163 | crow = y * XL + x; 164 | prow = crow - XL; 165 | cell = grid[crow]; 166 | top = grid[prow]; 167 | left = grid[crow - 1]; 168 | diagonal = grid[prow - 1]; 169 | if (diagonal <= left && diagonal <= top && diagonal <= cell) { 170 | x--; 171 | y--; 172 | if (diagonal < cell) { 173 | addOperation(list, SUBSTITUTE, x + beginIndex, y + beginIndex, 1, [X[x + beginIndex]]); 174 | } 175 | } 176 | else if (left <= top && left <= cell) { 177 | x--; 178 | addOperation(list, INSERT, x + beginIndex, y + beginIndex, 0, [X[x + beginIndex]]); 179 | } 180 | else { 181 | y--; 182 | addOperation(list, DELETE, x + beginIndex, y + beginIndex, 1, []); 183 | } 184 | } 185 | while (x--) { 186 | addOperation(list, INSERT, x + beginIndex, y + beginIndex, 0, [X[x + beginIndex]]); 187 | } 188 | while (y--) { 189 | addOperation(list, DELETE, x + beginIndex, y + beginIndex, 1, []); 190 | } 191 | return list; 192 | }; 193 | 194 | /* grouped operations */ 195 | const performOperations = (target, operations) => { 196 | const length = operations.length; 197 | let diff = 0; 198 | let i = 1; 199 | let curr, prev, op; 200 | op = (prev = operations[0]); 201 | while (i < length) { 202 | curr = operations[i++]; 203 | if (prev.type === curr.type && (curr.x - prev.x) <= 1 && (curr.y - prev.y) <= 1) { 204 | op.count += curr.count; 205 | op.items = op.items.concat(curr.items); 206 | } else { 207 | target.splice.apply(target, [op.y + diff, op.count].concat(op.items)); 208 | diff += op.type === INSERT ? 209 | op.items.length : (op.type === DELETE ? 210 | -op.count : 0); 211 | op = curr; 212 | } 213 | prev = curr; 214 | } 215 | target.splice.apply(target, [op.y + diff, op.count].concat(op.items)); 216 | }; 217 | 218 | majinbuu.aura = aura; 219 | 220 | export default majinbuu; 221 | export {aura, majinbuu}; 222 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var majinbuu = function (cache, modules) { 2 | function require(i) { 3 | return cache[i] || get(i); 4 | } 5 | function get(i) { 6 | var exports = {}, 7 | module = { exports: exports }; 8 | modules[i].call(exports, window, require, module, exports); 9 | return cache[i] = module.exports; 10 | } 11 | require.E = function (exports) { 12 | return Object.defineProperty(exports, '__esModule', { value: true }); 13 | }; 14 | var main = require(0); 15 | return main.__esModule ? main.default : main; 16 | }([], [function (global, require, module, exports) { 17 | // index.js 18 | 'use strict'; 19 | /*! Copyright (c) 2017, Andrea Giammarchi, @WebReflection */ 20 | 21 | // grid operations 22 | 23 | var DELETE = 'del'; 24 | var INSERT = 'ins'; 25 | var SUBSTITUTE = 'sub'; 26 | 27 | // typed Array 28 | var TypedArray = typeof Int32Array === 'function' ? Int32Array : Array; 29 | 30 | // shortcuts 31 | var min = Math.min, 32 | sqrt = Math.sqrt; 33 | 34 | 35 | var majinbuu = function majinbuu(from, to, fromStart, fromEnd, fromLength, toStart, toEnd, toLength, SIZE) { 36 | 37 | if (from === to) { 38 | //# same arrays. Do nothing 39 | return; 40 | } 41 | 42 | if (arguments.length < 4) { 43 | SIZE = fromStart || Infinity; 44 | fromLength = from.length; 45 | fromStart = 0; 46 | fromEnd = fromLength; 47 | toLength = to.length; 48 | toStart = 0; 49 | toEnd = toLength; 50 | } else { 51 | SIZE = SIZE || Infinity; 52 | } 53 | 54 | var TOO_MANY = SIZE !== Infinity && SIZE < sqrt((fromEnd - fromStart || 1) * (toEnd - toStart || 1)); 55 | 56 | if (TOO_MANY || fromLength < 1) { 57 | if (TOO_MANY || toLength) { 58 | from.splice.apply(from, [0, fromLength].concat(to)); 59 | } 60 | return; 61 | } 62 | if (toLength < 1) { 63 | from.splice(0); 64 | return; 65 | } 66 | var minLength = min(fromLength, toLength); 67 | var beginIndex = fromStart; 68 | while (beginIndex < minLength && from[beginIndex] === to[beginIndex]) { 69 | beginIndex += 1; 70 | } 71 | if (beginIndex == fromLength && fromLength == toLength) { 72 | // content of { from } and { to } are equal. Do nothing 73 | return; 74 | } else { 75 | // relative from both ends { from } and { to }. { -1 } is last element, 76 | // { -2 } is { to[to.length - 2] } and { from[fromLength - 2] } etc 77 | var endRelIndex = 0; 78 | var fromLengthMinus1 = fromEnd - 1; 79 | var toLengthMinus1 = toEnd - 1; 80 | while (beginIndex < minLength + endRelIndex && from[fromLengthMinus1 + endRelIndex] === to[toLengthMinus1 + endRelIndex]) { 81 | endRelIndex--; 82 | } 83 | performOperations(from, getOperations(levenstein(from, beginIndex, fromLength, to, endRelIndex, toLength), from, beginIndex, fromLength, to, endRelIndex, toLength)); 84 | } 85 | }; 86 | 87 | // given an object that would like to intercept 88 | // all splice operations performed through a list, 89 | // wraps the list.splice method to delegate such object 90 | // and it puts back original splice right before every invocation. 91 | // Note: do not use the same list in two different aura 92 | var aura = function aura(splicer, list) { 93 | var splice = list.splice; 94 | function $splice() { 95 | list.splice = splice; 96 | var result = splicer.splice.apply(splicer, arguments); 97 | list.splice = $splice; 98 | return result; 99 | } 100 | list.splice = $splice; 101 | return list; 102 | }; 103 | 104 | // Helpers - - - - - - - - - - - - - - - - - - - - - - 105 | 106 | // originally readapted from: 107 | // http://webreflection.blogspot.co.uk/2009/02/levenshtein-algorithm-revisited-25.html 108 | // then rewritten in C for Emscripten (see levenstein.c) 109 | // then "screw you ASM" due no much gain but very bloated code 110 | var levenstein = function levenstein(from, beginIndex, fromLength, to, endRelIndex, toLength) { 111 | var fLength = fromLength + 1 - beginIndex + endRelIndex; 112 | var tLength = toLength + 1 - beginIndex + endRelIndex; 113 | var size = fLength * tLength; 114 | var grid = new TypedArray(size); 115 | var x = 0; 116 | var y = 0; 117 | var X = 0; 118 | var Y = 0; 119 | var crow = 0; 120 | var prow = 0; 121 | var del = void 0, 122 | ins = void 0, 123 | sub = void 0; 124 | grid[0] = 0; 125 | while (++x < tLength) { 126 | grid[x] = x; 127 | }while (++y < fLength) { 128 | X = x = 0; 129 | prow = crow; 130 | crow = y * tLength; 131 | grid[crow + x] = y; 132 | while (++x < tLength) { 133 | del = grid[prow + x] + 1; 134 | ins = grid[crow + X] + 1; 135 | sub = grid[prow + X] + (from[Y + beginIndex] == to[X + beginIndex] ? 0 : 1); 136 | grid[crow + x] = del < ins ? del < sub ? del : sub : ins < sub ? ins : sub; 137 | ++X; 138 | }; 139 | Y = y; 140 | } 141 | return grid; 142 | }; 143 | 144 | // add operations (in reversed order) 145 | var addOperation = function addOperation(list, type, x, y, count, items) { 146 | list.unshift({ type: type, x: x, y: y, count: count, items: items }); 147 | }; 148 | 149 | // walk the Levenshtein grid bottom -> up 150 | var getOperations = function getOperations(grid, Y, beginIndex, YLength, X, endRelIndex, XLength) { 151 | var list = []; 152 | var YL = YLength + 1 - beginIndex + endRelIndex; 153 | var XL = XLength + 1 - beginIndex + endRelIndex; 154 | var y = YL - 1; 155 | var x = XL - 1; 156 | var cell = void 0, 157 | top = void 0, 158 | left = void 0, 159 | diagonal = void 0, 160 | crow = void 0, 161 | prow = void 0; 162 | while (x && y) { 163 | crow = y * XL + x; 164 | prow = crow - XL; 165 | cell = grid[crow]; 166 | top = grid[prow]; 167 | left = grid[crow - 1]; 168 | diagonal = grid[prow - 1]; 169 | if (diagonal <= left && diagonal <= top && diagonal <= cell) { 170 | x--; 171 | y--; 172 | if (diagonal < cell) { 173 | addOperation(list, SUBSTITUTE, x + beginIndex, y + beginIndex, 1, [X[x + beginIndex]]); 174 | } 175 | } else if (left <= top && left <= cell) { 176 | x--; 177 | addOperation(list, INSERT, x + beginIndex, y + beginIndex, 0, [X[x + beginIndex]]); 178 | } else { 179 | y--; 180 | addOperation(list, DELETE, x + beginIndex, y + beginIndex, 1, []); 181 | } 182 | } 183 | while (x--) { 184 | addOperation(list, INSERT, x + beginIndex, y + beginIndex, 0, [X[x + beginIndex]]); 185 | } 186 | while (y--) { 187 | addOperation(list, DELETE, x + beginIndex, y + beginIndex, 1, []); 188 | } 189 | return list; 190 | }; 191 | 192 | /* grouped operations */ 193 | var performOperations = function performOperations(target, operations) { 194 | var length = operations.length; 195 | var diff = 0; 196 | var i = 1; 197 | var curr = void 0, 198 | prev = void 0, 199 | op = void 0; 200 | op = prev = operations[0]; 201 | while (i < length) { 202 | curr = operations[i++]; 203 | if (prev.type === curr.type && curr.x - prev.x <= 1 && curr.y - prev.y <= 1) { 204 | op.count += curr.count; 205 | op.items = op.items.concat(curr.items); 206 | } else { 207 | target.splice.apply(target, [op.y + diff, op.count].concat(op.items)); 208 | diff += op.type === INSERT ? op.items.length : op.type === DELETE ? -op.count : 0; 209 | op = curr; 210 | } 211 | prev = curr; 212 | } 213 | target.splice.apply(target, [op.y + diff, op.count].concat(op.items)); 214 | }; 215 | 216 | majinbuu.aura = aura; 217 | 218 | require.E(exports).default = majinbuu; 219 | exports.aura = aura; 220 | exports.majinbuu = majinbuu; 221 | }]); 222 | -------------------------------------------------------------------------------- /levenstein.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /*! Copyright (c) 2017, Andrea Giammarchi, @WebReflection */ 6 | 7 | int *levenstein(char *from, char *to) { 8 | int fromLength = strlen(from) + 1; 9 | int toLength = strlen(to) + 1; 10 | int size = fromLength * toLength; 11 | int x = 0; 12 | int y = 0; 13 | int X = 0; 14 | int Y = 0; 15 | int crow = 0; 16 | int prow = 0; 17 | int del, ins, sub; 18 | int *grid = malloc(sizeof(int) * size); 19 | grid[0] = 0; 20 | while (++x < toLength) grid[x] = x; 21 | while (++y < fromLength) { 22 | X = x = 0; 23 | prow = crow; 24 | crow = y * toLength; 25 | grid[crow + x] = y; 26 | while (++x < toLength) { 27 | del = grid[prow + x] + 1; 28 | ins = grid[crow + X] + 1; 29 | sub = grid[prow + X] + (from[Y] == to[X] ? 0 : 1); 30 | grid[crow + x] = del < ins ? 31 | (del < sub ? 32 | del : sub) : 33 | (ins < sub ? 34 | ins : sub); 35 | ++X; 36 | }; 37 | Y = y; 38 | } 39 | return grid; 40 | } 41 | 42 | int main(int argc, char *argv[]) 43 | { 44 | if (argc == 3) { 45 | int *result = levenstein(argv[1], argv[2]); 46 | int size = (strlen(argv[1]) + 1) * (strlen(argv[2]) + 1); 47 | printf("%i\n", result[size - 1]); 48 | } 49 | } -------------------------------------------------------------------------------- /min.js: -------------------------------------------------------------------------------- 1 | var majinbuu=function(t,n){function e(n){return t[n]||i(n)}function i(i){var o={},r={exports:o};return n[i].call(o,window,e,r,o),t[i]=r.exports}e.E=function(t){return Object.defineProperty(t,"__esModule",{value:!0})};var o=e(0);return o.__esModule?o.default:o}([],[function(t,n,e,i){"use strict";/*! Copyright (c) 2017, Andrea Giammarchi, @WebReflection */ 2 | var o="function"==typeof Int32Array?Int32Array:Array,r=Math.min,u=Math.sqrt,c=function(t,n,e,i,o,c,a,l,v){if(t!==n){arguments.length<4?(v=e||1/0,e=0,i=o=t.length,c=0,a=l=n.length):v=v||1/0;var d=v!==1/0&&v'} => ${b || ''}`); 18 | if (a !== b) { 19 | arr = b.split(''); 20 | brr = a.split(''); 21 | count = 0; 22 | arr.splice = splice; 23 | majinbuu(arr, brr); 24 | assert(arr.join('') === brr.join(''), `\x1b[2m[${count}]\x1b[22m ${b || ''} => ${a}`); 25 | } 26 | } 27 | 28 | let sameArray = []; majinbuu(sameArray, sameArray); //# to cover { if(from === to) return; } trivial case 29 | 30 | test('', ''); 31 | test('same', 'same'); 32 | test('democrat', 'republican'); 33 | test('kitten', 'sitting'); 34 | test('abc', ''); 35 | test('roar', 'meow'); 36 | test('abra', 'cadabra'); 37 | test('matrix', 'xxxmatr'); 38 | test('matrix', 'matrixhasyou'); //# check that skipping of equal elements at begin works 39 | 40 | delete global.Int32Array; 41 | delete require.cache[require.resolve('./cjs')]; 42 | var majinbuu = require('./cjs').default; 43 | 44 | log('## majinbuu.aura'); 45 | var list = 'abra'.split(''); 46 | var wrap = { 47 | spliced: false, 48 | splice: function () { 49 | this.spliced = true; 50 | this.result = list.splice.apply(list, arguments); 51 | } 52 | }; 53 | 54 | var aura = majinbuu.aura(wrap, list); 55 | 56 | majinbuu(aura, 'cadabra'.split('')); 57 | assert(wrap.spliced, 'aura invoked the wrapper instead'); 58 | assert(list.join('') === 'cadabra', 'aura modified the list'); 59 | assert(aura.join('') === 'cadabra', 'aura inherits list'); 60 | 61 | list = ['12']; 62 | aura = majinbuu.aura(wrap, list); 63 | majinbuu(aura, ['a', 'b']); 64 | assert(aura.join('') === 'ab', 'single to double is OK'); 65 | 66 | list = '0123456789'.split(''); 67 | log('## grid limit'); 68 | majinbuu( 69 | majinbuu.aura({ 70 | splice: function (index, many) { 71 | assert( 72 | index === 0 && 73 | many === list.length && 74 | list.slice.call(arguments, 2).join('') === 'OK', 75 | 'max grid limit respected' 76 | ); 77 | } 78 | }, list), 79 | 'OK'.split(''), 80 | 3 81 | ); 82 | 83 | const abra = ['a', 'b', 'r', 'a']; 84 | majinbuu( 85 | abra, 86 | ['c', 'a', 'd', 'a', 'b', 'r', 'a'], 87 | 0, 1, 4, 88 | 0, 4, 7, 89 | 0 90 | ); 91 | 92 | tressa.assert(abra.join('') === 'cadabra', 'passing extra info works too'); 93 | --------------------------------------------------------------------------------