als-document 1.4.2 → 1.4.3

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/build.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const { readFileSync, writeFileSync, watchFile, watch } = require('fs')
2
- const { join,basename } = require('path')
2
+ const { join, basename } = require('path')
3
3
 
4
4
  function optimizeCode(content) {
5
5
  // content = content.replace(/(?<!\\)\/\/.*$/gm, '') // remove comments
@@ -19,18 +19,18 @@ function optimizeCode(content) {
19
19
 
20
20
  const root = __dirname
21
21
  const files = {
22
- 'query': ['query','check-element'],
23
- 'node':[
24
- 'dataset','find','text-node',
25
- 'style','class-list','node','single-node','root','document'
22
+ 'query': ['query', 'check-element'],
23
+ 'node': [
24
+ 'dataset', 'find', 'text-node',
25
+ 'style', 'class-list', 'node', 'single-node', 'root', 'document'
26
26
  ],
27
- 'parse':['parse-atts','void-tags','parser','cache'],
27
+ 'parse': ['parse-atts', 'void-tags', 'parser', 'cache'],
28
28
  }
29
29
  const fileList = []
30
30
  function buildFileList() {
31
- Object.entries(files).forEach(([dir,filenames]) => {
31
+ Object.entries(files).forEach(([dir, filenames]) => {
32
32
  filenames.forEach(filename => {
33
- fileList.push(join(root,'lib',dir,filename+'.js'))
33
+ fileList.push(join(root, 'lib', dir, filename + '.js'))
34
34
  });
35
35
  });
36
36
  }
@@ -39,12 +39,12 @@ buildFileList()
39
39
 
40
40
  function build() {
41
41
  let content = fileList.map(filePath => readFileSync(filePath, 'utf-8')).join('\n');
42
-
43
- const toReturn = '{ parseHTML, Node, Query, TextNode, SingleNode, buildFromCache, cacheDoc, Root, Document }'
42
+ const arr = ['parseHTML', 'Node', 'Query', 'TextNode', 'SingleNode', 'buildFromCache', 'cacheDoc', 'Root', 'Document']
43
+ const toReturn = `{ ${arr.join(',')} }`
44
44
  content = optimizeCode(content)
45
45
  writeFileSync(join(root, 'document.js'), `const alsDocument = (function(){\n${content}\nreturn ${toReturn}\n})()`)
46
- writeFileSync(join(root, 'index.js'), content + '\n' + `module.exports = ${toReturn}`)
47
- writeFileSync(join(root, 'index.mjs'), content + '\n' + `export default ${toReturn}`)
46
+ writeFileSync(join(root, 'index.js'), [content,`module.exports = ${toReturn}`].join('\n'))
47
+ writeFileSync(join(root, 'index.mjs'), [content,`export ${toReturn}`,`export default ${toReturn}`].join('\n'))
48
48
  console.log('Files are builded')
49
49
  }
50
50
 
@@ -54,10 +54,10 @@ if (process.argv[2] === '--watch') {
54
54
  console.log('Waching...')
55
55
  let lastChangeTime = Date.now()
56
56
  Object.keys(files).forEach(dirName => {
57
- const dirPath = join(__dirname,dirName)
57
+ const dirPath = join(__dirname, dirName)
58
58
  watch(dirPath, (eventType, filename) => {
59
59
  let newChangeTime = Date.now()
60
- if(newChangeTime - lastChangeTime < 1000) return
60
+ if (newChangeTime - lastChangeTime < 1000) return
61
61
  build()
62
62
  lastChangeTime = newChangeTime
63
63
  console.log(`${filename} has changed (${count++})`)
package/document.js CHANGED
@@ -40,5 +40,5 @@ function buildFromCache(cached){
40
40
  function buildNode(cache,parent=null){
41
41
  }
42
42
 
43
43
  function cacheDoc(doc){
44
44
  const props=['isSingle','tagName','attributes']
45
45
  function addToCache(element,cache={}){
46
46
  if(typeof element==='string') return element
47
47
  if(element.nodeName==='#text') return{textContent:element.textContent}
48
48
  props.forEach(prop=>{
49
49
  if(element[prop]){
50
50
  cache[prop]=typeof element[prop]==='object' ?{...element[prop]} : element[prop]
51
51
  }
52
52
  });
53
53
  if(!element.childNodes) return cache
54
54
  cache.childNodes=[]
55
55
  element.childNodes.forEach(childNode=>{
56
56
  cache.childNodes.push(addToCache(childNode))
57
57
  });
58
58
  return cache
59
59
  }
60
60
  return addToCache(doc)
61
61
  }
62
- return { parseHTML, Node, Query, TextNode, SingleNode, buildFromCache, cacheDoc, Root, Document }
62
+ return { parseHTML,Node,Query,TextNode,SingleNode,buildFromCache,cacheDoc,Root,Document }
63
63
  })()
package/index.js CHANGED
@@ -39,4 +39,4 @@ function buildFromCache(cached){
39
39
  function buildNode(cache,parent=null){
40
40
  }
41
41
 
42
42
  function cacheDoc(doc){
43
43
  const props=['isSingle','tagName','attributes']
44
44
  function addToCache(element,cache={}){
45
45
  if(typeof element==='string') return element
46
46
  if(element.nodeName==='#text') return{textContent:element.textContent}
47
47
  props.forEach(prop=>{
48
48
  if(element[prop]){
49
49
  cache[prop]=typeof element[prop]==='object' ?{...element[prop]} : element[prop]
50
50
  }
51
51
  });
52
52
  if(!element.childNodes) return cache
53
53
  cache.childNodes=[]
54
54
  element.childNodes.forEach(childNode=>{
55
55
  cache.childNodes.push(addToCache(childNode))
56
56
  });
57
57
  return cache
58
58
  }
59
59
  return addToCache(doc)
60
60
  }
61
- module.exports = { parseHTML, Node, Query, TextNode, SingleNode, buildFromCache, cacheDoc, Root, Document }
61
+ module.exports = { parseHTML,Node,Query,TextNode,SingleNode,buildFromCache,cacheDoc,Root,Document }
package/index.mjs CHANGED
@@ -39,4 +39,5 @@ function buildFromCache(cached){
39
39
  function buildNode(cache,parent=null){
40
40
  }
41
41
 
42
42
  function cacheDoc(doc){
43
43
  const props=['isSingle','tagName','attributes']
44
44
  function addToCache(element,cache={}){
45
45
  if(typeof element==='string') return element
46
46
  if(element.nodeName==='#text') return{textContent:element.textContent}
47
47
  props.forEach(prop=>{
48
48
  if(element[prop]){
49
49
  cache[prop]=typeof element[prop]==='object' ?{...element[prop]} : element[prop]
50
50
  }
51
51
  });
52
52
  if(!element.childNodes) return cache
53
53
  cache.childNodes=[]
54
54
  element.childNodes.forEach(childNode=>{
55
55
  cache.childNodes.push(addToCache(childNode))
56
56
  });
57
57
  return cache
58
58
  }
59
59
  return addToCache(doc)
60
60
  }
61
- export default { parseHTML, Node, Query, TextNode, SingleNode, buildFromCache, cacheDoc, Root, Document }
61
+ export { parseHTML,Node,Query,TextNode,SingleNode,buildFromCache,cacheDoc,Root,Document }
62
+ export default { parseHTML,Node,Query,TextNode,SingleNode,buildFromCache,cacheDoc,Root,Document }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "als-document",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "A powerful HTML parser & DOM manipulation library for both backend and frontend.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",