hyperbuild 0.0.43 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13f6bc841f3244550cd7757709fed9405e450fe6446b8a0722548596739b2f7c
4
- data.tar.gz: 676dc872075403abf309021820c2057dd386c71c03e5119aba92e0b17551a837
3
+ metadata.gz: ae9df977339decdd91315a657eaf93b7cc5d3d5baf3d151baa1c8765cec50a54
4
+ data.tar.gz: 1162609f080717dda0b870ff8a02c750a9f975a116256a7cf70976bd830f0b9c
5
5
  SHA512:
6
- metadata.gz: eba2fe40c60af99d2c032e0d57c9da0cef85e46930cca1664b9a29a333d0c5dd71305079b2eb48e826178832381784eb3419c07eb319ae2fb434c57d5d9a5721
7
- data.tar.gz: 82956e71a245a7788bb08bed7e51f7b288b76841f2e9bd4048b4d71e458331e0dae5841cabecf716ce3337cf7b00c5b1b5698ceb9de2faaf950a9eeac3aed0c3
6
+ metadata.gz: bd32cdf147710950a6fda57a423734662d3cbe1bf090b0b2e64136bdfc5b178c7d2c0af581aa44eb709fc74dbd951a255f41ff849310dcfca30f72e18480cdc9
7
+ data.tar.gz: deca3b2b2c2bdc1f5450a1b33ed4a07a4a23e7a9a70fc8f29c059c41c33d4d149eac58f8ba1b938086dfdc1fd9c728d33e055d4a62ab154cbbd7f8dbd2b70074
data/README.md CHANGED
@@ -15,21 +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.43/average-speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.0.43/average-sizes.png">
20
+ <img width="435" alt="Chart showing speed of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.1.4/average-speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.1.4/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. To compile and install from source, run `cargo install hyperbuild`, which requires [Rust](https://www.rust-lang.org/tools/install).
26
+ Precompiled binaries are available for x86-64 Windows, macOS, and Linux.
27
27
 
28
28
  ##### Get
29
29
 
30
- [Windows](https://wilsonl.in/hyperbuild/bin/0.0.43-windows-x86_64.exe) |
31
- [macOS](https://wilsonl.in/hyperbuild/bin/0.0.43-macos-x86_64) |
32
- [Linux](https://wilsonl.in/hyperbuild/bin/0.0.43-linux-x86_64)
30
+ [Windows](https://wilsonl.in/hyperbuild/bin/0.1.4-windows-x86_64.exe) |
31
+ [macOS](https://wilsonl.in/hyperbuild/bin/0.1.4-macos-x86_64) |
32
+ [Linux](https://wilsonl.in/hyperbuild/bin/0.1.4-linux-x86_64)
33
33
 
34
34
  ##### Use
35
35
 
@@ -46,19 +46,48 @@ hyperbuild --src /path/to/src.html --out /path/to/output.min.html
46
46
 
47
47
  ```toml
48
48
  [dependencies]
49
- hyperbuild = "0.0.43"
49
+ hyperbuild = "0.1.4"
50
50
  ```
51
51
 
52
52
  ##### Use
53
53
 
54
54
  ```rust
55
- use hyperbuild::hyperbuild;
55
+ use hyperbuild::{FriendlyError, hyperbuild};
56
56
 
57
57
  fn main() {
58
58
  let mut code = b"<p> Hello, world! </p>".to_vec();
59
+
60
+ // Minifies a slice in-place and returns the new minified length,
61
+ // but leaves any original code after the minified code intact.
59
62
  match hyperbuild(&mut code) {
60
63
  Ok(minified_len) => {}
61
- Err((error_type, error_at_char_no)) => {}
64
+ Err((error_type, error_position)) => {}
65
+ };
66
+
67
+ // Creates a vector copy containing only minified code
68
+ // instead of minifying in-place.
69
+ match hyperbuild_copy(&code) {
70
+ Ok(minified) => {}
71
+ Err((error_type, error_position)) => {}
72
+ };
73
+
74
+ // Minifies a vector in-place, and then truncates the
75
+ // vector to the new minified length.
76
+ match hyperbuild_truncate(&mut code) {
77
+ Ok(()) => {}
78
+ Err((error_type, error_position)) => {}
79
+ };
80
+
81
+ // Identical to `hyperbuild` except with FriendlyError instead.
82
+ // `code_context` is a string of a visual representation of the source,
83
+ // with line numbers and position markers to aid in debugging syntax.
84
+ match hyperbuild_friendly_error(&mut code) {
85
+ Ok(minified_len) => {}
86
+ Err(FriendlyError { position, message, code_context }) => {
87
+ eprintln!("Failed at character {}:", position);
88
+ eprintln!("{}", message);
89
+ eprintln!("{}", code_context);
90
+ }
62
91
  };
63
92
  }
64
93
  ```
@@ -90,6 +119,20 @@ yarn add hyperbuild
90
119
  const hyperbuild = require("hyperbuild");
91
120
 
92
121
  const minified = hyperbuild.minify("<p> Hello, world! </p>");
122
+
123
+ // Alternatively, minify in place to avoid copying.
124
+ const source = Buffer.from("<p> Hello, world! </p>");
125
+ hyperbuild.minifyInPlace(source);
126
+ ```
127
+
128
+ hyperbuild is also available for TypeScript:
129
+
130
+ ```ts
131
+ import * as hyperbuild from "hyperbuild";
132
+ import * as fs from "fs";
133
+
134
+ const minified = hyperbuild.minify("<p> Hello, world! </p>");
135
+ hyperbuild.minifyInPlace(fs.readFileSync("source.html"));
93
136
  ```
94
137
 
95
138
  </details>
@@ -107,7 +150,7 @@ Add as a Maven dependency:
107
150
  <dependency>
108
151
  <groupId>in.wilsonl.hyperbuild</groupId>
109
152
  <artifactId>hyperbuild</artifactId>
110
- <version>0.0.43</version>
153
+ <version>0.1.4</version>
111
154
  </dependency>
112
155
  ```
113
156
 
@@ -116,11 +159,15 @@ Add as a Maven dependency:
116
159
  ```java
117
160
  import in.wilsonl.hyperbuild.Hyperbuild;
118
161
 
119
- class Main {
120
- public static void main(String[] args) {
121
- String minified = Hyperbuild.minify("<p> Hello, world! </p>");
122
- }
162
+ try {
163
+ String minified = Hyperbuild.minify("<p> Hello, world! </p>");
164
+ } catch (Hyperbuild.SyntaxException e) {
165
+ System.err.println(e.getMessage());
123
166
  }
167
+
168
+ // Alternatively, minify in place:
169
+ assert source instanceof ByteBuffer && source.isDirect();
170
+ Hyperbuild.minifyInPlace(source);
124
171
  ```
125
172
 
126
173
  </details>
@@ -139,7 +186,10 @@ Add the PyPI project as a dependency and install it using `pip` or `pipenv`.
139
186
  ```python
140
187
  import hyperbuild
141
188
 
142
- minified = hyperbuild.minify("<p> Hello, world! </p>")
189
+ try:
190
+ minified = hyperbuild.minify("<p> Hello, world! </p>")
191
+ except SyntaxError as e:
192
+ print(e)
143
193
  ```
144
194
 
145
195
  </details>
@@ -165,6 +215,10 @@ print Hyperbuild.minify "

Hello, world!

"
165
215
 
166
216
  ## Minification
167
217
 
218
+ ### Configurability
219
+
220
+ Configuration of minification is currently WIP across all languages. The behaviour mentioned below is the default.
221
+
168
222
  ### Whitespace
169
223
 
170
224
  hyperbuild has advanced context-aware whitespace minification that does things such as:
@@ -208,7 +262,7 @@ Reduce a sequence of whitespace characters in text nodes to a single space (U+00
208
262
 
209
263
  > **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.
210
264
 
211
- Remove any text nodes that only consist of whitespace characters.
265
+ Remove any text nodes between tags that only consist of whitespace characters.
212
266
 
213
267
  <table><thead><tr><th>Before<th>After<tbody><tr><td>
214
268
 
@@ -383,10 +437,10 @@ Spaces are removed between attributes if possible.
383
437
  Entities are decoded if valid (see relevant parsing section) and their decoded characters as UTF-8 is shorter or equal in length.
384
438
 
385
439
  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).
386
-
440
+
387
441
  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`.
388
442
 
389
- Right chevrons after any decoding in text are encoded to `&GT` if possible or `&GT;` otherwise.
443
+ Left chevrons after any decoding in text are encoded to `&LT` if possible or `&LT;` otherwise.
390
444
 
391
445
  ### Comments
392
446
 
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.43
4
+ version: 0.1.4
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-31 00:00:00.000000000 Z
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fiddle