1.0.1 • Published 3 years ago

diff-encrypt v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
3 years ago

diff-encrypt

diff-encrypt 使用diff算法,对文本等加密和还原,用于文档提交等,目标已存在旧副本的情况。

NPM

npm install diff-encrypt --save

yarn add diff-encrypt

DMEO

import {
  // 加密
  endiff,
  // 解密 
  dediff,
  // 所有换行符修改为\n 
  ignoreFeedLine
} from 'diff-encrypt';

const oldText = `// 旧的数据有中文;
const getNotword = (src: string, dist: string): string => {
  // 查找notword, 找出都不包含的字符串
  const srcDist = src + dist;
  const notword = config.notwords.find((v: string) => {
    return srcDist.indexOf(v) === -1;
  });
  return notword;
};`;

const newText = `// delete all chinese words;
const getNotword = (src: string, dist: string): string => {
  //
  const srcDist = src + dist;
  const notword = config.notwords.find((v: string) => {
    return srcDist.indexOf(v) === -1;
  });
  return notword;
};`;

const diffResult = endiff(oldText, newText);
const originStr = dediff(oldText, diffResult.result);
// α10α65α97α150αα// delete all chinese words;α;
console.log(diffResult.result);
// true 17.62
console.log(originStr.result === ignoreFeedLine(newText), diffResult.compressibility);

TEST

node ./diff_demo.js