本文整理汇总了TypeScript中diff.diffChars函数的典型用法代码示例。如果您正苦于以下问题:TypeScript diffChars函数的具体用法?TypeScript diffChars怎么用?TypeScript diffChars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了diffChars函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: encodeDiff
export function encodeDiff(orig: string, modified: string): string {
let diff = "";
if (orig !== modified) {
const results = diffChars(modified, orig);
const last = results[results.length - 1];
for (let ix = 0; ix < results.length; ++ix) {
const result = results[ix];
if (result.added === true) {
diff += `p${stringToCodeSequence(result.value)}`;
}
else if (result.removed === true) {
const next = results[ix + 1];
if ((next !== undefined && next.added === true) &&
(result.value.toUpperCase() === next.value)) {
diff += `u${result.value.length}`;
ix++;
}
else {
diff += `m${result.value.length}`;
}
}
else {
// We don't output this if it is last, as it is implied.
if (result !== last) {
diff += `g${result.value.length}`;
}
}
}
}
return diff;
}
开发者ID:lddubeau,项目名称:wed,代码行数:32,代码来源:util.ts
示例2: pad
res.diffSet.forEach((entry) => {
var state = {
'equal' : '==',
'left' : '->',
'right' : '<-',
'distinct' : '<>'
}[entry.state];
var name1 = entry.name1 ? entry.name1 : '';
var name2 = entry.name2 ? entry.name2 : '';
var space = ' ';
console.log(' - ' + pad(space, name1 + '(' + entry.type1.cyan + ') ', true)
+ state + ' ' + pad(space, name2 + '(' + entry.type2.cyan + ')', true));
if (entry.state === 'distinct') {
var diff = jsdiff.diffChars(
io.readFileSync(path.join(entry.path1, entry.name1)),
io.readFileSync(path.join(entry.path2, entry.name2)));
diff.forEach(function(part) {
var color = part.added
? 'green'
: part.removed
? 'red'
: 'magenta';
process.stderr.write(part.value[color]);
});
}
});
开发者ID:AsherBarak,项目名称:tsd,代码行数:28,代码来源:cases-spec.ts
示例3: diff
protected diff(text: string, other: string, before: string = '', after: string = '') {
const diff = jsdiff.diffChars(text, other);
let out: string[] = [];
diff.forEach(function(part){
let color = part.added ? 'green' : part.removed ? 'red' : 'black';
out.push(part.value[color]);
});
return before['black'] + out.join('') + after['black'];
}
开发者ID:kerbyfc,项目名称:cucumber-tsflow-suite,代码行数:9,代码来源:stepset.ts
示例4: getWrappingLines
//print string diff with indent and wrapping
public getWrappingLines(actual:string, expected:string, maxWidth:number, rowPadLength:number, padFirst:string[], leadSymbols:boolean = false):string {
var changes:StringDiffChange[] = stringDiff.diffChars(expected, actual);
var escape = unfunk.escape;
var style = this.diff.style;
var sep = '\n';
// should not happen
if (changes.length === 0) {
return [
padFirst[0],
padFirst[1] + style.warning('<no diff data>'),
padFirst[1]
].join(sep);
}
// checked if string has no whitespace or other fancy characters
// RegExp should also pick up empty strings
var isSimple:boolean = (unfunk.identAnyExp.test(actual) && unfunk.identAnyExp.test(expected));
var delim:string = (isSimple ? '' : '"');
var delimEmpty = repeatStr(' ', delim.length);
// accumulate the 3 rows
var top = padFirst[0];
var middle = padFirst[1];
var bottom = padFirst[2];
// accumulate styles center
var buffer = '';
// sometimes first set of rows has symbols
if (leadSymbols) {
top += style.error(this.diff.markRemov);
middle += style.plain(this.diff.markEmpty);
bottom += style.success(this.diff.markAdded);
rowPadLength += this.diff.markAdded.length;
}
// sanity check if we don't break availible space
var dataLength = maxWidth - rowPadLength;
if (rowPadLength + delim.length * 2 >= maxWidth) {
return '<no space for padded diff: "' + (rowPadLength + ' >= ' + maxWidth) + '">';
}
var rowPad = repeatStr(' ', rowPadLength);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var blocks = [];
var charSame = '|';
var charAdded = '+';
var charMissing = '-';
var charCounter = 0;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// append wrapping quotes
function delimLine() {
top += delimEmpty;
middle += delim;
bottom += delimEmpty;
}
delimLine();
// concat accumulated lined and add to block buffer
function flushLine() {
// close open lines
flushStyle();
delimLine();
blocks.push(top + sep + middle + sep + bottom);
// prepare new
top = rowPad;
middle = rowPad;
bottom = rowPad;
charCounter = 0;
delimLine();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//TODO swap style/row accumulators with some kind of statemachine (not worth it
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function appendAdd(value) {
for (var i = 0; i < value.length; i++) {
top += ' ';
buffer += charAdded;
}
bottom += value;
}
function flushAdd() {
if (buffer.length > 0) {
middle += style.success(buffer);
//.........这里部分代码省略.........
开发者ID:Bartvds,项目名称:unfunk-diff,代码行数:101,代码来源:string.ts
示例5: examineChanges
import * as diff from 'diff';
const one = 'beep boop';
const other = 'beep boob blah';
let changes = diff.diffChars(one, other);
examineChanges(changes);
// $ExpectType void
diff.diffChars(one, other, {
callback: (err, value) => {
err; // $ExpectType undefined
value; // $ExpectType Change[] | undefined
},
});
// $ExpectType void
diff.diffChars(one, other, (err, value) => {
err; // $ExpectType undefined
value; // $ExpectType Change[] | undefined
});
const diffArraysResult = diff.diffArrays(['a', 'b', 'c'], ['a', 'c', 'd']);
diffArraysResult.forEach(result => {
result.added; // $ExpectType boolean | undefined
result.removed; // $ExpectType boolean | undefined
result.value; // $ExpectType string[]
result.count; // $ExpectType number | undefined
});
interface DiffObj {
value: number;
开发者ID:frankwallis,项目名称:DefinitelyTyped,代码行数:31,代码来源:diff-tests.ts
注:本文中的diff.diffChars函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论