hyperbuild 0.0.40 → 0.1.2

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: 9f2a6102a9052622a2adcb638efc16b689bec1a2cc081fd1c99aa682536f7707
4
- data.tar.gz: 691368c264d4637f41f8b6248b1f902dfd2f5de08dda4d297d49680c169ca8b5
3
+ metadata.gz: 7bb6f0f8e73f9613317562e0a3daf1fa0b9d67f21bb659759d67b65f0cecf573
4
+ data.tar.gz: 33dab007c631e2f7fbe465c104185c900a7b05c33eaffe837ed77aad70e04599
5
5
  SHA512:
6
- metadata.gz: 3742bc67d08738a164c6f96a9e77570b3894d3cd2ff1d40d5cf5ee97abf67e3dc95038976c57467eaa2002d2a0b0e48b4e4273e3049fff4aafc9bcb420b4ca8c
7
- data.tar.gz: 4bcc6a195bc70b374cc628058d6789dcf0b700f2a15cf9dfd5b469e4defd5e756ef26436e32a1e3f75cba2dedc4140856220f9141bd7d923cad40a70d021e0e7
6
+ metadata.gz: 379e7d4f40fe1d42f0771ade0a09f9bf902aa5cfd0e6eeb6a92a7b7fb6b9da13dbe082724d6dd6485ddce9e9d85b90f8f85d68910fb83cf4a1961266c819df54
7
+ data.tar.gz: d90bc35584be1022996380f4e8a06782a8801ef94dd680f8e87677095277cbdd8b23c29cc7bf60aef427ed8795a5baec6ca9a2e08f8be1ab2997335f487932fb
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.40/average-speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.0.40/average-sizes.png">
20
+ <img width="435" alt="Chart showing speed of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.1.2/average-speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.1.2/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.40-windows-x86_64.exe) |
31
- [macOS](https://wilsonl.in/hyperbuild/bin/0.0.40-macos-x86_64) |
32
- [Linux](https://wilsonl.in/hyperbuild/bin/0.0.40-linux-x86_64)
30
+ [Windows](https://wilsonl.in/hyperbuild/bin/0.1.2-windows-x86_64.exe) |
31
+ [macOS](https://wilsonl.in/hyperbuild/bin/0.1.2-macos-x86_64) |
32
+ [Linux](https://wilsonl.in/hyperbuild/bin/0.1.2-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.40"
49
+ hyperbuild = "0.1.2"
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.40</version>
153
+ <version>0.1.2</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.40
4
+ version: 0.1.2
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