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.18 to 4.0.19

4

dist/string-remove-widows.esm.js
/**
* @name string-remove-widows
* @fileoverview Helps to prevent widow words in a text
* @version 4.0.18
* @version 4.0.19
* @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.18";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.19";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,u,c,r,d,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,u=void 0,c=void 0,r=void 0,d=void 0}O();for(let e=0;e<=L;e++){if(!s&&b(o.ignore)&&o.ignore.length&&o.ignore.some((n,l)=>{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[l].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]?.trim()&&(!t[e-1]||t[e-1]&&!t[e-1].trim())&&(c=e),!s&&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,d=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,d=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,d=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,d=e+1,o.convertEntities&&a.push(e,e+1,o.targetLanguage==="css"?E:o.targetLanguage==="js"?S:f)),!s&&t[e]?.trim()&&!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.18
* @version 4.0.19
* @author Roy Revelt, Codsen Ltd

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

${JSON.stringify(a,null,4)}`);if(R(this.ranges)&&Array.isArray(this.last())&&s===this.last()[1]){if(this.last()[1]=u,this.last()[2],this.last()[2]!==null&&R(a)){let l=this.last()[2]&&this.last()[2].length&&(!((t=this.opts)!=null&&t.mergeType)||this.opts.mergeType===1)?`${this.last()[2]}${a}`:a;this.opts.limitToBeAddedWhitespace&&(l=J(l,this.opts.limitLinebreaksCount)),N(l)&&!l.length||(this.last()[2]=l)}}else{this.ranges||(this.ranges=[]);let l=a!==void 0&&!(N(a)&&!a.length)?[s,u,a&&this.opts.limitToBeAddedWhitespace?J(a,this.opts.limitLinebreaksCount):a]:[s,u];this.ranges.push(l)}}else throw O(s)&&s>=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 s}" equal to: ${JSON.stringify(s,null,4)}`)}push(e,r,a){this.add(e,r,a)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=nt(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>R(e[2])?[e[0],e[1],J(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])&&O(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 We={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function Ce(e,r){function a(n){return!!n&&typeof n=="object"&&!Array.isArray(n)}if(!Array.isArray(e)||!e.length)return null;let s;if(r)if(a(r)){if(s=A(A({},We),r),s.progressFn&&a(s.progressFn)&&!Object.keys(s.progressFn).length)s.progressFn=null;else if(s.progressFn&&typeof s.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof s.progressFn}", equal to ${JSON.stringify(s.progressFn,null,4)}`);if(![1,2,"1","2"].includes(s.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof s.mergeType}", equal to ${JSON.stringify(s.mergeType,null,4)}`);if(typeof s.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 s.joinRangesThatTouchEdges}", equal to ${JSON.stringify(s.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(r,null,4)} (type ${typeof r})`);else s=A({},We);let u=e.filter(n=>Array.isArray(n)).map(n=>[...n]).filter(n=>n[2]!==void 0||n[0]!==n[1]),t,l,i;s.progressFn?t=V(u,{progressFn:n=>{i=Math.floor(n/5),i!==l&&(l=i,s.progressFn(i))}}):t=V(u);let g=t.length-1;for(let n=g;n>0;n--)s.progressFn&&(i=Math.floor((1-n/g)*78)+21,i!==l&&i>l&&(l=i,s.progressFn(i))),(t[n][0]<=t[n-1][0]||!s.joinRangesThatTouchEdges&&t[n][0]<t[n-1][1]||s.joinRangesThatTouchEdges&&t[n][0]<=t[n-1][1])&&(t[n-1][0]=Math.min(t[n][0],t[n-1][0]),t[n-1][1]=Math.max(t[n][1],t[n-1][1]),t[n][2]!==void 0&&(t[n-1][0]>=t[n][0]||t[n-1][1]<=t[n][1])&&t[n-1][2]!==null&&(t[n][2]===null&&t[n-1][2]!==null?t[n-1][2]=null:t[n-1][2]!=null?+s.mergeType==2&&t[n-1][0]===t[n][0]?t[n-1][2]=t[n][2]:t[n-1][2]+=t[n][2]:t[n-1][2]=t[n][2]),t.splice(n,1),n=t.length);return t.length?t:null}var it=!0,G="Invariant failed";function Oe(e,r){if(!e){if(it)throw new Error(G);var a=typeof r=="function"?r():r,s=a?"".concat(G,": ").concat(a):G;throw new Error(s)}}function K(e,r,a){let s=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(r&&!Array.isArray(r))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(a&&typeof a!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof a}, equal to: ${JSON.stringify(a,null,4)}`);if(!(r!=null&&r.filter(c=>c).length))return e;let t;Array.isArray(r)&&Number.isInteger(r[0])&&Number.isInteger(r[1])?t=[Array.from(r)]:t=Array.from(r);let l=t.length,i=0;t.filter(c=>c).forEach((c,p)=>{if(a&&(s=Math.floor(i/l*10),s!==u&&(u=s,a(s))),!Array.isArray(c))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${p}th element not an array: ${JSON.stringify(c,null,4)}, which is ${typeof c}`);if(!Number.isInteger(c[0])){if(!Number.isInteger(+c[0])||+c[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${p}th element, array ${JSON.stringify(c,null,0)}. Its first element is not an integer, string index, but ${typeof c[0]}, equal to: ${JSON.stringify(c[0],null,4)}.`);t[p][0]=+t[p][0]}if(!Number.isInteger(c[1])){if(!Number.isInteger(+c[1])||+c[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${p}th element, array ${JSON.stringify(c,null,0)}. Its second element is not an integer, string index, but ${typeof c[1]}, equal to: ${JSON.stringify(c[1],null,4)}.`);t[p][1]=+t[p][1]}i+=1});let g=Ce(t,{progressFn:c=>{a&&(s=10+Math.floor(c/10),s!==u&&(u=s,a(s)))}});Oe(g);let n=g.length;if(n>0){let c=e.slice(g[n-1][1]);e=g.reduce((p,h,m,d)=>{a&&(s=20+Math.floor(m/n*80),s!==u&&(u=s,a(s)));let v=m===0?0:d[m-1][1],y=d[m][0];return`${p}${e.slice(v,y)}${d[m][2]||""}`},""),e+=c}return e}var Re="4.0.18";var H="&nbsp;",P="\\00A0",B="\\u00A0",Me="&ndash;",xe="\\2013",Ie="\\u2013",Le="&mdash;",Ve="\\2014",je="\\u2014",Z=[{heads:"{{",tails:"}}"},{heads:["{% if","{%- if"],tails:["{% endif","{%- endif"]},{heads:["{% for","{%- for"],tails:["{% endfor","{%- endfor"]},{heads:["{%","{%-"],tails:["%}","-%}"]},{heads:"{#",tails:"#}"}],Fe=[{heads:"{{",tails:"}}"}],z=[{heads:["<%","<%=","<%-"],tails:["%>","=%>","-%>"]}],_e=["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 at=Re,He={removeWidowPreventionMeasures:!1,convertEntities:!0,targetLanguage:"html",UKPostcodes:!1,hyphens:!0,minWordCount:4,minCharCount:5,ignore:[],reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,tagRanges:[]};function lt(e,r){var ee,te,re,ne,se,ie,oe,ae,le,ue;let a=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(r,null,4)} (type ${typeof r})`);else s=A({},We);let u=e.filter(n=>Array.isArray(n)).map(n=>[...n]).filter(n=>n[2]!==void 0||n[0]!==n[1]),t,l,i;s.progressFn?t=V(u,{progressFn:n=>{i=Math.floor(n/5),i!==l&&(l=i,s.progressFn(i))}}):t=V(u);let g=t.length-1;for(let n=g;n>0;n--)s.progressFn&&(i=Math.floor((1-n/g)*78)+21,i!==l&&i>l&&(l=i,s.progressFn(i))),(t[n][0]<=t[n-1][0]||!s.joinRangesThatTouchEdges&&t[n][0]<t[n-1][1]||s.joinRangesThatTouchEdges&&t[n][0]<=t[n-1][1])&&(t[n-1][0]=Math.min(t[n][0],t[n-1][0]),t[n-1][1]=Math.max(t[n][1],t[n-1][1]),t[n][2]!==void 0&&(t[n-1][0]>=t[n][0]||t[n-1][1]<=t[n][1])&&t[n-1][2]!==null&&(t[n][2]===null&&t[n-1][2]!==null?t[n-1][2]=null:t[n-1][2]!=null?+s.mergeType==2&&t[n-1][0]===t[n][0]?t[n-1][2]=t[n][2]:t[n-1][2]+=t[n][2]:t[n-1][2]=t[n][2]),t.splice(n,1),n=t.length);return t.length?t:null}var it=!0,G="Invariant failed";function Oe(e,r){if(!e){if(it)throw new Error(G);var a=typeof r=="function"?r():r,s=a?"".concat(G,": ").concat(a):G;throw new Error(s)}}function K(e,r,a){let s=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(r&&!Array.isArray(r))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(a&&typeof a!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof a}, equal to: ${JSON.stringify(a,null,4)}`);if(!(r!=null&&r.filter(c=>c).length))return e;let t;Array.isArray(r)&&Number.isInteger(r[0])&&Number.isInteger(r[1])?t=[Array.from(r)]:t=Array.from(r);let l=t.length,i=0;t.filter(c=>c).forEach((c,p)=>{if(a&&(s=Math.floor(i/l*10),s!==u&&(u=s,a(s))),!Array.isArray(c))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${p}th element not an array: ${JSON.stringify(c,null,4)}, which is ${typeof c}`);if(!Number.isInteger(c[0])){if(!Number.isInteger(+c[0])||+c[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${p}th element, array ${JSON.stringify(c,null,0)}. Its first element is not an integer, string index, but ${typeof c[0]}, equal to: ${JSON.stringify(c[0],null,4)}.`);t[p][0]=+t[p][0]}if(!Number.isInteger(c[1])){if(!Number.isInteger(+c[1])||+c[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${p}th element, array ${JSON.stringify(c,null,0)}. Its second element is not an integer, string index, but ${typeof c[1]}, equal to: ${JSON.stringify(c[1],null,4)}.`);t[p][1]=+t[p][1]}i+=1});let g=Ce(t,{progressFn:c=>{a&&(s=10+Math.floor(c/10),s!==u&&(u=s,a(s)))}});Oe(g);let n=g.length;if(n>0){let c=e.slice(g[n-1][1]);e=g.reduce((p,h,m,d)=>{a&&(s=20+Math.floor(m/n*80),s!==u&&(u=s,a(s)));let v=m===0?0:d[m-1][1],y=d[m][0];return`${p}${e.slice(v,y)}${d[m][2]||""}`},""),e+=c}return e}var Re="4.0.19";var H="&nbsp;",P="\\00A0",B="\\u00A0",Me="&ndash;",xe="\\2013",Ie="\\u2013",Le="&mdash;",Ve="\\2014",je="\\u2014",Z=[{heads:"{{",tails:"}}"},{heads:["{% if","{%- if"],tails:["{% endif","{%- endif"]},{heads:["{% for","{%- for"],tails:["{% endfor","{%- endfor"]},{heads:["{%","{%-"],tails:["%}","-%}"]},{heads:"{#",tails:"#}"}],Fe=[{heads:"{{",tails:"}}"}],z=[{heads:["<%","<%=","<%-"],tails:["%>","=%>","-%>"]}],_e=["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 at=Re,He={removeWidowPreventionMeasures:!1,convertEntities:!0,targetLanguage:"html",UKPostcodes:!1,hyphens:!0,minWordCount:4,minCharCount:5,ignore:[],reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,tagRanges:[]};function lt(e,r){var ee,te,re,ne,se,ie,oe,ae,le,ue;let a=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(r&&typeof r!="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 r}, equal to ${JSON.stringify(r,null,4)}`);let s=Array.isArray,u=e.length,t=new Ne({mergeType:2}),l=["."],i=/[A-Z]{1,2}[0-9][0-9A-Z]?$/,g=/^[0-9][A-Z]{2}/,n=.06,c,p=0,h=0,m=0,d,v,y,T,w,$,E,S,f=A(A({},He),r),W={removeWidows:!1,convertEntities:!1};if(!f.ignore||!s(f.ignore)&&typeof f.ignore!="string")f.ignore=[];else if(typeof f.ignore=="string"&&(f.ignore=[f.ignore]),f.ignore.includes("all"))f.ignore=f.ignore.concat(Z.concat(z));else if(f.ignore.some(o=>typeof o=="string")){let o=[];f.ignore=f.ignore.filter(D=>typeof D=="string"&&D.length?(["nunjucks","jinja","liquid"].includes(D.trim().toLowerCase())?o=o.concat(Z):["hugo"].includes(D.trim().toLowerCase())?o=o.concat(Fe):["hexo"].includes(D.trim().toLowerCase())&&(o=o.concat(z)),!1):typeof D=="object"),o.length&&(f.ignore=f.ignore.concat(o))}let Y;f.reportProgressFunc&&(Y=Math.floor(f.reportProgressFuncTo-(f.reportProgressFuncTo-f.reportProgressFuncFrom)*n-f.reportProgressFuncFrom));function U(o,D){let b=x;f.removeWidowPreventionMeasures?b=" ":f.convertEntities&&(b=H,typeof f.targetLanguage=="string"&&(f.targetLanguage.trim().toLowerCase()==="css"?b=P:f.targetLanguage.trim().toLowerCase()==="js"&&(b=B))),e.slice(o,D)!==b&&t.push(o,D,b)}function X(){h=0,m=0,d=void 0,v=void 0,y=void 0,T=void 0,w=void 0,$=void 0}X();for(let o=0;o<=u;o++){if(!E&&s(f.ignore)&&f.ignore.length&&f.ignore.some((b,C)=>{if(s(b.heads)&&b.heads.some(ge=>e.startsWith(ge,o))||typeof b.heads=="string"&&e.startsWith(b.heads,o))return h+=1,E=f.ignore[C].tails,!0}),!E&&S&&S===o&&(h+=1,S=void 0),typeof f.reportProgressFunc=="function"&&(c=f.reportProgressFuncFrom+Math.floor(o/u*(Y||1)),c!==p&&(p=c,f.reportProgressFunc(c))),!E&&o&&((ee=e[o])!=null&&ee.trim())&&(!e[o-1]||e[o-1]&&!e[o-1].trim())&&(T=o),!E&&((te=e[o])!=null&&te.trim())&&(m+=1),!E&&f.hyphens&&(`-${Ee}${we}`.includes(e[o])||e.startsWith(Me,o)||e.startsWith(xe,o)||e.startsWith(Ie,o)||e.startsWith(Le,o)||e.startsWith(Ve,o)||e.startsWith(je,o))&&e[o+1]&&(!e[o+1].trim()||e[o]==="&")&&e[o-1]&&!e[o-1].trim()&&e[_(e,o)]&&(U(_(e,o)+1,o),W.removeWidows=!0),!E&&(e.startsWith("&nbsp;",o)||e.startsWith("&#160;",o))&&(w=o,$=o+6,(re=e[o+6])!=null&&re.trim()&&(S=o+6),f.convertEntities?(f.targetLanguage==="css"||f.targetLanguage==="js")&&(t.push(o,o+6,f.targetLanguage==="css"?P:B),W.convertEntities=!0):(t.push(o,o+6,x),W.convertEntities=!0)),!E&&e[o+4]&&e[o]==="\\"&&e[o+1]==="0"&&e[o+2]==="0"&&e[o+3].toUpperCase()==="A"&&e[o+4]==="0"&&(w=o,$=o+5,(ne=e[o+5])!=null&&ne.trim()&&(S=o+5),f.convertEntities?(f.targetLanguage==="html"||f.targetLanguage==="js")&&(t.push(o,o+5,f.targetLanguage==="html"?H:B),W.convertEntities=!0):(t.push(o,o+5,x),W.convertEntities=!0)),!E&&e[o]==="\\"&&e[o+1]&&e[o+1].toLowerCase()==="u"&&e[o+2]==="0"&&e[o+3]==="0"&&e[o+4]&&e[o+4].toUpperCase()==="A"&&e[o+5]==="0"&&(w=o,$=o+6,(se=e[o+6])!=null&&se.trim()&&(S=o+6),f.convertEntities?(f.targetLanguage==="html"||f.targetLanguage==="css")&&t.push(o,o+6,f.targetLanguage==="html"?H:P):t.push(o,o+6,x)),!E&&e[o]===x&&(w=o,$=o+1,f.convertEntities&&t.push(o,o+1,f.targetLanguage==="css"?P:f.targetLanguage==="js"?B:H)),!E&&((ie=e[o])!=null&&ie.trim())&&!((oe=e[o-1])!=null&&oe.trim())&&(h+=1),!E&&(!e[o]||`\r

@@ -35,3 +35,3 @@ `.includes(e[o])||(e[o]===`

* @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
* @version 5.0.7
* @version 5.0.8
* @author Roy Revelt, Codsen Ltd

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

* @fileoverview Various utility functions
* @version 1.6.2
* @version 1.6.3
* @author Roy Revelt, Codsen Ltd

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

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

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

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

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

* @fileoverview Collapse the leading and trailing whitespace of a string
* @version 7.0.6
* @version 7.0.7
* @author Roy Revelt, Codsen Ltd

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

* @fileoverview Sort string index ranges
* @version 6.0.10
* @version 6.0.11
* @author Roy Revelt, Codsen Ltd

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

* @fileoverview Gather string index ranges
* @version 7.0.13
* @version 7.0.14
* @author Roy Revelt, Codsen Ltd

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

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

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

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

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

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

@@ -78,11 +78,11 @@ "keywords": [

"dependencies": {
"codsen-utils": "^1.6.2",
"ranges-apply": "^7.0.13",
"ranges-push": "^7.0.13",
"string-left-right": "^6.0.15",
"string-match-left-right": "^9.0.16"
"codsen-utils": "^1.6.3",
"ranges-apply": "^7.0.14",
"ranges-push": "^7.0.14",
"string-left-right": "^6.0.16",
"string-match-left-right": "^9.0.17"
},
"devDependencies": {
"string-strip-html": "^13.4.4"
"string-strip-html": "^13.4.5"
}
}

@@ -59,4 +59,4 @@ <h1 align="center">string-remove-widows</h1>

Copyright © 2010-2023 Roy Revelt and other contributors.
Copyright © 2010-2024 Roy Revelt and other contributors.
<p align="center"><img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center"></p>

Sorry, the diff of this file is not supported yet

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