0.0.2 • Published 8 months ago

string-line v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

string-line

用于处理字符串增减内容,非常轻量!

安装

npm i string-line

使用

import sl from 'string-line'

// 初始化 diff 函数
const diff = sl(`
  hello world!
`)

// 传入新的字符串
console.log(diff(`
  你好世界!
`))
// 输出
/*
  {
    subs: ['hello world!'],
    adds: ['你好世界!']
  }
*/

参数

string-line 默认将 \n 作为分隔符,你可以传入其它正则表达式作为分隔符

import sl from 'string-line'

// 初始化 diff 函数
const diff = sl('hello world!', /\s/)

// 传入新的字符串
console.log(diff('hello')
// 输出
/*
  {
    subs: ['world!'],
    adds: []
  }
*/

为什么不是 diff

事实上 string-linediff 应用的范围、甚至返回的格式不一样,diff 可以用于 objectarray 等各种类型的比较,string-line 只适用于字符串,因此不能将两者混为一谈。

0.0.2

8 months ago

0.0.1

8 months ago

0.0.0

8 months ago