@litejs/dom 23.7.0 → 23.11.0

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.
Files changed (4) hide show
  1. package/README.md +9 -18
  2. package/index.js +3 -3
  3. package/net.js +27 -16
  4. package/package.json +4 -18
package/README.md CHANGED
@@ -10,7 +10,9 @@
10
10
  LiteJS DOM – [![Coverage][1]][2] [![Size][3]][4] [![Buy Me A Tea][5]][6]
11
11
  ==========
12
12
 
13
- A small DOM library for server-side testing, rendering, and handling of HTML files.
13
+ A small DOM library for server-side testing, rendering, and handling of HTML files.
14
+ [DOM spec](https://dom.spec.whatwg.org/) |
15
+ [Selectors Level 3](http://www.w3.org/TR/selectors/)
14
16
 
15
17
 
16
18
  Examples
@@ -61,28 +63,17 @@ el.querySelectorAll("b");
61
63
  ## Contributing
62
64
 
63
65
  Follow [Coding Style Guide](https://github.com/litejs/litejs/wiki/Style-Guide)
66
+ and run tests.
67
+ `npm install; npm test`
64
68
 
65
- Run tests
66
-
67
- ```
68
- npm install
69
- npm test
70
- ```
71
69
 
70
+ ## Licence
72
71
 
73
- ## External links
74
-
72
+ Copyright (c) 2014-2023 Lauri Rooden <lauri@rooden.ee>
73
+ [MIT License](https://litejs.com/MIT-LICENSE.txt) |
75
74
  [GitHub repo](https://github.com/litejs/dom) |
76
75
  [npm package](https://npmjs.org/package/@litejs/dom) |
77
- [DOM spec](https://dom.spec.whatwg.org/) |
78
- [Selectors Level 3](http://www.w3.org/TR/selectors/) |
79
- [Coveralls coverage][2]
76
+ [coverage][2] |
80
77
  [Buy Me A Tea][6]
81
78
 
82
79
 
83
- ## Licence
84
-
85
- Copyright (c) 2014-2023 Lauri Rooden <lauri@rooden.ee>
86
- [The MIT License](http://lauri.rooden.ee/mit-license.txt)
87
-
88
-
package/index.js CHANGED
@@ -235,13 +235,13 @@ var boolAttrs = {
235
235
  "§": "§", "²": "²", "³": "³", "¥": "¥"
236
236
  }
237
237
 
238
- Object.keys(boolAttrs).forEach(addGetter, { isBool: true })
238
+ Object.keys(boolAttrs).forEach(addGetter, { isBool: true, readonly: "readOnly" })
239
239
  numAttrs.split(" ").forEach(addGetter, { isNum: true })
240
- strAttrs.split(" ").forEach(addGetter, { })
240
+ strAttrs.split(" ").forEach(addGetter, { "for": "htmlFor", "class": "className" })
241
241
 
242
242
  function addGetter(key) {
243
243
  var attr = key.toLowerCase()
244
- Object.defineProperty(Element, key == "for" ? "htmlFor" : key == "class" ? "className" : key, {
244
+ Object.defineProperty(Element, this[key] || key, {
245
245
  configurable: true,
246
246
  enumerable: true,
247
247
  get: (
package/net.js CHANGED
@@ -4,8 +4,9 @@
4
4
 
5
5
 
6
6
  var DOM = require(".")
7
+ , URL = require("url").URL
7
8
  , parser = new DOM.DOMParser()
8
- , dataUrlRe = /^data:([^;,]*?)(;[^,]+?|),(.*)$/
9
+ , dataUrlRe = /^([^;,]*?)(;[^,]+?|),(.*)$/
9
10
 
10
11
  function XMLHttpRequest() {}
11
12
 
@@ -67,32 +68,42 @@ XMLHttpRequest.prototype = {
67
68
  },
68
69
  send: function (data) {
69
70
  var xhr = this
70
- , url = xhr.responseURL
71
- , proto = url.split(":", 1)[0]
72
- , opts = {
73
- method: xhr.method
74
- }
71
+ , url = new URL(xhr.responseURL, XMLHttpRequest.base)
75
72
 
76
- if (proto === "http" || proto === "https") {
77
- require(proto).request(url, opts, function(res) {
73
+ if (url.protocol === "http:" || url.protocol === "https:") {
74
+ url.method = xhr.method
75
+ require(url.protocol.slice(0, -1)).request(url, function(res) {
78
76
  head(res.statusCode, res.statusMessage, res.headers)
79
- res.on("data", body)
77
+ res.on("data", fillBody)
80
78
  res.on("end", done)
81
79
  }).end(data)
82
80
  return
83
81
  }
84
- if (proto === "data") {
85
- var match = dataUrlRe.exec(url)
82
+ if (url.protocol === "data:") {
83
+ var match = dataUrlRe.exec(url.pathname)
86
84
  if (!match) throw Error("Invalid URL: " + url)
87
- setTimeout(function() {
85
+ process.nextTick(function() {
88
86
  head(200, "OK", { "content-type": match[1] || "text/plain" })
89
- body(match[2] ? Buffer.from(match[3], "base64") : unescape(match[3]))
87
+ fillBody(match[2] ? Buffer.from(match[3], "base64") : unescape(match[3]))
88
+ done()
89
+ })
90
+ return
91
+ }
92
+
93
+ if (url.protocol === "file:") {
94
+ require("fs").readFile(url, function(err, chunk) {
95
+ if (err) {
96
+ head(404, "Not Found", {})
97
+ } else {
98
+ head(200, "OK", { "content-type": "text/plain" })
99
+ fillBody(chunk)
100
+ }
90
101
  done()
91
- }, 1)
102
+ })
92
103
  return
93
104
  }
94
105
 
95
- throw Error("Unsuported protocol: " + proto)
106
+ throw Error("Unsuported protocol in: " + url)
96
107
 
97
108
  function head(code, text, headers) {
98
109
  xhr.status = code
@@ -100,7 +111,7 @@ XMLHttpRequest.prototype = {
100
111
  xhr._headers = headers
101
112
  setState(xhr, xhr.HEADERS_RECEIVED)
102
113
  }
103
- function body(chunk) {
114
+ function fillBody(chunk) {
104
115
  xhr.responseText += chunk.toString("utf8")
105
116
  setState(xhr, xhr.LOADING)
106
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litejs/dom",
3
- "version": "23.7.0",
3
+ "version": "23.11.0",
4
4
  "description": "A small DOM library for server-side testing, rendering, and handling of HTML files",
5
5
  "license": "MIT",
6
6
  "author": "Lauri Rooden <lauri@rooden.ee>",
@@ -16,29 +16,15 @@
16
16
  "*.js"
17
17
  ],
18
18
  "scripts": {
19
- "test": "lj test --coverage --ignore=net.js --brief test/index.js && jshint *.js",
19
+ "test": "lj test --coverage --brief test/index.js && node --import=@litejs/cli/test.js test/run.mjs && jshint --config .github/jshint.json *.js",
20
20
  "test-fast": "lj test --brief test/index.js"
21
21
  },
22
22
  "repository": "github:litejs/dom",
23
23
  "devDependencies": {
24
- "@litejs/cli": "23.7.0",
24
+ "@litejs/cli": "23.9.0",
25
25
  "jshint": "2.13.6"
26
26
  },
27
27
  "litejs": {
28
- "build": false,
29
- "global": false
30
- },
31
- "jshintConfig": {
32
- "esversion": 5,
33
- "asi": true,
34
- "evil": true,
35
- "laxcomma": true,
36
- "maxdepth": 6,
37
- "node": true,
38
- "nonbsp": true,
39
- "undef": true,
40
- "unused": true,
41
- "shadow": "outer",
42
- "quotmark": "double"
28
+ "build": false
43
29
  }
44
30
  }