string-process-comma-separated
Advanced tools
Comparing version 1.2.4 to 1.2.5
/** | ||
* string-process-comma-separated | ||
* Extracts chunks from possibly comma or whatever-separated string | ||
* Version: 1.2.4 | ||
* Version: 1.2.5 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -63,6 +63,6 @@ * License: MIT | ||
for (var i = opts.from; i < opts.to; i++) { | ||
if (str[i].trim().length && str[i] !== opts.separator) { | ||
if (str[i].trim() && str[i] !== opts.separator) { | ||
lastNonWhitespaceCharAt = i; | ||
} | ||
if (chunkStartsAt === null && str[i].trim().length && (!opts.separator || str[i] !== opts.separator)) { | ||
if (chunkStartsAt === null && str[i].trim() && (!opts.separator || str[i] !== opts.separator)) { | ||
if (!firstNonwhitespaceNonseparatorCharFound) { | ||
@@ -84,12 +84,12 @@ firstNonwhitespaceNonseparatorCharFound = true; | ||
if (Number.isInteger(chunkStartsAt) && (i > chunkStartsAt && opts.separator && str[i] === opts.separator || i + 1 === opts.to)) { | ||
var chunk = str.slice(chunkStartsAt, i + 1 === opts.to && str[i] !== opts.separator && str[i].trim().length ? i + 1 : i); | ||
var chunk = str.slice(chunkStartsAt, i + 1 === opts.to && str[i] !== opts.separator && str[i].trim() ? i + 1 : i); | ||
if (typeof opts.cb === "function") { | ||
opts.cb(chunkStartsAt + opts.offset, (i + 1 === opts.to && str[i] !== opts.separator && str[i].trim().length ? i + 1 : lastNonWhitespaceCharAt + 1) + opts.offset); | ||
opts.cb(chunkStartsAt + opts.offset, (i + 1 === opts.to && str[i] !== opts.separator && str[i].trim() ? i + 1 : lastNonWhitespaceCharAt + 1) + opts.offset); | ||
} | ||
chunkStartsAt = null; | ||
} | ||
if (!str[i].trim().length && whitespaceStartsAt === null) { | ||
if (!str[i].trim() && whitespaceStartsAt === null) { | ||
whitespaceStartsAt = i; | ||
} | ||
if (whitespaceStartsAt !== null && (str[i].trim().length || i + 1 === opts.to)) { | ||
if (whitespaceStartsAt !== null && (str[i].trim() || i + 1 === opts.to)) { | ||
if (whitespaceStartsAt === opts.from) { | ||
@@ -99,10 +99,10 @@ if (!opts.leadingWhitespaceOK && typeof opts.errCb === "function") { | ||
} | ||
} else if (!str[i].trim().length && i + 1 === opts.to) { | ||
} else if (!str[i].trim() && i + 1 === opts.to) { | ||
if (!opts.trailingWhitespaceOK && typeof opts.errCb === "function") { | ||
opts.errCb([[whitespaceStartsAt + opts.offset, i + 1 + opts.offset]], "Remove whitespace.", fixable); | ||
} | ||
} else if ((!opts.oneSpaceAfterCommaOK || !(str[i].trim().length && i > opts.from + 1 && str[i - 1] === " " && str[i - 2] === ",")) && (!opts.innerWhitespaceAllowed || !(firstNonwhitespaceNonseparatorCharFound && str[whitespaceStartsAt - 1] && str[i].trim().length && str[i] !== opts.separator && str[whitespaceStartsAt - 1] !== opts.separator))) { | ||
} else if ((!opts.oneSpaceAfterCommaOK || !(str[i].trim() && i > opts.from + 1 && str[i - 1] === " " && str[i - 2] === ",")) && (!opts.innerWhitespaceAllowed || !(firstNonwhitespaceNonseparatorCharFound && str[whitespaceStartsAt - 1] && str[i].trim() && str[i] !== opts.separator && str[whitespaceStartsAt - 1] !== opts.separator))) { | ||
var startingIdx = whitespaceStartsAt; | ||
var endingIdx = i; | ||
if (i + 1 === opts.to && str[i] !== opts.separator && !str[i].trim().length) { | ||
if (i + 1 === opts.to && str[i] !== opts.separator && !str[i].trim()) { | ||
endingIdx++; | ||
@@ -119,3 +119,3 @@ } | ||
var message = "Remove whitespace."; | ||
if (!opts.innerWhitespaceAllowed && firstNonwhitespaceNonseparatorCharFound && str[whitespaceStartsAt - 1] && str[i].trim().length && str[i] !== opts.separator && str[whitespaceStartsAt - 1] !== opts.separator) { | ||
if (!opts.innerWhitespaceAllowed && firstNonwhitespaceNonseparatorCharFound && str[whitespaceStartsAt - 1] && str[i].trim() && str[i] !== opts.separator && str[whitespaceStartsAt - 1] !== opts.separator) { | ||
fixable = false; | ||
@@ -122,0 +122,0 @@ message = "Bad whitespace."; |
/** | ||
* string-process-comma-separated | ||
* Extracts chunks from possibly comma or whatever-separated string | ||
* Version: 1.2.4 | ||
* Version: 1.2.5 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -79,3 +79,3 @@ * License: MIT | ||
// catch the last nonwhitespace char | ||
if (str[i].trim().length && str[i] !== opts.separator) { | ||
if (str[i].trim() && str[i] !== opts.separator) { | ||
lastNonWhitespaceCharAt = i; | ||
@@ -85,3 +85,3 @@ } // catch the beginning of a chunk | ||
if (chunkStartsAt === null && str[i].trim().length && (!opts.separator || str[i] !== opts.separator)) { | ||
if (chunkStartsAt === null && str[i].trim() && (!opts.separator || str[i] !== opts.separator)) { | ||
if (!firstNonwhitespaceNonseparatorCharFound) { | ||
@@ -109,6 +109,6 @@ firstNonwhitespaceNonseparatorCharFound = true; | ||
if (Number.isInteger(chunkStartsAt) && (i > chunkStartsAt && opts.separator && str[i] === opts.separator || i + 1 === opts.to)) { | ||
var chunk = str.slice(chunkStartsAt, i + 1 === opts.to && str[i] !== opts.separator && str[i].trim().length ? i + 1 : i); // ping the cb | ||
var chunk = str.slice(chunkStartsAt, i + 1 === opts.to && str[i] !== opts.separator && str[i].trim() ? i + 1 : i); // ping the cb | ||
if (typeof opts.cb === "function") { | ||
opts.cb(chunkStartsAt + opts.offset, (i + 1 === opts.to && str[i] !== opts.separator && str[i].trim().length ? i + 1 : lastNonWhitespaceCharAt + 1) + opts.offset); | ||
opts.cb(chunkStartsAt + opts.offset, (i + 1 === opts.to && str[i] !== opts.separator && str[i].trim() ? i + 1 : lastNonWhitespaceCharAt + 1) + opts.offset); | ||
} // reset | ||
@@ -121,3 +121,3 @@ | ||
if (!str[i].trim().length && whitespaceStartsAt === null) { | ||
if (!str[i].trim() && whitespaceStartsAt === null) { | ||
whitespaceStartsAt = i; | ||
@@ -127,3 +127,3 @@ } // catch the ending of a whitespace | ||
if (whitespaceStartsAt !== null && (str[i].trim().length || i + 1 === opts.to)) { | ||
if (whitespaceStartsAt !== null && (str[i].trim() || i + 1 === opts.to)) { | ||
if (whitespaceStartsAt === opts.from) { | ||
@@ -134,3 +134,3 @@ if (!opts.leadingWhitespaceOK && typeof opts.errCb === "function") { | ||
} else if (!str[i].trim().length && i + 1 === opts.to) { | ||
} else if (!str[i].trim() && i + 1 === opts.to) { | ||
// if it's trailing whitespace, we're on the last character | ||
@@ -142,3 +142,3 @@ // (right before opts.to) | ||
} else if ((!opts.oneSpaceAfterCommaOK || !(str[i].trim().length && i > opts.from + 1 && str[i - 1] === " " && str[i - 2] === ",")) && (!opts.innerWhitespaceAllowed || !(firstNonwhitespaceNonseparatorCharFound && str[whitespaceStartsAt - 1] && str[i].trim().length && str[i] !== opts.separator && str[whitespaceStartsAt - 1] !== opts.separator))) { | ||
} else if ((!opts.oneSpaceAfterCommaOK || !(str[i].trim() && i > opts.from + 1 && str[i - 1] === " " && str[i - 2] === ",")) && (!opts.innerWhitespaceAllowed || !(firstNonwhitespaceNonseparatorCharFound && str[whitespaceStartsAt - 1] && str[i].trim() && str[i] !== opts.separator && str[whitespaceStartsAt - 1] !== opts.separator))) { | ||
// exclude single space after a comma, with condition that something | ||
@@ -150,5 +150,5 @@ // non-whitespacey follows | ||
if (i + 1 === opts.to && str[i] !== opts.separator && !str[i].trim().length) { | ||
if (i + 1 === opts.to && str[i] !== opts.separator && !str[i].trim()) { | ||
endingIdx++; | ||
} // i + 1 === opts.to && str[i] !== opts.separator && str[i].trim().length | ||
} // i + 1 === opts.to && str[i] !== opts.separator && str[i].trim() | ||
// ? i + 1 | ||
@@ -177,3 +177,3 @@ // : i; | ||
if (!opts.innerWhitespaceAllowed && firstNonwhitespaceNonseparatorCharFound && str[whitespaceStartsAt - 1] && str[i].trim().length && str[i] !== opts.separator && str[whitespaceStartsAt - 1] !== opts.separator) { | ||
if (!opts.innerWhitespaceAllowed && firstNonwhitespaceNonseparatorCharFound && str[whitespaceStartsAt - 1] && str[i].trim() && str[i] !== opts.separator && str[whitespaceStartsAt - 1] !== opts.separator) { | ||
fixable = false; | ||
@@ -180,0 +180,0 @@ message = "Bad whitespace."; |
/** | ||
* string-process-comma-separated | ||
* Extracts chunks from possibly comma or whatever-separated string | ||
* Version: 1.2.4 | ||
* Version: 1.2.5 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -51,3 +51,3 @@ * License: MIT | ||
for (let i = opts.from; i < opts.to; i++) { | ||
if (str[i].trim().length && str[i] !== opts.separator) { | ||
if (str[i].trim() && str[i] !== opts.separator) { | ||
lastNonWhitespaceCharAt = i; | ||
@@ -57,3 +57,3 @@ } | ||
chunkStartsAt === null && | ||
str[i].trim().length && | ||
str[i].trim() && | ||
(!opts.separator || str[i] !== opts.separator) | ||
@@ -92,3 +92,3 @@ ) { | ||
chunkStartsAt, | ||
i + 1 === opts.to && str[i] !== opts.separator && str[i].trim().length | ||
i + 1 === opts.to && str[i] !== opts.separator && str[i].trim() | ||
? i + 1 | ||
@@ -100,5 +100,3 @@ : i | ||
chunkStartsAt + opts.offset, | ||
(i + 1 === opts.to && | ||
str[i] !== opts.separator && | ||
str[i].trim().length | ||
(i + 1 === opts.to && str[i] !== opts.separator && str[i].trim() | ||
? i + 1 | ||
@@ -110,9 +108,6 @@ : lastNonWhitespaceCharAt + 1) + opts.offset | ||
} | ||
if (!str[i].trim().length && whitespaceStartsAt === null) { | ||
if (!str[i].trim() && whitespaceStartsAt === null) { | ||
whitespaceStartsAt = i; | ||
} | ||
if ( | ||
whitespaceStartsAt !== null && | ||
(str[i].trim().length || i + 1 === opts.to) | ||
) { | ||
if (whitespaceStartsAt !== null && (str[i].trim() || i + 1 === opts.to)) { | ||
if (whitespaceStartsAt === opts.from) { | ||
@@ -131,3 +126,3 @@ if (!opts.leadingWhitespaceOK && typeof opts.errCb === "function") { | ||
} | ||
} else if (!str[i].trim().length && i + 1 === opts.to) { | ||
} else if (!str[i].trim() && i + 1 === opts.to) { | ||
if (!opts.trailingWhitespaceOK && typeof opts.errCb === "function") { | ||
@@ -143,3 +138,3 @@ opts.errCb( | ||
!( | ||
str[i].trim().length && | ||
str[i].trim() && | ||
i > opts.from + 1 && | ||
@@ -153,3 +148,3 @@ str[i - 1] === " " && | ||
str[whitespaceStartsAt - 1] && | ||
str[i].trim().length && | ||
str[i].trim() && | ||
str[i] !== opts.separator && | ||
@@ -161,7 +156,3 @@ str[whitespaceStartsAt - 1] !== opts.separator | ||
let endingIdx = i; | ||
if ( | ||
i + 1 === opts.to && | ||
str[i] !== opts.separator && | ||
!str[i].trim().length | ||
) { | ||
if (i + 1 === opts.to && str[i] !== opts.separator && !str[i].trim()) { | ||
endingIdx++; | ||
@@ -185,3 +176,3 @@ } | ||
str[whitespaceStartsAt - 1] && | ||
str[i].trim().length && | ||
str[i].trim() && | ||
str[i] !== opts.separator && | ||
@@ -188,0 +179,0 @@ str[whitespaceStartsAt - 1] !== opts.separator |
/** | ||
* string-process-comma-separated | ||
* Extracts chunks from possibly comma or whatever-separated string | ||
* Version: 1.2.4 | ||
* Version: 1.2.5 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -10,2 +10,2 @@ * License: MIT | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).stringProcessCommaSeparated=t()}(this,(function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}return function(t,r){if("string"!=typeof t)throw new Error("string-process-comma-separated: [THROW_ID_01] input must be string! It was given as ".concat(e(t),", equal to:\n").concat(JSON.stringify(t,null,4)));if(t.length&&(r.cb||r.errCb)){var o={from:0,to:t.length,offset:0,leadingWhitespaceOK:!1,trailingWhitespaceOK:!1,oneSpaceAfterCommaOK:!1,innerWhitespaceAllowed:!1,separator:",",cb:null,errCb:null},n=Object.assign({},o,r);Number.isInteger(r.from)||(n.from=0),Number.isInteger(r.to)||(n.to=t.length),Number.isInteger(r.offset)||(n.offset=0);for(var f=null,s=null,a=!1,i=[],l=null,p=!0,m=n.from;m<n.to;m++){if(t[m].trim().length&&t[m]!==n.separator&&(l=m),null!==f||!t[m].trim().length||n.separator&&t[m]===n.separator||(a||(a=!0),i.length&&(i.length>1&&i.forEach((function(e,t){t&&n.errCb([[e+n.offset,e+1+n.offset]],"Remove separator.",p)})),i=[]),f=m),Number.isInteger(f)&&(m>f&&n.separator&&t[m]===n.separator||m+1===n.to)){t.slice(f,m+1===n.to&&t[m]!==n.separator&&t[m].trim().length?m+1:m);"function"==typeof n.cb&&n.cb(f+n.offset,(m+1===n.to&&t[m]!==n.separator&&t[m].trim().length?m+1:l+1)+n.offset),f=null}if(t[m].trim().length||null!==s||(s=m),null!==s&&(t[m].trim().length||m+1===n.to)){if(s===n.from)n.leadingWhitespaceOK||"function"!=typeof n.errCb||n.errCb([[s+n.offset,(m+1===n.to?m+1:m)+n.offset]],"Remove whitespace.",p);else if(t[m].trim().length||m+1!==n.to){if(!(n.oneSpaceAfterCommaOK&&t[m].trim().length&&m>n.from+1&&" "===t[m-1]&&","===t[m-2]||n.innerWhitespaceAllowed&&a&&t[s-1]&&t[m].trim().length&&t[m]!==n.separator&&t[s-1]!==n.separator)){var c=s,u=m;m+1!==n.to||t[m]===n.separator||t[m].trim().length||u++;var h="";n.oneSpaceAfterCommaOK&&(" "===t[s]&&t[s-1]===n.separator?c++:" "!==t[s]&&(h=" "));var g="Remove whitespace.";!n.innerWhitespaceAllowed&&a&&t[s-1]&&t[m].trim().length&&t[m]!==n.separator&&t[s-1]!==n.separator&&(p=!1,g="Bad whitespace."),h.length?n.errCb([[c+n.offset,u+n.offset,h]],g,p):n.errCb([[c+n.offset,u+n.offset]],g,p),p=!0}}else n.trailingWhitespaceOK||"function"!=typeof n.errCb||n.errCb([[s+n.offset,m+1+n.offset]],"Remove whitespace.",p);s=null}t[m]===n.separator&&(a?i.push(m):n.errCb([[m+n.offset,m+1+n.offset]],"Remove separator.",p)),m+1===n.to&&i.forEach((function(e){n.errCb([[e+n.offset,e+1+n.offset]],"Remove separator.",p)}))}}}})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).stringProcessCommaSeparated=t()}(this,(function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}return function(t,r){if("string"!=typeof t)throw new Error("string-process-comma-separated: [THROW_ID_01] input must be string! It was given as ".concat(e(t),", equal to:\n").concat(JSON.stringify(t,null,4)));if(t.length&&(r.cb||r.errCb)){var o={from:0,to:t.length,offset:0,leadingWhitespaceOK:!1,trailingWhitespaceOK:!1,oneSpaceAfterCommaOK:!1,innerWhitespaceAllowed:!1,separator:",",cb:null,errCb:null},f=Object.assign({},o,r);Number.isInteger(r.from)||(f.from=0),Number.isInteger(r.to)||(f.to=t.length),Number.isInteger(r.offset)||(f.offset=0);for(var n=null,s=null,a=!1,i=[],p=null,l=!0,m=f.from;m<f.to;m++){if(t[m].trim()&&t[m]!==f.separator&&(p=m),null!==n||!t[m].trim()||f.separator&&t[m]===f.separator||(a||(a=!0),i.length&&(i.length>1&&i.forEach((function(e,t){t&&f.errCb([[e+f.offset,e+1+f.offset]],"Remove separator.",l)})),i=[]),n=m),Number.isInteger(n)&&(m>n&&f.separator&&t[m]===f.separator||m+1===f.to)){t.slice(n,m+1===f.to&&t[m]!==f.separator&&t[m].trim()?m+1:m);"function"==typeof f.cb&&f.cb(n+f.offset,(m+1===f.to&&t[m]!==f.separator&&t[m].trim()?m+1:p+1)+f.offset),n=null}if(t[m].trim()||null!==s||(s=m),null!==s&&(t[m].trim()||m+1===f.to)){if(s===f.from)f.leadingWhitespaceOK||"function"!=typeof f.errCb||f.errCb([[s+f.offset,(m+1===f.to?m+1:m)+f.offset]],"Remove whitespace.",l);else if(t[m].trim()||m+1!==f.to){if(!(f.oneSpaceAfterCommaOK&&t[m].trim()&&m>f.from+1&&" "===t[m-1]&&","===t[m-2]||f.innerWhitespaceAllowed&&a&&t[s-1]&&t[m].trim()&&t[m]!==f.separator&&t[s-1]!==f.separator)){var c=s,u=m;m+1!==f.to||t[m]===f.separator||t[m].trim()||u++;var b="";f.oneSpaceAfterCommaOK&&(" "===t[s]&&t[s-1]===f.separator?c++:" "!==t[s]&&(b=" "));var h="Remove whitespace.";!f.innerWhitespaceAllowed&&a&&t[s-1]&&t[m].trim()&&t[m]!==f.separator&&t[s-1]!==f.separator&&(l=!1,h="Bad whitespace."),b.length?f.errCb([[c+f.offset,u+f.offset,b]],h,l):f.errCb([[c+f.offset,u+f.offset]],h,l),l=!0}}else f.trailingWhitespaceOK||"function"!=typeof f.errCb||f.errCb([[s+f.offset,m+1+f.offset]],"Remove whitespace.",l);s=null}t[m]===f.separator&&(a?i.push(m):f.errCb([[m+f.offset,m+1+f.offset]],"Remove separator.",l)),m+1===f.to&&i.forEach((function(e){f.errCb([[e+f.offset,e+1+f.offset]],"Remove separator.",l)}))}}}})); |
{ | ||
"name": "string-process-comma-separated", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "Extracts chunks from possibly comma or whatever-separated string", | ||
@@ -30,14 +30,16 @@ "license": "MIT", | ||
"build": "rollup -c", | ||
"ci_test": "npm run build && npm run lint && tap --no-only --reporter=silent --output-file=testStats.md && npm run format", | ||
"dev": "rollup -c --dev", | ||
"devunittest": "npm run dev && ./node_modules/.bin/tap --only", | ||
"devunittest": "npm run dev && ./node_modules/.bin/tap --only -R 'base'", | ||
"format": "npm run lect && npm run prettier && npm run lint", | ||
"lect": "lect", | ||
"lint": "../../node_modules/eslint/bin/eslint.js \"**/*.js\" --fix --config \"../../.eslintrc.json\"", | ||
"lint": "../../node_modules/eslint/bin/eslint.js \"**/*.js\" --fix --config \"../../.eslintrc.json\" --quiet", | ||
"perf": "node perf/check", | ||
"prepare": "npm run build", | ||
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md}' --write", | ||
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md}' --write --loglevel silent", | ||
"republish": "npm publish || :", | ||
"tap": "tap", | ||
"pretest": "npm run build", | ||
"test": "npm run lint && npm run unittest && npm run format", | ||
"unittest": "./node_modules/.bin/tap --no-only -R 'terse' -o testStats.md && npm run perf", | ||
"unittest": "./node_modules/.bin/tap --no-only --output-file=testStats.md && npm run perf", | ||
"version": "npm run build && git add ." | ||
@@ -114,3 +116,6 @@ }, | ||
"tap": { | ||
"coverage-report": "json-summary", | ||
"coverage-report": [ | ||
"json-summary", | ||
"text" | ||
], | ||
"timeout": 0 | ||
@@ -125,3 +130,3 @@ }, | ||
"benchmark": "^2.1.4", | ||
"lect": "^0.12.5", | ||
"lect": "^0.12.6", | ||
"rollup": "^2.6.1", | ||
@@ -128,0 +133,0 @@ "rollup-plugin-ascii": "^0.0.3", |
46933
550