Socket
Socket
Sign inDemoInstall

string-remove-widows

Package Overview
Dependencies
Maintainers
1
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-remove-widows - npm Package Compare versions

Comparing version 4.0.7 to 4.0.8

4

dist/string-remove-widows.esm.js
/**
* @name string-remove-widows
* @fileoverview Helps to prevent widow words in a text
* @version 4.0.7
* @version 4.0.8
* @author Roy Revelt, Codsen Ltd

@@ -10,3 +10,3 @@ * @license MIT

import{matchRightIncl as Q}from"string-match-left-right";import{left as T,right as D}from"string-left-right";import{Ranges as X}from"ranges-push";import{rApply as q}from"ranges-apply";import{rawNbsp as w,rawNDash as ee,rawMDash as te}from"codsen-utils";var R="4.0.7";var f="&nbsp;",E="\\00A0",S="\\u00A0",j="&ndash;",M="\\2013",J="\\u2013",U="&mdash;",k="\\2014",I="\\u2014",C=[{heads:"{{",tails:"}}"},{heads:["{% if","{%- if"],tails:["{% endif","{%- endif"]},{heads:["{% for","{%- for"],tails:["{% endfor","{%- endfor"]},{heads:["{%","{%-"],tails:["%}","-%}"]},{heads:"{#",tails:"#}"}],B=[{heads:"{{",tails:"}}"}],P=[{heads:["<%","<%=","<%-"],tails:["%>","=%>","-%>"]}],_=["abbr","address","area","article","aside","audio","base","bdi","bdo","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","doctype","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","math","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","param","picture","pre","progress","rb","rp","rt","rtc","ruby","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","ul","var","video","wbr","xml"];var ce=R,oe={removeWidowPreventionMeasures:!1,convertEntities:!0,targetLanguage:"html",UKPostcodes:!1,hyphens:!0,minWordCount:4,minCharCount:5,ignore:[],reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,tagRanges:[]};function me(t,h){let G=Date.now();if(typeof t!="string")throw t===void 0?new Error("string-remove-widows: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`string-remove-widows: [THROW_ID_02] the first input argument must be string! It was given as "${typeof t}", equal to:
import{matchRightIncl as Q}from"string-match-left-right";import{left as T,right as D}from"string-left-right";import{Ranges as X}from"ranges-push";import{rApply as q}from"ranges-apply";import{rawNbsp as w,rawNDash as ee,rawMDash as te}from"codsen-utils";var R="4.0.8";var f="&nbsp;",E="\\00A0",S="\\u00A0",j="&ndash;",M="\\2013",J="\\u2013",U="&mdash;",k="\\2014",I="\\u2014",C=[{heads:"{{",tails:"}}"},{heads:["{% if","{%- if"],tails:["{% endif","{%- endif"]},{heads:["{% for","{%- for"],tails:["{% endfor","{%- endfor"]},{heads:["{%","{%-"],tails:["%}","-%}"]},{heads:"{#",tails:"#}"}],B=[{heads:"{{",tails:"}}"}],P=[{heads:["<%","<%=","<%-"],tails:["%>","=%>","-%>"]}],_=["abbr","address","area","article","aside","audio","base","bdi","bdo","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","doctype","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","math","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","param","picture","pre","progress","rb","rp","rt","rtc","ruby","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","ul","var","video","wbr","xml"];var ce=R,oe={removeWidowPreventionMeasures:!1,convertEntities:!0,targetLanguage:"html",UKPostcodes:!1,hyphens:!0,minWordCount:4,minCharCount:5,ignore:[],reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,tagRanges:[]};function me(t,h){let G=Date.now();if(typeof t!="string")throw t===void 0?new Error("string-remove-widows: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`string-remove-widows: [THROW_ID_02] the first input argument must be string! It was given as "${typeof t}", equal to:
${JSON.stringify(t,null,4)}`);if(h&&typeof h!="object")throw new Error(`string-remove-widows: [THROW_ID_03] the second input argument, options object, should be a plain object but it was given as type ${typeof h}, equal to ${JSON.stringify(h,null,4)}`);let b=Array.isArray,L=t.length,a=new X({mergeType:2}),K=["."],Z=/[A-Z]{1,2}[0-9][0-9A-Z]?$/,Y=/^[0-9][A-Z]{2}/,V=.06,$,A=0,g=0,W=0,y,N,d,c,r,l,s,p,o={...oe,...h},m={removeWidows:!1,convertEntities:!1};if(!o.ignore||!b(o.ignore)&&typeof o.ignore!="string")o.ignore=[];else if(typeof o.ignore=="string"&&(o.ignore=[o.ignore]),o.ignore.includes("all"))o.ignore=o.ignore.concat(C.concat(P));else if(o.ignore.some(e=>typeof e=="string")){let e=[];o.ignore=o.ignore.filter(i=>typeof i=="string"&&i.length?(["nunjucks","jinja","liquid"].includes(i.trim().toLowerCase())?e=e.concat(C):["hugo"].includes(i.trim().toLowerCase())?e=e.concat(B):["hexo"].includes(i.trim().toLowerCase())&&(e=e.concat(P)),!1):typeof i=="object"),e.length&&(o.ignore=o.ignore.concat(e))}let x;o.reportProgressFunc&&(x=Math.floor(o.reportProgressFuncTo-(o.reportProgressFuncTo-o.reportProgressFuncFrom)*V-o.reportProgressFuncFrom));function v(e,i){let n=w;o.removeWidowPreventionMeasures?n=" ":o.convertEntities&&(n=f,typeof o.targetLanguage=="string"&&(o.targetLanguage.trim().toLowerCase()==="css"?n=E:o.targetLanguage.trim().toLowerCase()==="js"&&(n=S))),t.slice(e,i)!==n&&a.push(e,i,n)}function O(){g=0,W=0,y=void 0,N=void 0,d=void 0,c=void 0,r=void 0,l=void 0}O();for(let e=0;e<=L;e++){if(!s&&b(o.ignore)&&o.ignore.length&&o.ignore.some((n,u)=>{if(b(n.heads)&&n.heads.some(H=>t.startsWith(H,e))||typeof n.heads=="string"&&t.startsWith(n.heads,e))return g+=1,s=o.ignore[u].tails,!0}),!s&&p&&p===e&&(g+=1,p=void 0),typeof o.reportProgressFunc=="function"&&($=o.reportProgressFuncFrom+Math.floor(e/L*(x||1)),$!==A&&(A=$,o.reportProgressFunc($))),!s&&e&&t[e]&&t[e].trim()&&(!t[e-1]||t[e-1]&&!t[e-1].trim())&&(c=e),!s&&t[e]&&t[e].trim()&&(W+=1),!s&&o.hyphens&&(`-${te}${ee}`.includes(t[e])||t.startsWith(j,e)||t.startsWith(M,e)||t.startsWith(J,e)||t.startsWith(U,e)||t.startsWith(k,e)||t.startsWith(I,e))&&t[e+1]&&(!t[e+1].trim()||t[e]==="&")&&t[e-1]&&!t[e-1].trim()&&t[T(t,e)]&&(v(T(t,e)+1,e),m.removeWidows=!0),!s&&(t.startsWith("&nbsp;",e)||t.startsWith("&#160;",e))&&(r=e,l=e+6,t[e+6]&&t[e+6].trim()&&(p=e+6),o.convertEntities?(o.targetLanguage==="css"||o.targetLanguage==="js")&&(a.push(e,e+6,o.targetLanguage==="css"?E:S),m.convertEntities=!0):(a.push(e,e+6,w),m.convertEntities=!0)),!s&&t[e+4]&&t[e]==="\\"&&t[e+1]==="0"&&t[e+2]==="0"&&t[e+3].toUpperCase()==="A"&&t[e+4]==="0"&&(r=e,l=e+5,t[e+5]&&t[e+5].trim()&&(p=e+5),o.convertEntities?(o.targetLanguage==="html"||o.targetLanguage==="js")&&(a.push(e,e+5,o.targetLanguage==="html"?f:S),m.convertEntities=!0):(a.push(e,e+5,w),m.convertEntities=!0)),!s&&t[e]==="\\"&&t[e+1]&&t[e+1].toLowerCase()==="u"&&t[e+2]==="0"&&t[e+3]==="0"&&t[e+4]&&t[e+4].toUpperCase()==="A"&&t[e+5]==="0"&&(r=e,l=e+6,t[e+6]&&t[e+6].trim()&&(p=e+6),o.convertEntities?(o.targetLanguage==="html"||o.targetLanguage==="css")&&a.push(e,e+6,o.targetLanguage==="html"?f:E):a.push(e,e+6,w)),!s&&t[e]===w&&(r=e,l=e+1,o.convertEntities&&a.push(e,e+1,o.targetLanguage==="css"?E:o.targetLanguage==="js"?S:f)),!s&&t[e]&&t[e].trim()&&(!t[e-1]||!t[e-1].trim())&&(g+=1),!s&&(!t[e]||`\r

@@ -13,0 +13,0 @@ `.includes(t[e])||(t[e]===`

/**
* @name string-remove-widows
* @fileoverview Helps to prevent widow words in a text
* @version 4.0.7
* @version 4.0.8
* @author Roy Revelt, Codsen Ltd

@@ -25,3 +25,3 @@ * @license MIT

${JSON.stringify(r,null,4)}`);if(x(this.ranges)&&Array.isArray(this.last())&&n===this.last()[1]){if(this.last()[1]=u,this.last()[2],this.last()[2]!==null&&x(r)){let l=this.last()[2]&&this.last()[2].length&&(!((o=this.opts)!=null&&o.mergeType)||this.opts.mergeType===1)?`${this.last()[2]}${r}`:r;this.opts.limitToBeAddedWhitespace&&(l=le(l,this.opts.limitLinebreaksCount)),Z(l)&&!l.length||(this.last()[2]=l)}}else{this.ranges||(this.ranges=[]);let l=r!==void 0&&!(Z(r)&&!r.length)?[n,u,r&&this.opts.limitToBeAddedWhitespace?le(r,this.opts.limitLinebreaksCount):r]:[n,u];this.ranges.push(l)}}else throw I(n)&&n>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof u}" equal to: ${JSON.stringify(u,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof n}" equal to: ${JSON.stringify(n,null,4)}`)}push(e,t,r){this.add(e,t,r)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=Hn(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>x(e[2])?[e[0],e[1],le(e[2],this.opts.limitLinebreaksCount)]:e):this.ranges):null}wipe(){this.ranges=[]}replace(e){if(Array.isArray(e)&&e.length)if(Array.isArray(e[0])&&I(e[0][0]))this.ranges=Array.from(e);else throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(e[0],null,4)} should be an array and its first element should be an integer, a string index.`);else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}};var Pn={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function Ce(e,t){if(!Array.isArray(e)||!e.length)return e;let r=A(A({},Pn),t),n,u;if(r.strictlyTwoElementsInRangeArrays&&!e.every((a,g)=>!Array.isArray(a)||a.length!==2?(n=g,u=a.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${n}th range (${JSON.stringify(e[n],null,4)}) has not two but ${u} elements!`);if(!e.every((a,g)=>!Array.isArray(a)||!Number.isInteger(a[0])||a[0]<0||!Number.isInteger(a[1])||a[1]<0?(n=g,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${n}th range (${JSON.stringify(e[n],null,4)}) does not consist of only natural numbers!`);let o=e.length**2,l=0;return Array.from(e).sort((a,g)=>(r.progressFn&&(l+=1,r.progressFn(Math.floor(l*100/o))),a[0]===g[0]?a[1]<g[1]?-1:a[1]>g[1]?1:0:a[0]<g[0]?-1:1))}var Lt={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function jt(e,t){function r(i){return!!i&&typeof i=="object"&&!Array.isArray(i)}if(!Array.isArray(e)||!e.length)return null;let n;if(t)if(r(t)){if(n=A(A({},Lt),t),n.progressFn&&r(n.progressFn)&&!Object.keys(n.progressFn).length)n.progressFn=null;else if(n.progressFn&&typeof n.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof n.progressFn}", equal to ${JSON.stringify(n.progressFn,null,4)}`);if(![1,2,"1","2"].includes(n.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof n.mergeType}", equal to ${JSON.stringify(n.mergeType,null,4)}`);if(typeof n.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof n.joinRangesThatTouchEdges}", equal to ${JSON.stringify(n.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:
${JSON.stringify(t,null,4)} (type ${typeof t})`);else n=A({},Lt);let u=e.filter(i=>Array.isArray(i)).map(i=>[...i]).filter(i=>i[2]!==void 0||i[0]!==i[1]),o,l,a;n.progressFn?o=Ce(u,{progressFn:i=>{a=Math.floor(i/5),a!==l&&(l=a,n.progressFn(a))}}):o=Ce(u);let g=o.length-1;for(let i=g;i>0;i--)n.progressFn&&(a=Math.floor((1-i/g)*78)+21,a!==l&&a>l&&(l=a,n.progressFn(a))),(o[i][0]<=o[i-1][0]||!n.joinRangesThatTouchEdges&&o[i][0]<o[i-1][1]||n.joinRangesThatTouchEdges&&o[i][0]<=o[i-1][1])&&(o[i-1][0]=Math.min(o[i][0],o[i-1][0]),o[i-1][1]=Math.max(o[i][1],o[i-1][1]),o[i][2]!==void 0&&(o[i-1][0]>=o[i][0]||o[i-1][1]<=o[i][1])&&o[i-1][2]!==null&&(o[i][2]===null&&o[i-1][2]!==null?o[i-1][2]=null:o[i-1][2]!=null?+n.mergeType==2&&o[i-1][0]===o[i][0]?o[i-1][2]=o[i][2]:o[i-1][2]+=o[i][2]:o[i-1][2]=o[i][2]),o.splice(i,1),i=o.length);return o.length?o:null}var Bn=!0,Ne="Invariant failed";function Ft(e,t){if(!e){if(Bn)throw new Error(Ne);var r=typeof t=="function"?t():t,n=r?"".concat(Ne,": ").concat(r):Ne;throw new Error(n)}}function Oe(e,t,r){let n=0,u=0;if(arguments.length===0)throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");if(typeof e!="string")throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(t&&!Array.isArray(t))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof t}, equal to: ${JSON.stringify(t,null,4)}`);if(r&&typeof r!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(!t||!t.filter(h=>h).length)return e;let o;Array.isArray(t)&&Number.isInteger(t[0])&&Number.isInteger(t[1])?o=[Array.from(t)]:o=Array.from(t);let l=o.length,a=0;o.filter(h=>h).forEach((h,$)=>{if(r&&(n=Math.floor(a/l*10),n!==u&&(u=n,r(n))),!Array.isArray(h))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${$}th element not an array: ${JSON.stringify(h,null,4)}, which is ${typeof h}`);if(!Number.isInteger(h[0])){if(!Number.isInteger(+h[0])||+h[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${$}th element, array ${JSON.stringify(h,null,0)}. Its first element is not an integer, string index, but ${typeof h[0]}, equal to: ${JSON.stringify(h[0],null,4)}.`);o[$][0]=+o[$][0]}if(!Number.isInteger(h[1])){if(!Number.isInteger(+h[1])||+h[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${$}th element, array ${JSON.stringify(h,null,0)}. Its second element is not an integer, string index, but ${typeof h[1]}, equal to: ${JSON.stringify(h[1],null,4)}.`);o[$][1]=+o[$][1]}a+=1});let g=jt(o,{progressFn:h=>{r&&(n=10+Math.floor(h/10),n!==u&&(u=n,r(n)))}});Ft(g);let i=g.length;if(i>0){let h=e.slice(g[i-1][1]);e=g.reduce(($,p,f,d)=>{r&&(n=20+Math.floor(f/i*80),n!==u&&(u=n,r(n)));let S=f===0?0:d[f-1][1],y=d[f][0];return`${$}${e.slice(S,y)}${d[f][2]||""}`},""),e+=h}return e}var Ht="4.0.7";var Y="&nbsp;",z="\\00A0",X="\\u00A0",Vt="&ndash;",Pt="\\2013",Bt="\\u2013",Jt="&mdash;",kt="\\2014",Ut="\\u2014",De=[{heads:"{{",tails:"}}"},{heads:["{% if","{%- if"],tails:["{% endif","{%- endif"]},{heads:["{% for","{%- for"],tails:["{% endfor","{%- endfor"]},{heads:["{%","{%-"],tails:["%}","-%}"]},{heads:"{#",tails:"#}"}],qt=[{heads:"{{",tails:"}}"}],We=[{heads:["<%","<%=","<%-"],tails:["%>","=%>","-%>"]}],Gt=["abbr","address","area","article","aside","audio","base","bdi","bdo","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","doctype","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","math","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","param","picture","pre","progress","rb","rp","rt","rtc","ruby","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","ul","var","video","wbr","xml"];var kn=Ht,Kt={removeWidowPreventionMeasures:!1,convertEntities:!0,targetLanguage:"html",UKPostcodes:!1,hyphens:!0,minWordCount:4,minCharCount:5,ignore:[],reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,tagRanges:[]};function Un(e,t){let r=Date.now();if(typeof e!="string")throw e===void 0?new Error("string-remove-widows: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`string-remove-widows: [THROW_ID_02] the first input argument must be string! It was given as "${typeof e}", equal to:
${JSON.stringify(t,null,4)} (type ${typeof t})`);else n=A({},Lt);let u=e.filter(i=>Array.isArray(i)).map(i=>[...i]).filter(i=>i[2]!==void 0||i[0]!==i[1]),o,l,a;n.progressFn?o=Ce(u,{progressFn:i=>{a=Math.floor(i/5),a!==l&&(l=a,n.progressFn(a))}}):o=Ce(u);let g=o.length-1;for(let i=g;i>0;i--)n.progressFn&&(a=Math.floor((1-i/g)*78)+21,a!==l&&a>l&&(l=a,n.progressFn(a))),(o[i][0]<=o[i-1][0]||!n.joinRangesThatTouchEdges&&o[i][0]<o[i-1][1]||n.joinRangesThatTouchEdges&&o[i][0]<=o[i-1][1])&&(o[i-1][0]=Math.min(o[i][0],o[i-1][0]),o[i-1][1]=Math.max(o[i][1],o[i-1][1]),o[i][2]!==void 0&&(o[i-1][0]>=o[i][0]||o[i-1][1]<=o[i][1])&&o[i-1][2]!==null&&(o[i][2]===null&&o[i-1][2]!==null?o[i-1][2]=null:o[i-1][2]!=null?+n.mergeType==2&&o[i-1][0]===o[i][0]?o[i-1][2]=o[i][2]:o[i-1][2]+=o[i][2]:o[i-1][2]=o[i][2]),o.splice(i,1),i=o.length);return o.length?o:null}var Bn=!0,Ne="Invariant failed";function Ft(e,t){if(!e){if(Bn)throw new Error(Ne);var r=typeof t=="function"?t():t,n=r?"".concat(Ne,": ").concat(r):Ne;throw new Error(n)}}function Oe(e,t,r){let n=0,u=0;if(arguments.length===0)throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");if(typeof e!="string")throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(t&&!Array.isArray(t))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof t}, equal to: ${JSON.stringify(t,null,4)}`);if(r&&typeof r!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(!t||!t.filter(h=>h).length)return e;let o;Array.isArray(t)&&Number.isInteger(t[0])&&Number.isInteger(t[1])?o=[Array.from(t)]:o=Array.from(t);let l=o.length,a=0;o.filter(h=>h).forEach((h,$)=>{if(r&&(n=Math.floor(a/l*10),n!==u&&(u=n,r(n))),!Array.isArray(h))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${$}th element not an array: ${JSON.stringify(h,null,4)}, which is ${typeof h}`);if(!Number.isInteger(h[0])){if(!Number.isInteger(+h[0])||+h[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${$}th element, array ${JSON.stringify(h,null,0)}. Its first element is not an integer, string index, but ${typeof h[0]}, equal to: ${JSON.stringify(h[0],null,4)}.`);o[$][0]=+o[$][0]}if(!Number.isInteger(h[1])){if(!Number.isInteger(+h[1])||+h[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${$}th element, array ${JSON.stringify(h,null,0)}. Its second element is not an integer, string index, but ${typeof h[1]}, equal to: ${JSON.stringify(h[1],null,4)}.`);o[$][1]=+o[$][1]}a+=1});let g=jt(o,{progressFn:h=>{r&&(n=10+Math.floor(h/10),n!==u&&(u=n,r(n)))}});Ft(g);let i=g.length;if(i>0){let h=e.slice(g[i-1][1]);e=g.reduce(($,p,f,d)=>{r&&(n=20+Math.floor(f/i*80),n!==u&&(u=n,r(n)));let S=f===0?0:d[f-1][1],y=d[f][0];return`${$}${e.slice(S,y)}${d[f][2]||""}`},""),e+=h}return e}var Ht="4.0.8";var Y="&nbsp;",z="\\00A0",X="\\u00A0",Vt="&ndash;",Pt="\\2013",Bt="\\u2013",Jt="&mdash;",kt="\\2014",Ut="\\u2014",De=[{heads:"{{",tails:"}}"},{heads:["{% if","{%- if"],tails:["{% endif","{%- endif"]},{heads:["{% for","{%- for"],tails:["{% endfor","{%- endfor"]},{heads:["{%","{%-"],tails:["%}","-%}"]},{heads:"{#",tails:"#}"}],qt=[{heads:"{{",tails:"}}"}],We=[{heads:["<%","<%=","<%-"],tails:["%>","=%>","-%>"]}],Gt=["abbr","address","area","article","aside","audio","base","bdi","bdo","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","doctype","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","math","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","param","picture","pre","progress","rb","rp","rt","rtc","ruby","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","ul","var","video","wbr","xml"];var kn=Ht,Kt={removeWidowPreventionMeasures:!1,convertEntities:!0,targetLanguage:"html",UKPostcodes:!1,hyphens:!0,minWordCount:4,minCharCount:5,ignore:[],reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,tagRanges:[]};function Un(e,t){let r=Date.now();if(typeof e!="string")throw e===void 0?new Error("string-remove-widows: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`string-remove-widows: [THROW_ID_02] the first input argument must be string! It was given as "${typeof e}", equal to:
${JSON.stringify(e,null,4)}`);if(t&&typeof t!="object")throw new Error(`string-remove-widows: [THROW_ID_03] the second input argument, options object, should be a plain object but it was given as type ${typeof t}, equal to ${JSON.stringify(t,null,4)}`);let n=Array.isArray,u=e.length,o=new Mt({mergeType:2}),l=["."],a=/[A-Z]{1,2}[0-9][0-9A-Z]?$/,g=/^[0-9][A-Z]{2}/,i=.06,h,$=0,p=0,f=0,d,S,y,v,w,b,E,_,c=A(A({},Kt),t),N={removeWidows:!1,convertEntities:!1};if(!c.ignore||!n(c.ignore)&&typeof c.ignore!="string")c.ignore=[];else if(typeof c.ignore=="string"&&(c.ignore=[c.ignore]),c.ignore.includes("all"))c.ignore=c.ignore.concat(De.concat(We));else if(c.ignore.some(s=>typeof s=="string")){let s=[];c.ignore=c.ignore.filter(C=>typeof C=="string"&&C.length?(["nunjucks","jinja","liquid"].includes(C.trim().toLowerCase())?s=s.concat(De):["hugo"].includes(C.trim().toLowerCase())?s=s.concat(qt):["hexo"].includes(C.trim().toLowerCase())&&(s=s.concat(We)),!1):typeof C=="object"),s.length&&(c.ignore=c.ignore.concat(s))}let Re;c.reportProgressFunc&&(Re=Math.floor(c.reportProgressFuncTo-(c.reportProgressFuncTo-c.reportProgressFuncFrom)*i-c.reportProgressFuncFrom));function ce(s,C){let m=F;c.removeWidowPreventionMeasures?m=" ":c.convertEntities&&(m=Y,typeof c.targetLanguage=="string"&&(c.targetLanguage.trim().toLowerCase()==="css"?m=z:c.targetLanguage.trim().toLowerCase()==="js"&&(m=X))),e.slice(s,C)!==m&&o.push(s,C,m)}function xe(){p=0,f=0,d=void 0,S=void 0,y=void 0,v=void 0,w=void 0,b=void 0}xe();for(let s=0;s<=u;s++){if(!E&&n(c.ignore)&&c.ignore.length&&c.ignore.some((m,O)=>{if(n(m.heads)&&m.heads.some(Ie=>e.startsWith(Ie,s))||typeof m.heads=="string"&&e.startsWith(m.heads,s))return p+=1,E=c.ignore[O].tails,!0}),!E&&_&&_===s&&(p+=1,_=void 0),typeof c.reportProgressFunc=="function"&&(h=c.reportProgressFuncFrom+Math.floor(s/u*(Re||1)),h!==$&&($=h,c.reportProgressFunc(h))),!E&&s&&e[s]&&e[s].trim()&&(!e[s-1]||e[s-1]&&!e[s-1].trim())&&(v=s),!E&&e[s]&&e[s].trim()&&(f+=1),!E&&c.hyphens&&(`-${ke}${Je}`.includes(e[s])||e.startsWith(Vt,s)||e.startsWith(Pt,s)||e.startsWith(Bt,s)||e.startsWith(Jt,s)||e.startsWith(kt,s)||e.startsWith(Ut,s))&&e[s+1]&&(!e[s+1].trim()||e[s]==="&")&&e[s-1]&&!e[s-1].trim()&&e[Q(e,s)]&&(ce(Q(e,s)+1,s),N.removeWidows=!0),!E&&(e.startsWith("&nbsp;",s)||e.startsWith("&#160;",s))&&(w=s,b=s+6,e[s+6]&&e[s+6].trim()&&(_=s+6),c.convertEntities?(c.targetLanguage==="css"||c.targetLanguage==="js")&&(o.push(s,s+6,c.targetLanguage==="css"?z:X),N.convertEntities=!0):(o.push(s,s+6,F),N.convertEntities=!0)),!E&&e[s+4]&&e[s]==="\\"&&e[s+1]==="0"&&e[s+2]==="0"&&e[s+3].toUpperCase()==="A"&&e[s+4]==="0"&&(w=s,b=s+5,e[s+5]&&e[s+5].trim()&&(_=s+5),c.convertEntities?(c.targetLanguage==="html"||c.targetLanguage==="js")&&(o.push(s,s+5,c.targetLanguage==="html"?Y:X),N.convertEntities=!0):(o.push(s,s+5,F),N.convertEntities=!0)),!E&&e[s]==="\\"&&e[s+1]&&e[s+1].toLowerCase()==="u"&&e[s+2]==="0"&&e[s+3]==="0"&&e[s+4]&&e[s+4].toUpperCase()==="A"&&e[s+5]==="0"&&(w=s,b=s+6,e[s+6]&&e[s+6].trim()&&(_=s+6),c.convertEntities?(c.targetLanguage==="html"||c.targetLanguage==="css")&&o.push(s,s+6,c.targetLanguage==="html"?Y:z):o.push(s,s+6,F)),!E&&e[s]===F&&(w=s,b=s+1,c.convertEntities&&o.push(s,s+1,c.targetLanguage==="css"?z:c.targetLanguage==="js"?X:Y)),!E&&e[s]&&e[s].trim()&&(!e[s-1]||!e[s-1].trim())&&(p+=1),!E&&(!e[s]||`\r

@@ -43,3 +43,3 @@ `.includes(e[s])||(e[s]===`

* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
* @version 9.0.7
* @version 9.0.8
* @author Roy Revelt, Codsen Ltd

@@ -60,3 +60,3 @@ * @license MIT

* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
* @version 6.0.7
* @version 6.0.8
* @author Roy Revelt, Codsen Ltd

@@ -77,3 +77,3 @@ * @license MIT

* @fileoverview Gather string index ranges
* @version 7.0.4
* @version 7.0.5
* @author Roy Revelt, Codsen Ltd

@@ -86,3 +86,3 @@ * @license MIT

* @fileoverview Sort string index ranges
* @version 6.0.4
* @version 6.0.5
* @author Roy Revelt, Codsen Ltd

@@ -95,3 +95,3 @@ * @license MIT

* @fileoverview Merge and sort string index ranges
* @version 9.0.4
* @version 9.0.5
* @author Roy Revelt, Codsen Ltd

@@ -104,3 +104,3 @@ * @license MIT

* @fileoverview Take an array of string index ranges, delete/replace the string according to them
* @version 7.0.4
* @version 7.0.5
* @author Roy Revelt, Codsen Ltd

@@ -107,0 +107,0 @@ * @license MIT

{
"name": "string-remove-widows",
"version": "4.0.7",
"version": "4.0.8",
"description": "Helps to prevent widow words in a text",

@@ -79,10 +79,10 @@ "keywords": [

"codsen-utils": "^1.2.0",
"ranges-apply": "^7.0.4",
"ranges-push": "^7.0.4",
"string-left-right": "^6.0.7",
"string-match-left-right": "^9.0.7"
"ranges-apply": "^7.0.5",
"ranges-push": "^7.0.5",
"string-left-right": "^6.0.8",
"string-match-left-right": "^9.0.8"
},
"devDependencies": {
"string-strip-html": "^13.1.0"
"string-strip-html": "^13.2.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc