MCPcopy Create free account
hub / github.com/BloombergGraphics/whatiscode / diffToWords

Function diffToWords

modules/text-diff/text-diff.js:15–54  ·  view source on GitHub ↗
(diff)

Source from the content-addressed store, hash-verified

13 var puncuation = '.-,)’'.split('')
14
15 function diffToWords(diff){
16 var rv = []
17 diff.forEach(function(obj, i){
18 obj.value.split(' ').forEach(function(chr, j, array){
19 var lastChar = ' '
20 var nextChar = ''; k = 1
21 // TODO fix spacing on evolve
22
23 if (j == array.length - 1){
24 nextChar = diff[i + k] ? diff[i + k].value[0] : ''
25 while(diff[i + k] && (diff[i + k].removed || diff[i + k].added)){
26 k++
27 nextChar = diff[i + k] ? diff[i + k].value[0] : ''
28 }
29 }
30 if (nextChar){
31 lastChar = _.contains(puncuation, nextChar) ? '' : ' '
32 }
33 rv.push({
34 value: chr + lastChar,
35 added: obj.added,
36 removed: obj.removed,
37 width: obj.width,
38 obj: obj
39 })
40 })
41 })
42
43 d3.select('#width-calc').html('').append('div')
44 .style('width', '100000px')
45 .style('margin-top', '10px')
46 .dataAppend(rv, 'div').append('div')
47 .text(ƒ('value'))
48 .each(function(d){
49 d.width = this.getBoundingClientRect().width
50 d.width = d.width + (_.last(d.value) == ' ' ? 4 : 0) + 'px'
51 })
52
53 return rv
54 }
55
56
57 var s = 1

Callers 1

updateFallingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected