Comparing version 2.0.1 to 2.0.2
{ | ||
"name": "smartwrap", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Textwrap for javascript/nodejs. Correctly handles wide characters (宽字符) and emojis (😃). Wraps strings with option to break on words.", | ||
@@ -26,3 +26,3 @@ "main": "src/main.js", | ||
"author": "tecfu", | ||
"license": "GPL-2.0", | ||
"license": "MIT", | ||
"dependencies": { | ||
@@ -29,0 +29,0 @@ "array.prototype.flat": "^1.2.3", |
@@ -111,3 +111,3 @@ # smartwrap | ||
[GPL 2.0](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html) | ||
[MIT](https://opensource.org/licenses/MIT) | ||
@@ -1,20 +0,78 @@ | ||
let smartwrap = require("../") | ||
let chalk = require("chalk") | ||
// iterate array pointer in both arrays to first matching element | ||
// savedArr: remove and copy all elements (e0) preceding match | ||
// processedArr: insert (e0) before pointer | ||
// repeat | ||
// | ||
// if savedArr has elements remaining after loop complete, append to processedArr | ||
let string = `The use of the secure-rm CLI is deprecated. | ||
Migrate over -> secure-rm-cli. Run: | ||
const ANSIRegexp = [ | ||
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', | ||
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))' | ||
].join('|'); | ||
const ANSICloseRegexp = new RegExp(`\\u001b\\[0m`) | ||
npm un secure-rm -g | ||
npm i secure-rm-cli -g` | ||
let processedArr = ["r", "e", "\n", "d"] | ||
// let savedArr = [ | ||
// "\033[34m", "r", "\033[0m", | ||
// "\033[34m", "e", "\033[0m", | ||
// "\033[34m", "d", "\033[0m", | ||
// ] | ||
let text = "\033[34mr\033[0m\033[34me\033[0m\033[34md\033[0m" | ||
console.log(text.length) | ||
let string2 = "The use of the secure-rm CLI is deprecated.\nMigrate over -> secure-rm-cli. Run:\nnpm un secure-rm -g\nnpm i secure-rm-cli -g" | ||
let escapedRegex = new RegExp(ANSIRegexp, "g") | ||
string = chalk['yellow'](string) | ||
const outstring = smartwrap(string, { | ||
minWidth: 1, | ||
trim: true, | ||
width: 70 | ||
}) | ||
// get string positions for matches | ||
let matches = [] | ||
while((result = escapedRegex.exec(text)) !== null) { | ||
matches.push({ | ||
start: result.index, | ||
end: result.index + result[0].length, | ||
match: result[0] | ||
}) | ||
} | ||
console.log(outstring) | ||
// add start and end positions for non matches | ||
matches = matches.reduce((prev, curr) => { | ||
// check if space exists between this and last match | ||
// get end of previous match | ||
let prevEnd = prev[prev.length -1] | ||
if (prevEnd.end < curr.start) { | ||
prev.push({ start: prevEnd.end, end: curr.start }, curr) | ||
} | ||
else { | ||
prev.push(curr) | ||
} | ||
return prev | ||
},[{start:0, end:0}]) | ||
.splice(1) // removes starting accumulator object | ||
// get regex pattern for each split point | ||
let splitStr = matches.map( value => `(.{${value.end - value.start}})` ) | ||
.join('') | ||
// now we have an array of all ansi escaped and non-ansi escaped strings | ||
let savedArr = new RegExp(`^${splitStr}`).exec(text).splice(1) | ||
let restoredANSI = processedArr.map((char) => { | ||
if (char === '\n') return char | ||
let splicePoint = savedArr.findIndex(element => element === char) + 1 | ||
let result = savedArr.splice(0, splicePoint) | ||
// add all consecutive closing tags | ||
while (ANSICloseRegexp.test(savedArr[0])){ | ||
result.push(savedArr.shift()) | ||
} | ||
return result.join("") | ||
}).concat(savedArr) | ||
console.log(restoredANSI) | ||
console.log(restoredANSI.join("")) | ||
// // return immediately if is a closing tag, so no linebreaks in front | ||
// if (ANSICloseRegexp.test(char)) return char |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
20
0
100
664
35716