summaryrefslogtreecommitdiff
path: root/node_modules/printable-characters/printable-characters.js
diff options
context:
space:
mode:
authorakiyamn2023-09-24 23:22:21 +1000
committerakiyamn2023-09-24 23:22:21 +1000
commit4e87195739f2a5d9a05451b48773c8afdc680765 (patch)
tree9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/printable-characters/printable-characters.js
downloadprice-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz
price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'node_modules/printable-characters/printable-characters.js')
-rw-r--r--node_modules/printable-characters/printable-characters.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/node_modules/printable-characters/printable-characters.js b/node_modules/printable-characters/printable-characters.js
new file mode 100644
index 0000000..4478d36
--- /dev/null
+++ b/node_modules/printable-characters/printable-characters.js
@@ -0,0 +1,44 @@
+"use strict";
+
+const ansiEscapeCode = '[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]'
+ , zeroWidthCharacterExceptNewline = '\u0000-\u0008\u000B-\u0019\u001b\u009b\u00ad\u200b\u2028\u2029\ufeff\ufe00-\ufe0f'
+ , zeroWidthCharacter = '\n' + zeroWidthCharacterExceptNewline
+ , zeroWidthCharactersExceptNewline = new RegExp ('(?:' + ansiEscapeCode + ')|[' + zeroWidthCharacterExceptNewline + ']', 'g')
+ , zeroWidthCharacters = new RegExp ('(?:' + ansiEscapeCode + ')|[' + zeroWidthCharacter + ']', 'g')
+ , partition = new RegExp ('((?:' + ansiEscapeCode + ')|[\t' + zeroWidthCharacter + '])?([^\t' + zeroWidthCharacter + ']*)', 'g')
+
+module.exports = {
+
+ zeroWidthCharacters,
+
+ ansiEscapeCodes: new RegExp (ansiEscapeCode, 'g'),
+
+ strlen: s => Array.from (s.replace (zeroWidthCharacters, '')).length, // Array.from solves the emoji problem as described here: http://blog.jonnew.com/posts/poo-dot-length-equals-two
+
+ isBlank: s => s.replace (zeroWidthCharacters, '')
+ .replace (/\s/g, '')
+ .length === 0,
+
+ blank: s => Array.from (s.replace (zeroWidthCharactersExceptNewline, '')) // Array.from solves the emoji problem as described here: http://blog.jonnew.com/posts/poo-dot-length-equals-two
+ .map (x => ((x === '\t') || (x === '\n')) ? x : ' ')
+ .join (''),
+
+ partition (s) {
+ for (var m, spans = []; (partition.lastIndex !== s.length) && (m = partition.exec (s));) { spans.push ([m[1] || '', m[2]]) }
+ partition.lastIndex = 0 // reset
+ return spans
+ },
+
+ first (s, n) {
+
+ let result = '', length = 0
+
+ for (const [nonPrintable, printable] of module.exports.partition (s)) {
+ const text = Array.from (printable).slice (0, n - length) // Array.from solves the emoji problem as described here: http://blog.jonnew.com/posts/poo-dot-length-equals-two
+ result += nonPrintable + text.join ('')
+ length += text.length
+ }
+
+ return result
+ }
+} \ No newline at end of file