html-crush 5.0.10 → 5.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +2 -6
- package/dist/html-crush.esm.js +2 -2
- package/dist/html-crush.umd.js +11 -11
- package/package.json +10 -8
- package/types/index.d.ts +26 -24
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010-
|
|
3
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/README.md
CHANGED
|
@@ -26,14 +26,12 @@
|
|
|
26
26
|
|
|
27
27
|
## Install
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `4.2.0`.
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
npm i html-crush
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
If you need a legacy version which works with `require`, use version 4.2.0
|
|
36
|
-
|
|
37
35
|
## Quick Take
|
|
38
36
|
|
|
39
37
|
```js
|
|
@@ -69,8 +67,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
|
|
|
69
67
|
|
|
70
68
|
MIT License
|
|
71
69
|
|
|
72
|
-
Copyright (c) 2010-
|
|
73
|
-
|
|
70
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
74
71
|
|
|
75
72
|
<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">
|
|
76
|
-
|
package/dist/html-crush.esm.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name html-crush
|
|
3
3
|
* @fileoverview Minifies HTML/CSS: valid or broken, pure or mixed with other languages
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/html-crush/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import{rApply as ne}from"ranges-apply";import{Ranges as le}from"ranges-push";import{matchLeft as oe,matchRight as F,matchRightIncl as X}from"string-match-left-right";import{expander as _}from"string-range-expander";import{left as G,right as a}from"string-left-right";var Y="5.0.
|
|
10
|
+
import{rApply as ne}from"ranges-apply";import{Ranges as le}from"ranges-push";import{matchLeft as oe,matchRight as F,matchRightIncl as X}from"string-match-left-right";import{expander as _}from"string-range-expander";import{left as G,right as a}from"string-left-right";var Y="5.0.11";var ge=Y,$=new le({limitToBeAddedWhitespace:!0}),te={lineLengthLimit:500,removeIndentations:!0,removeLineBreaks:!1,removeHTMLComments:!1,removeCSSComments:!0,reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,breakToTheLeftOf:["</td","<html","</html","<head","</head","<meta","<link","<table","<script","<\/script","<!DOCTYPE","<style","</style","<title","<body","@media","</body","<!--[if","<!--<![endif","<![endif]"],mindTheInlineTags:["a","abbr","acronym","audio","b","bdi","bdo","big","br","button","canvas","cite","code","data","datalist","del","dfn","em","embed","i","iframe","img","input","ins","kbd","label","map","mark","meter","noscript","object","output","picture","progress","q","ruby","s","samp","script","select","slot","small","span","strong","sub","sup","svg","template","textarea","time","u","tt","var","video","wbr"]};function y(n){return typeof n=="string"}function A(n){return typeof n=="string"&&n.toUpperCase()!==n.toLowerCase()}function ce(n,E){let W=Date.now();if(!y(n))throw n===void 0?new Error("html-crush: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`html-crush: [THROW_ID_02] the first input argument must be string! It was given as "${typeof n}", equal to:
|
|
11
11
|
${JSON.stringify(n,null,4)}`);if(E&&typeof E!="object")throw new Error(`html-crush: [THROW_ID_03] the second input argument, options object, should be a plain object but it was given as type ${typeof E}, equal to ${JSON.stringify(E,null,4)}`);if(E&&Array.isArray(E.breakToTheLeftOf)&&E.breakToTheLeftOf.length){for(let e=0,w=E.breakToTheLeftOf.length;e<w;e++)if(!y(E.breakToTheLeftOf[e]))throw new TypeError(`html-crush: [THROW_ID_05] the opts.breakToTheLeftOf array contains non-string elements! For example, element at index ${e} is of a type "${typeof E.breakToTheLeftOf[e]}" and is equal to:
|
|
12
12
|
${JSON.stringify(E.breakToTheLeftOf[e],null,4)}`)}let l={...te,...E};typeof l.removeHTMLComments=="boolean"&&(l.removeHTMLComments=l.removeHTMLComments?1:0);let H="";Array.isArray(l.breakToTheLeftOf)&&l.breakToTheLeftOf.length&&(H=[...new Set(l.breakToTheLeftOf.map(e=>e[0]))].join(""));let D={removeHTMLComments:!1,removeCSSComments:!1},S=null,i=null,p=!1,m=0,M=0,g=!1,V=!1,c=null,f=null,C=null,U=null,s,t=null,u=null,r=null,T=null,L=null,v=null,P=">};",I="<",K="!",q=">",z="<",B="{},:;<>~+",k=B,J=B,O=!0,h=n.length,Q=Math.floor(h/2),x=.01,j;l.reportProgressFunc&&(j=Math.floor(l.reportProgressFuncTo-(l.reportProgressFuncTo-l.reportProgressFuncFrom)*x-l.reportProgressFuncFrom));let d,R=0,b=`
|
|
13
13
|
`;if(n.includes(`\r
|
package/dist/html-crush.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name html-crush
|
|
3
3
|
* @fileoverview Minifies HTML/CSS: valid or broken, pure or mixed with other languages
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/html-crush/}
|
|
@@ -24,7 +24,7 @@ ${JSON.stringify(a.ifLeftSideIncludesThisThenCropTightly,null,4)}. Now, that arr
|
|
|
24
24
|
\r`.includes(e[a])||n&&e[a]===K)return a;return null}function D(e,t=0){return li({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function si({str:e,idx:t,stopAtNewlines:r,stopAtRawNbsp:n}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),t<1))return null;if(e[~-t]&&(e[~-t].trim()||r&&`
|
|
25
25
|
\r`.includes(e[~-t])||n&&e[~-t]===K))return~-t;if(e[t-2]&&(e[t-2].trim()||r&&`
|
|
26
26
|
\r`.includes(e[t-2])||n&&e[t-2]===K))return t-2;for(let a=t;a--;)if(e[a]&&(e[a].trim()||r&&`
|
|
27
|
-
\r`.includes(e[a])||n&&e[a]===K))return a;return null}function be(e,t=0){return si({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}var Zt="5.0.
|
|
27
|
+
\r`.includes(e[a])||n&&e[a]===K))return a;return null}function be(e,t=0){return si({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}var Zt="5.0.11";var ui=Zt,y=new tt({limitToBeAddedWhitespace:!0}),Qt={lineLengthLimit:500,removeIndentations:!0,removeLineBreaks:!1,removeHTMLComments:!1,removeCSSComments:!0,reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,breakToTheLeftOf:["</td","<html","</html","<head","</head","<meta","<link","<table","<script","<\/script","<!DOCTYPE","<style","</style","<title","<body","@media","</body","<!--[if","<!--<![endif","<![endif]"],mindTheInlineTags:["a","abbr","acronym","audio","b","bdi","bdo","big","br","button","canvas","cite","code","data","datalist","del","dfn","em","embed","i","iframe","img","input","ins","kbd","label","map","mark","meter","noscript","object","output","picture","progress","q","ruby","s","samp","script","select","slot","small","span","strong","sub","sup","svg","template","textarea","time","u","tt","var","video","wbr"]};function Y(e){return typeof e=="string"}function X(e){return typeof e=="string"&&e.toUpperCase()!==e.toLowerCase()}function gi(e,t){var fi;let r=Date.now();if(!Y(e))throw e===void 0?new Error("html-crush: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`html-crush: [THROW_ID_02] the first input argument must be string! It was given as "${typeof e}", equal to:
|
|
28
28
|
${JSON.stringify(e,null,4)}`);if(t&&typeof t!="object")throw new Error(`html-crush: [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)}`);if(t&&Array.isArray(t.breakToTheLeftOf)&&t.breakToTheLeftOf.length){for(let i=0,Q=t.breakToTheLeftOf.length;i<Q;i++)if(!Y(t.breakToTheLeftOf[i]))throw new TypeError(`html-crush: [THROW_ID_05] the opts.breakToTheLeftOf array contains non-string elements! For example, element at index ${i} is of a type "${typeof t.breakToTheLeftOf[i]}" and is equal to:
|
|
29
29
|
${JSON.stringify(t.breakToTheLeftOf[i],null,4)}`)}let n=S(S({},Qt),t);typeof n.removeHTMLComments=="boolean"&&(n.removeHTMLComments=n.removeHTMLComments?1:0);let a="";Array.isArray(n.breakToTheLeftOf)&&n.breakToTheLeftOf.length&&(a=[...new Set(n.breakToTheLeftOf.map(i=>i[0]))].join(""));let o={removeHTMLComments:!1,removeCSSComments:!1},u=null,s=null,c=!1,l=0,$=0,h=!1,T=!1,m=null,f=null,O=null,L=null,p,b=null,d=null,E=null,A=null,I=null,V=null,z=">};",Z="<",en="!",tn=">",nn="<",We="{},:;<>~+",de=We,Te=We,J=!0,_=e.length,rn=Math.floor(_/2),Je=.01,je;n.reportProgressFunc&&(je=Math.floor(n.reportProgressFuncTo-(n.reportProgressFuncTo-n.reportProgressFuncFrom)*Je-n.reportProgressFuncFrom));let R,oe=0,C=`
|
|
30
30
|
`;if(e.includes(`\r
|
|
@@ -42,7 +42,7 @@ ${JSON.stringify(t.breakToTheLeftOf[i],null,4)}`)}let n=S(S({},Qt),t);typeof n.r
|
|
|
42
42
|
/**
|
|
43
43
|
* @name arrayiffy-if-string
|
|
44
44
|
* @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
|
|
45
|
-
* @version 4.0.
|
|
45
|
+
* @version 4.0.11
|
|
46
46
|
* @author Roy Revelt, Codsen Ltd
|
|
47
47
|
* @license MIT
|
|
48
48
|
* {@link https://codsen.com/os/arrayiffy-if-string/}
|
|
@@ -50,7 +50,7 @@ ${JSON.stringify(t.breakToTheLeftOf[i],null,4)}`)}let n=S(S({},Qt),t);typeof n.r
|
|
|
50
50
|
/**
|
|
51
51
|
* @name ranges-apply
|
|
52
52
|
* @fileoverview Take an array of string index ranges, delete/replace the string according to them
|
|
53
|
-
* @version 6.0.
|
|
53
|
+
* @version 6.0.11
|
|
54
54
|
* @author Roy Revelt, Codsen Ltd
|
|
55
55
|
* @license MIT
|
|
56
56
|
* {@link https://codsen.com/os/ranges-apply/}
|
|
@@ -58,7 +58,7 @@ ${JSON.stringify(t.breakToTheLeftOf[i],null,4)}`)}let n=S(S({},Qt),t);typeof n.r
|
|
|
58
58
|
/**
|
|
59
59
|
* @name ranges-merge
|
|
60
60
|
* @fileoverview Merge and sort string index ranges
|
|
61
|
-
* @version 8.0.
|
|
61
|
+
* @version 8.0.11
|
|
62
62
|
* @author Roy Revelt, Codsen Ltd
|
|
63
63
|
* @license MIT
|
|
64
64
|
* {@link https://codsen.com/os/ranges-merge/}
|
|
@@ -66,7 +66,7 @@ ${JSON.stringify(t.breakToTheLeftOf[i],null,4)}`)}let n=S(S({},Qt),t);typeof n.r
|
|
|
66
66
|
/**
|
|
67
67
|
* @name ranges-push
|
|
68
68
|
* @fileoverview Gather string index ranges
|
|
69
|
-
* @version 6.0.
|
|
69
|
+
* @version 6.0.11
|
|
70
70
|
* @author Roy Revelt, Codsen Ltd
|
|
71
71
|
* @license MIT
|
|
72
72
|
* {@link https://codsen.com/os/ranges-push/}
|
|
@@ -74,7 +74,7 @@ ${JSON.stringify(t.breakToTheLeftOf[i],null,4)}`)}let n=S(S({},Qt),t);typeof n.r
|
|
|
74
74
|
/**
|
|
75
75
|
* @name ranges-sort
|
|
76
76
|
* @fileoverview Sort string index ranges
|
|
77
|
-
* @version 5.0.
|
|
77
|
+
* @version 5.0.11
|
|
78
78
|
* @author Roy Revelt, Codsen Ltd
|
|
79
79
|
* @license MIT
|
|
80
80
|
* {@link https://codsen.com/os/ranges-sort/}
|
|
@@ -82,7 +82,7 @@ ${JSON.stringify(t.breakToTheLeftOf[i],null,4)}`)}let n=S(S({},Qt),t);typeof n.r
|
|
|
82
82
|
/**
|
|
83
83
|
* @name string-collapse-leading-whitespace
|
|
84
84
|
* @fileoverview Collapse the leading and trailing whitespace of a string
|
|
85
|
-
* @version 6.0.
|
|
85
|
+
* @version 6.0.11
|
|
86
86
|
* @author Roy Revelt, Codsen Ltd
|
|
87
87
|
* @license MIT
|
|
88
88
|
* {@link https://codsen.com/os/string-collapse-leading-whitespace/}
|
|
@@ -90,7 +90,7 @@ ${JSON.stringify(t.breakToTheLeftOf[i],null,4)}`)}let n=S(S({},Qt),t);typeof n.r
|
|
|
90
90
|
/**
|
|
91
91
|
* @name string-left-right
|
|
92
92
|
* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
|
|
93
|
-
* @version 5.0.
|
|
93
|
+
* @version 5.0.11
|
|
94
94
|
* @author Roy Revelt, Codsen Ltd
|
|
95
95
|
* @license MIT
|
|
96
96
|
* {@link https://codsen.com/os/string-left-right/}
|
|
@@ -98,7 +98,7 @@ ${JSON.stringify(t.breakToTheLeftOf[i],null,4)}`)}let n=S(S({},Qt),t);typeof n.r
|
|
|
98
98
|
/**
|
|
99
99
|
* @name string-match-left-right
|
|
100
100
|
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
|
|
101
|
-
* @version 8.0.
|
|
101
|
+
* @version 8.0.11
|
|
102
102
|
* @author Roy Revelt, Codsen Ltd
|
|
103
103
|
* @license MIT
|
|
104
104
|
* {@link https://codsen.com/os/string-match-left-right/}
|
|
@@ -106,7 +106,7 @@ ${JSON.stringify(t.breakToTheLeftOf[i],null,4)}`)}let n=S(S({},Qt),t);typeof n.r
|
|
|
106
106
|
/**
|
|
107
107
|
* @name string-range-expander
|
|
108
108
|
* @fileoverview Expands string index ranges within whitespace boundaries until letters are met
|
|
109
|
-
* @version 3.0.
|
|
109
|
+
* @version 3.0.11
|
|
110
110
|
* @author Roy Revelt, Codsen Ltd
|
|
111
111
|
* @license MIT
|
|
112
112
|
* {@link https://codsen.com/os/string-range-expander/}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-crush",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.11",
|
|
4
4
|
"description": "Minifies HTML/CSS: valid or broken, pure or mixed with other languages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"breaks",
|
|
@@ -45,13 +45,15 @@
|
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
47
47
|
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
48
|
-
"dts": "rollup -c",
|
|
48
|
+
"dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
|
|
49
49
|
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
50
50
|
"lect": "node '../../ops/lect/lect.js'",
|
|
51
51
|
"letspublish": "yarn publish || :",
|
|
52
52
|
"lint": "eslint . --fix",
|
|
53
53
|
"perf": "node perf/check.js",
|
|
54
54
|
"prepare": "echo 'ready'",
|
|
55
|
+
"prettier": "prettier",
|
|
56
|
+
"prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
|
|
55
57
|
"pretest": "yarn run lect && yarn run build",
|
|
56
58
|
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
57
59
|
"unit": "uvu test"
|
|
@@ -74,11 +76,11 @@
|
|
|
74
76
|
}
|
|
75
77
|
},
|
|
76
78
|
"dependencies": {
|
|
77
|
-
"ranges-apply": "^6.0.
|
|
78
|
-
"ranges-push": "^6.0.
|
|
79
|
-
"string-left-right": "^5.0.
|
|
80
|
-
"string-match-left-right": "^8.0.
|
|
81
|
-
"string-range-expander": "^3.0.
|
|
82
|
-
"test-mixer": "^3.0.
|
|
79
|
+
"ranges-apply": "^6.0.11",
|
|
80
|
+
"ranges-push": "^6.0.11",
|
|
81
|
+
"string-left-right": "^5.0.11",
|
|
82
|
+
"string-match-left-right": "^8.0.11",
|
|
83
|
+
"string-range-expander": "^3.0.11",
|
|
84
|
+
"test-mixer": "^3.0.11"
|
|
83
85
|
}
|
|
84
86
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
|
-
declare type Range =
|
|
1
|
+
declare type Range =
|
|
2
|
+
| [from: number, to: number]
|
|
3
|
+
| [from: number, to: number, whatToInsert: string | null | undefined];
|
|
2
4
|
declare type Ranges = Range[] | null;
|
|
3
5
|
|
|
4
6
|
declare const version: string;
|
|
5
7
|
interface Opts {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
lineLengthLimit: number;
|
|
9
|
+
removeIndentations: boolean;
|
|
10
|
+
removeLineBreaks: boolean;
|
|
11
|
+
removeHTMLComments: boolean | 0 | 1 | 2;
|
|
12
|
+
removeCSSComments: boolean;
|
|
13
|
+
reportProgressFunc: null | ((percDone: number) => void);
|
|
14
|
+
reportProgressFuncFrom: number;
|
|
15
|
+
reportProgressFuncTo: number;
|
|
16
|
+
breakToTheLeftOf: string[];
|
|
17
|
+
mindTheInlineTags: string[];
|
|
16
18
|
}
|
|
17
19
|
declare const defaults: Opts;
|
|
18
20
|
interface Res {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
log: {
|
|
22
|
+
timeTakenInMilliseconds: number;
|
|
23
|
+
originalLength: number;
|
|
24
|
+
cleanedLength: number;
|
|
25
|
+
bytesSaved: number;
|
|
26
|
+
percentageReducedOfOriginal: number;
|
|
27
|
+
};
|
|
28
|
+
applicableOpts: {
|
|
29
|
+
removeHTMLComments: boolean;
|
|
30
|
+
removeCSSComments: boolean;
|
|
31
|
+
};
|
|
32
|
+
ranges: Ranges;
|
|
33
|
+
result: string;
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* Minifies HTML/CSS: valid or broken, pure or mixed with other languages
|