Skip to content

Commit 8a855c5

Browse files
committed
Initial commit
0 parents  commit 8a855c5

File tree

10 files changed

+581
-0
lines changed

10 files changed

+581
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
*.log
3+
.nyc_output/
4+
coverage/
5+
node_modules/
6+
yarn.lock

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage/

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- lts/dubnium
4+
- node
5+
after_script: bash <(curl -s https://codecov.io/bash)

index.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict'
2+
3+
module.exports = x
4+
5+
var slice = [].slice
6+
7+
// Creating xast elements.
8+
function x(name, attributes) {
9+
var attrs = {}
10+
var childrenIndex = 2
11+
var attribute
12+
var value
13+
var node
14+
15+
if (typeof name !== 'string' || name === '') {
16+
throw new Error('Expected element name, got `' + name + '`')
17+
}
18+
19+
node = {type: 'element', name: name, attributes: attrs, children: []}
20+
21+
// Note that we do not accept a node instead of attributes.
22+
if (
23+
typeof attributes === 'number' ||
24+
typeof attributes === 'string' ||
25+
(attributes && 'length' in attributes)
26+
) {
27+
childrenIndex = 1
28+
attributes = null
29+
}
30+
31+
if (attributes !== null && attributes !== undefined) {
32+
for (attribute in attributes) {
33+
value = attributes[attribute]
34+
35+
// Ignore nully and NaN values.
36+
if (value !== null && value !== undefined && value === value) {
37+
attrs[attribute] = String(value)
38+
}
39+
}
40+
}
41+
42+
add(node.children, slice.call(arguments, childrenIndex))
43+
44+
return node
45+
}
46+
47+
function add(siblings, value) {
48+
var index
49+
var length
50+
51+
if (value === null || value === undefined) {
52+
// Empty.
53+
} else if (typeof value === 'string' || typeof value === 'number') {
54+
siblings.push({type: 'text', value: String(value)})
55+
} else if (typeof value === 'object' && 'length' in value) {
56+
index = -1
57+
length = value.length
58+
59+
while (++index < length) {
60+
add(siblings, value[index])
61+
}
62+
} else if (typeof value === 'object' && typeof value.type === 'string') {
63+
siblings.push(value)
64+
} else {
65+
throw new TypeError('Expected node, nodes, string, got `' + value + '`')
66+
}
67+
}

license

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2020 Titus Wormer <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
'Software'), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

package.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "xastscript",
3+
"version": "0.0.0",
4+
"description": "Hyperscript compatible DSL for creating xast trees",
5+
"license": "MIT",
6+
"keywords": [
7+
"xast",
8+
"unist",
9+
"hyperscript",
10+
"dsl",
11+
"xml",
12+
"extensible",
13+
"markup",
14+
"language"
15+
],
16+
"repository": "syntax-tree/xastscript",
17+
"bugs": "https://github.com/syntax-tree/xastscript/issues",
18+
"funding": {
19+
"type": "opencollective",
20+
"url": "https://opencollective.com/unified"
21+
},
22+
"author": "Titus Wormer <[email protected]> (https://wooorm.com)",
23+
"contributors": [
24+
"Titus Wormer <[email protected]> (https://wooorm.com)"
25+
],
26+
"files": [
27+
"index.js"
28+
],
29+
"dependencies": {},
30+
"devDependencies": {
31+
"nyc": "^15.0.0",
32+
"prettier": "^1.0.0",
33+
"remark-cli": "^7.0.0",
34+
"remark-preset-wooorm": "^6.0.0",
35+
"tape": "^4.0.0",
36+
"xo": "^0.25.0"
37+
},
38+
"scripts": {
39+
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
40+
"test-api": "node test",
41+
"test-coverage": "nyc --reporter lcov tape test.js",
42+
"test": "npm run format && npm run test-coverage"
43+
},
44+
"nyc": {
45+
"check-coverage": true,
46+
"lines": 100,
47+
"functions": 100,
48+
"branches": 100
49+
},
50+
"prettier": {
51+
"tabWidth": 2,
52+
"useTabs": false,
53+
"singleQuote": true,
54+
"bracketSpacing": false,
55+
"semi": false,
56+
"trailingComma": "none"
57+
},
58+
"xo": {
59+
"prettier": true,
60+
"esnext": false,
61+
"rules": {
62+
"no-self-compare": "off",
63+
"guard-for-in": "off"
64+
}
65+
},
66+
"remarkConfig": {
67+
"plugins": [
68+
"preset-wooorm"
69+
]
70+
}
71+
}

0 commit comments

Comments
 (0)