hyperbuild 0.0.39 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf76b6eba2f31e29ec7710592cc2c4fd352c7aa4e443a5628483063a9236275d
4
- data.tar.gz: 852918eb82dc5156f6ca7a0daa39c900fd8fa3bdd71bf0f6382a7c484684401a
3
+ metadata.gz: 1caffe6030b630477a348d3ec79ff73b6f67b1abbab3caff22a7cba2252da378
4
+ data.tar.gz: 29c61e146de8f1ca6084879d6dbf50168fbc9cf7cd5019f22699df3a2f2bf751
5
5
  SHA512:
6
- metadata.gz: 21e6b993e37b16f0e2e00176796d3a1cc6e413c93e760b38c96869b3787a725cf809e44188d7e9cc68654a700754986f93788dfbeacae9b7024fe18dbde0fa9e
7
- data.tar.gz: 2d9eef71e0076b4a01a016cb4283c932fc61204bc8f4f89e981077076c01e7d69ed6d5607cce35a70bb19cb23c40126e20a8cf9751881bb70f1d09d856ee5beb
6
+ metadata.gz: 13bb7e4921171a136092018227b8b77a3d64599844c19cc7f6e835f9f47a3b5776660c49c13bffadbc68409b10fb7d6eb559f6c650f152d67f18e2650f1e9db2
7
+ data.tar.gz: 1e0b9c28914954a37a2dabc64544f876c7ab718408a8942d5aeff5781e4625002bb730e9707a768e5aca0f28b0fa9ca83397b5cb9b3154cfcf3c1b53b7d74941
data/README.md CHANGED
@@ -15,19 +15,21 @@ Available as:
15
15
 
16
16
  ## Performance
17
17
 
18
- Speed and effectiveness of Node.js version compared to [html-minfier](https://github.com/kangax/html-minifier) and [minimize](https://github.com/Swaagie/minimize). See [bench](./bench) folder for more details.
18
+ Speed and effectiveness of Node.js version compared to [html-minfier](https://github.com/kangax/html-minifier) and [minimize](https://github.com/Swaagie/minimize), run on popular already-minified web pages. See [bench](./bench) folder for more details.
19
19
 
20
- <img width="435" alt="Chart showing speed of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.0.39/average-speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.0.39/average-sizes.png">
20
+ <img width="435" alt="Chart showing speed of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.1.1/average-speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.1.1/average-sizes.png">
21
21
 
22
22
  ## Usage
23
23
 
24
24
  ### CLI
25
25
 
26
+ Precompiled binaries are available for x86-64 Windows, macOS, and Linux.
27
+
26
28
  ##### Get
27
29
 
28
- [Windows](https://wilsonl.in/hyperbuild/bin/0.0.39-windows-x86_64.exe) |
29
- [macOS](https://wilsonl.in/hyperbuild/bin/0.0.39-macos-x86_64) |
30
- [Linux](https://wilsonl.in/hyperbuild/bin/0.0.39-linux-x86_64)
30
+ [Windows](https://wilsonl.in/hyperbuild/bin/0.1.1-windows-x86_64.exe) |
31
+ [macOS](https://wilsonl.in/hyperbuild/bin/0.1.1-macos-x86_64) |
32
+ [Linux](https://wilsonl.in/hyperbuild/bin/0.1.1-linux-x86_64)
31
33
 
32
34
  ##### Use
33
35
 
@@ -44,7 +46,7 @@ hyperbuild --src /path/to/src.html --out /path/to/output.min.html
44
46
 
45
47
  ```toml
46
48
  [dependencies]
47
- hyperbuild = "0.0.39"
49
+ hyperbuild = "0.1.1"
48
50
  ```
49
51
 
50
52
  ##### Use
@@ -54,9 +56,34 @@ use hyperbuild::hyperbuild;
54
56
 
55
57
  fn main() {
56
58
  let mut code = b"<p> Hello, world! </p>".to_vec();
59
+
60
+ // `hyperbuild` minifies a slice in-place and returns the new minified length, but leaves any original code after the minified code intact.
57
61
  match hyperbuild(&mut code) {
58
62
  Ok(minified_len) => {}
59
- Err((error_type, error_at_char_no)) => {}
63
+ Err((error_type, error_position)) => {}
64
+ };
65
+
66
+ // `hyperbuild_copy` creates a vector copy containing only minified code instead of minifying in-place.
67
+ match hyperbuild_copy(&code) {
68
+ Ok(minified) => {}
69
+ Err((error_type, error_position)) => {}
70
+ };
71
+
72
+ // `hyperbuild_truncate` minifies a vector in-place, and then truncates the vector to the new minified length.
73
+ match hyperbuild_truncate(&mut code) {
74
+ Ok(()) => {}
75
+ Err((error_type, error_position)) => {}
76
+ };
77
+
78
+ // `hyperbuild_friendly_error` is identical to `hyperbuild` except the error is a FriendlyError instead.
79
+ // `code_context` is a string of a visual representation of the source code with line numbers and position markers to aid in debugging syntax issues, and should be printed.
80
+ match hyperbuild_friendly_error(&mut code) {
81
+ Ok(minified_len) => {}
82
+ Err(FriendlyError { position, message, code_context }) => {
83
+ eprintln!("Failed at character {}:", position);
84
+ eprintln!("{}", message);
85
+ eprintln!("{}", code_context);
86
+ }
60
87
  };
61
88
  }
62
89
  ```
@@ -88,6 +115,20 @@ yarn add hyperbuild
88
115
  const hyperbuild = require("hyperbuild");
89
116
 
90
117
  const minified = hyperbuild.minify("<p> Hello, world! </p>");
118
+
119
+ // Alternatively, minify in place to avoid copying.
120
+ const source = Buffer.from("<p> Hello, world! </p>");
121
+ hyperbuild.minifyInPlace(source);
122
+ ```
123
+
124
+ hyperbuild is also available for TypeScript:
125
+
126
+ ```ts
127
+ import * as hyperbuild from "hyperbuild";
128
+ import * as fs from "fs";
129
+
130
+ const minified = hyperbuild.minify("<p> Hello, world! </p>");
131
+ hyperbuild.minifyInPlace(fs.readFileSync("source.html"));
91
132
  ```
92
133
 
93
134
  </details>
@@ -105,7 +146,7 @@ Add as a Maven dependency:
105
146
  <dependency>
106
147
  <groupId>in.wilsonl.hyperbuild</groupId>
107
148
  <artifactId>hyperbuild</artifactId>
108
- <version>0.0.39</version>
149
+ <version>0.1.1</version>
109
150
  </dependency>
110
151
  ```
111
152
 
@@ -114,11 +155,15 @@ Add as a Maven dependency:
114
155
  ```java
115
156
  import in.wilsonl.hyperbuild.Hyperbuild;
116
157
 
117
- class Main {
118
- public static void main(String[] args) {
119
- String minified = Hyperbuild.minify("<p> Hello, world! </p>");
120
- }
158
+ try {
159
+ String minified = Hyperbuild.minify("<p> Hello, world! </p>");
160
+ } catch (Hyperbuild.SyntaxException e) {
161
+ System.err.println(e.getMessage());
121
162
  }
163
+
164
+ // Alternatively, minify in place:
165
+ assert source instanceof ByteBuffer && source.isDirect();
166
+ Hyperbuild.minifyInPlace(source);
122
167
  ```
123
168
 
124
169
  </details>
@@ -137,7 +182,10 @@ Add the PyPI project as a dependency and install it using `pip` or `pipenv`.
137
182
  ```python
138
183
  import hyperbuild
139
184
 
140
- minified = hyperbuild.minify("<p> Hello, world! </p>")
185
+ try:
186
+ minified = hyperbuild.minify("<p> Hello, world! </p>")
187
+ except SyntaxError as e:
188
+ print(e)
141
189
  ```
142
190
 
143
191
  </details>
@@ -163,6 +211,10 @@ print Hyperbuild.minify "

Hello, world!

"
163
211
 
164
212
  ## Minification
165
213
 
214
+ ### Configurability
215
+
216
+ Configuration of minification is currently WIP across all languages. The behaviour mentioned below is the default.
217
+
166
218
  ### Whitespace
167
219
 
168
220
  hyperbuild has advanced context-aware whitespace minification that does things such as:
@@ -206,7 +258,7 @@ Reduce a sequence of whitespace characters in text nodes to a single space (U+00
206
258
 
207
259
  > **Applies to:** any element except [whitespace sensitive](./src/spec/tag/whitespace.rs), [content](src/spec/tag/whitespace.rs), [content-first](./src/spec/tag/whitespace.rs), and [formatting](./src/spec/tag/whitespace.rs) elements.
208
260
 
209
- Remove any text nodes that only consist of whitespace characters.
261
+ Remove any text nodes between tags that only consist of whitespace characters.
210
262
 
211
263
  <table><thead><tr><th>Before<th>After<tbody><tr><td>
212
264
 
@@ -381,10 +433,10 @@ Spaces are removed between attributes if possible.
381
433
  Entities are decoded if valid (see relevant parsing section) and their decoded characters as UTF-8 is shorter or equal in length.
382
434
 
383
435
  Numeric entities that do not refer to a valid [Unicode Scalar Value](https://www.unicode.org/glossary/#unicode_scalar_value) are replaced with the [replacement character](https://en.wikipedia.org/wiki/Specials_(Unicode_block)#Replacement_character).
384
-
436
+
385
437
  If an entity is unintentionally formed after decoding, the leading ampersand is encoded, e.g. `&&#97;&#109;&#112;;` becomes `&ampamp;`. This is done as `&amp` is equal to or shorter than all other entity representations of characters part of an entity (`[&#a-zA-Z0-9;]`), and there is no other conflicting entity name that starts with `amp`.
386
438
 
387
- Right chevrons after any decoding in text are encoded to `&GT` if possible or `&GT;` otherwise.
439
+ Left chevrons after any decoding in text are encoded to `&LT` if possible or `&LT;` otherwise.
388
440
 
389
441
  ### Comments
390
442
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperbuild
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.39
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilson Lin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-26 00:00:00.000000000 Z
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fiddle