diff options
Diffstat (limited to 'school/node_modules/string-collapse-leading-whitespace/dist')
4 files changed, 305 insertions, 0 deletions
diff --git a/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.cjs.js b/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.cjs.js new file mode 100644 index 0000000..bc61686 --- /dev/null +++ b/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.cjs.js @@ -0,0 +1,88 @@ +/** + * @name string-collapse-leading-whitespace + * @fileoverview Collapse the leading and trailing whitespace of a string + * @version 5.1.0 + * @author Roy Revelt, Codsen Ltd + * @license MIT + * {@link https://codsen.com/os/string-collapse-leading-whitespace/} + */ + +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var version$1 = "5.1.0"; + +var version = version$1; +function collWhitespace(str) { + var originallineBreakLimit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + var rawNbsp = "\xA0"; + function reverse(s) { + return Array.from(s).reverse().join(""); + } + function prep(whitespaceChunk, limit, trailing) { + var firstBreakChar = trailing ? "\n" : "\r"; + var secondBreakChar = trailing ? "\r" : "\n"; + if (!whitespaceChunk) { + return whitespaceChunk; + } + var crlfCount = 0; + var res = ""; + for (var i = 0, len = whitespaceChunk.length; i < len; i++) { + if (whitespaceChunk[i] === firstBreakChar || whitespaceChunk[i] === secondBreakChar && whitespaceChunk[i - 1] !== firstBreakChar) { + crlfCount++; + } + if ("\r\n".includes(whitespaceChunk[i]) || whitespaceChunk[i] === rawNbsp) { + if (whitespaceChunk[i] === rawNbsp) { + res += whitespaceChunk[i]; + } else if (whitespaceChunk[i] === firstBreakChar) { + if (crlfCount <= limit) { + res += whitespaceChunk[i]; + if (whitespaceChunk[i + 1] === secondBreakChar) { + res += whitespaceChunk[i + 1]; + i++; + } + } + } else if (whitespaceChunk[i] === secondBreakChar && (!whitespaceChunk[i - 1] || whitespaceChunk[i - 1] !== firstBreakChar) && crlfCount <= limit) { + res += whitespaceChunk[i]; + } + } else { + if (!whitespaceChunk[i + 1] && !crlfCount) { + res += " "; + } + } + } + return res; + } + if (typeof str === "string" && str.length) { + var lineBreakLimit = 1; + if (typeof +originallineBreakLimit === "number" && Number.isInteger(+originallineBreakLimit) && +originallineBreakLimit >= 0) { + lineBreakLimit = +originallineBreakLimit; + } + var frontPart = ""; + var endPart = ""; + if (!str.trim()) { + frontPart = str; + } else if (!str[0].trim()) { + for (var i = 0, len = str.length; i < len; i++) { + if (str[i].trim()) { + frontPart = str.slice(0, i); + break; + } + } + } + if (str.trim() && (str.slice(-1).trim() === "" || str.slice(-1) === rawNbsp)) { + for (var _i = str.length; _i--;) { + if (str[_i].trim()) { + endPart = str.slice(_i + 1); + break; + } + } + } + return "".concat(prep(frontPart, lineBreakLimit, false)).concat(str.trim()).concat(reverse(prep(reverse(endPart), lineBreakLimit, true))); + } + return str; +} + +exports.collWhitespace = collWhitespace; +exports.version = version; diff --git a/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.dev.umd.js b/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.dev.umd.js new file mode 100644 index 0000000..5774a31 --- /dev/null +++ b/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.dev.umd.js @@ -0,0 +1,125 @@ +/** + * @name string-collapse-leading-whitespace + * @fileoverview Collapse the leading and trailing whitespace of a string + * @version 5.1.0 + * @author Roy Revelt, Codsen Ltd + * @license MIT + * {@link https://codsen.com/os/string-collapse-leading-whitespace/} + */ + +(function (global, factory) { +typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : +typeof define === 'function' && define.amd ? define(['exports'], factory) : +(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.stringCollapseLeadingWhitespace = {})); +}(this, (function (exports) { 'use strict'; + +var version$1 = "5.1.0"; + +const version = version$1; +function collWhitespace(str, originallineBreakLimit = 1) { + const rawNbsp = "\u00A0"; + // helpers + function reverse(s) { + return Array.from(s).reverse().join(""); + } + // replaces the leading/trailing whitespace chunks with final strings + function prep(whitespaceChunk, limit, trailing) { + // when processing the leading whitespace, it's \n\r --- CR - LF + // when processing the trailing whitespace, we're processing inverted order, + // so it's \n\r --- LF - CR + // for this reason, we set first and second linebreak according to direction, + // the "trailing" boolean: + const firstBreakChar = trailing ? "\n" : "\r"; + const secondBreakChar = trailing ? "\r" : "\n"; + if (!whitespaceChunk) { + return whitespaceChunk; + } + let crlfCount = 0; + let res = ""; + // let beginning = true; + for (let i = 0, len = whitespaceChunk.length; i < len; i++) { + if (whitespaceChunk[i] === firstBreakChar || + (whitespaceChunk[i] === secondBreakChar && + whitespaceChunk[i - 1] !== firstBreakChar)) { + crlfCount++; + } + if (`\r\n`.includes(whitespaceChunk[i]) || + whitespaceChunk[i] === rawNbsp) { + if (whitespaceChunk[i] === rawNbsp) { + res += whitespaceChunk[i]; + } + else if (whitespaceChunk[i] === firstBreakChar) { + if (crlfCount <= limit) { + res += whitespaceChunk[i]; + if (whitespaceChunk[i + 1] === secondBreakChar) { + res += whitespaceChunk[i + 1]; + i++; + } + } + } + else if (whitespaceChunk[i] === secondBreakChar && + (!whitespaceChunk[i - 1] || + whitespaceChunk[i - 1] !== firstBreakChar) && + crlfCount <= limit) { + res += whitespaceChunk[i]; + } + } + else { + if (!whitespaceChunk[i + 1] && !crlfCount) { + res += " "; + } + } + } + return res; + } + if (typeof str === "string" && str.length) { + // without a fuss, set the max allowed line breaks as a leading/trailing whitespace: + let lineBreakLimit = 1; + if (typeof +originallineBreakLimit === "number" && + Number.isInteger(+originallineBreakLimit) && + +originallineBreakLimit >= 0) { + lineBreakLimit = +originallineBreakLimit; + } + // plan: extract what would String.prototype() would remove, front and back parts + let frontPart = ""; + let endPart = ""; + if (!str.trim()) { + frontPart = str; + } + else if (!str[0].trim()) { + for (let i = 0, len = str.length; i < len; i++) { + if (str[i].trim()) { + frontPart = str.slice(0, i); + break; + } + } + } + // if whole string is whitespace, endPart is empty string + if (str.trim() && + (str.slice(-1).trim() === "" || str.slice(-1) === rawNbsp)) { + for (let i = str.length; i--;) { + // console.log( + // `${`\u001b[${36}m${`----------------------------------------------\niterating through: ${JSON.stringify( + // str[i], + // null, + // 4 + // )}`}\u001b[${39}m`}` + // ); + if (str[i].trim()) { + endPart = str.slice(i + 1); + break; + } + } + } + // ------------------------------------------------------------------------- + return `${prep(frontPart, lineBreakLimit, false)}${str.trim()}${reverse(prep(reverse(endPart), lineBreakLimit, true))}`; + } + return str; +} + +exports.collWhitespace = collWhitespace; +exports.version = version; + +Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.esm.js b/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.esm.js new file mode 100644 index 0000000..e1dd34f --- /dev/null +++ b/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.esm.js @@ -0,0 +1,82 @@ +/** + * @name string-collapse-leading-whitespace + * @fileoverview Collapse the leading and trailing whitespace of a string + * @version 5.1.0 + * @author Roy Revelt, Codsen Ltd + * @license MIT + * {@link https://codsen.com/os/string-collapse-leading-whitespace/} + */ + +var version$1 = "5.1.0"; + +const version = version$1; +function collWhitespace(str, originallineBreakLimit = 1) { + const rawNbsp = "\u00A0"; + function reverse(s) { + return Array.from(s).reverse().join(""); + } + function prep(whitespaceChunk, limit, trailing) { + const firstBreakChar = trailing ? "\n" : "\r"; + const secondBreakChar = trailing ? "\r" : "\n"; + if (!whitespaceChunk) { + return whitespaceChunk; + } + let crlfCount = 0; + let res = ""; + for (let i = 0, len = whitespaceChunk.length; i < len; i++) { + if (whitespaceChunk[i] === firstBreakChar || whitespaceChunk[i] === secondBreakChar && whitespaceChunk[i - 1] !== firstBreakChar) { + crlfCount++; + } + if (`\r\n`.includes(whitespaceChunk[i]) || whitespaceChunk[i] === rawNbsp) { + if (whitespaceChunk[i] === rawNbsp) { + res += whitespaceChunk[i]; + } else if (whitespaceChunk[i] === firstBreakChar) { + if (crlfCount <= limit) { + res += whitespaceChunk[i]; + if (whitespaceChunk[i + 1] === secondBreakChar) { + res += whitespaceChunk[i + 1]; + i++; + } + } + } else if (whitespaceChunk[i] === secondBreakChar && (!whitespaceChunk[i - 1] || whitespaceChunk[i - 1] !== firstBreakChar) && crlfCount <= limit) { + res += whitespaceChunk[i]; + } + } else { + if (!whitespaceChunk[i + 1] && !crlfCount) { + res += " "; + } + } + } + return res; + } + if (typeof str === "string" && str.length) { + let lineBreakLimit = 1; + if (typeof +originallineBreakLimit === "number" && Number.isInteger(+originallineBreakLimit) && +originallineBreakLimit >= 0) { + lineBreakLimit = +originallineBreakLimit; + } + let frontPart = ""; + let endPart = ""; + if (!str.trim()) { + frontPart = str; + } else if (!str[0].trim()) { + for (let i = 0, len = str.length; i < len; i++) { + if (str[i].trim()) { + frontPart = str.slice(0, i); + break; + } + } + } + if (str.trim() && (str.slice(-1).trim() === "" || str.slice(-1) === rawNbsp)) { + for (let i = str.length; i--;) { + if (str[i].trim()) { + endPart = str.slice(i + 1); + break; + } + } + } + return `${prep(frontPart, lineBreakLimit, false)}${str.trim()}${reverse(prep(reverse(endPart), lineBreakLimit, true))}`; + } + return str; +} + +export { collWhitespace, version }; diff --git a/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.umd.js b/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.umd.js new file mode 100644 index 0000000..b2be96c --- /dev/null +++ b/school/node_modules/string-collapse-leading-whitespace/dist/string-collapse-leading-whitespace.umd.js @@ -0,0 +1,10 @@ +/** + * @name string-collapse-leading-whitespace + * @fileoverview Collapse the leading and trailing whitespace of a string + * @version 5.1.0 + * @author Roy Revelt, Codsen Ltd + * @license MIT + * {@link https://codsen.com/os/string-collapse-leading-whitespace/} + */ + +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).stringCollapseLeadingWhitespace={})}(this,(function(e){"use strict";e.collWhitespace=function(e,t=1){function i(e){return Array.from(e).reverse().join("")}function r(e,t,i){const r=i?"\n":"\r",n=i?"\r":"\n";if(!e)return e;let f=0,o="";for(let i=0,l=e.length;i<l;i++)(e[i]===r||e[i]===n&&e[i-1]!==r)&&f++,"\r\n".includes(e[i])||" "===e[i]?" "===e[i]?o+=e[i]:e[i]===r?f<=t&&(o+=e[i],e[i+1]===n&&(o+=e[i+1],i++)):e[i]===n&&(!e[i-1]||e[i-1]!==r)&&f<=t&&(o+=e[i]):e[i+1]||f||(o+=" ");return o}if("string"==typeof e&&e.length){let n=1;"number"==typeof+t&&Number.isInteger(+t)&&+t>=0&&(n=+t);let f="",o="";if(e.trim()){if(!e[0].trim())for(let t=0,i=e.length;t<i;t++)if(e[t].trim()){f=e.slice(0,t);break}}else f=e;if(e.trim()&&(""===e.slice(-1).trim()||" "===e.slice(-1)))for(let t=e.length;t--;)if(e[t].trim()){o=e.slice(t+1);break}return`${r(f,n,!1)}${e.trim()}${i(r(i(o),n,!0))}`}return e},e.version="5.1.0",Object.defineProperty(e,"__esModule",{value:!0})})); |