Giter Club home page Giter Club logo

frontenddiffhelper's Introduction

纯JavaScript代码实现文本比较工具

release

文件简析

  • index.html 为一个完整的js文本比较工具。
  • main.js 为改进版本,可以直接引用

Usage

const doCompare = require('array-differ');
let arr1 = [ 'let b=2;' , 'let a=2;' , 'let c=1;' , 'let d=2;'];
let arr2 = [ 'let a=2;' , 'let b=2;' , 'let c=3;' , 'let d=2;' , 'let e=2;' , 'let f=3;'];

doCompare(arr1, arr2);
//=> { 
	LeftObj:{ 
			delete: [ true, false, false, false, false ],
	     		modify: [ false, false, true, false, false ],
	     		empty: [ false, false, false, true, false ],
	     		code: [ 'let b=2;', 'let a=2;', 'let c=1;', ' \n', 'let d=2;' ] 
	     	},
  	RightObj:{
			add: [ false, false, false, true, false, true, true ],
	     		modify: [ false, false, true, false, false, false, false ],
	     		empty: [ true, false, false, false, false ],
	     		code:[ ' \n','let a=2;','let b=2;','let c=3;','let d=2;','let e=2;','let f=3;' ] 
		 } 
	  }

说明

函数最终会返回一个对象,里面包含了三种状态 新增项 删除项 修改项
然后你状态渲染到页面
看看截图就明白了

示例

License

MIT © TonyDong

frontenddiffhelper's People

Contributors

tonydx avatar

Watchers

Hello Chen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.