Skip to content

Commit

Permalink
Update dev-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 1, 2021
1 parent 1f43c76 commit 5b74592
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 68 deletions.
82 changes: 37 additions & 45 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import fs from 'fs'
import https from 'https'
import fs from 'node:fs'
import https from 'node:https'
import {bail} from 'bail'
import concat from 'concat-stream'
import alphaSort from 'alpha-sort'
import unified from 'unified'
import {unified} from 'unified'
import parse from 'rehype-parse'
// @ts-ignore Remove when types are added
import q from 'hast-util-select'
// @ts-ignore Remove when types are added
import toString from 'hast-util-to-string'
// @ts-ignore Remove when types are added
import ev from 'hast-util-is-event-handler'
import {select, selectAll} from 'hast-util-select'
import {toString} from 'hast-util-to-string'
import {isEventHandler} from 'hast-util-is-event-handler'

/**
* @typedef {import('http').IncomingMessage} IncomingMessage
Expand All @@ -20,13 +17,13 @@ import ev from 'hast-util-is-event-handler'
* @typedef {Object.<string, Array.<string>>} Map
*/

var proc = unified().use(parse)
const proc = unified().use(parse)

var actual = 0
var expected = 3
let actual = 0
const expected = 3

/** @type {Map} */
var all = {}
const all = {}

https.get('https://www.w3.org/TR/SVG11/attindex.html', onsvg1)
https.get('https://www.w3.org/TR/SVGTiny12/attributeTable.html', ontiny)
Expand All @@ -42,11 +39,11 @@ function onsvg1(response) {
* @param {Buffer} buf
*/
function onconcat(buf) {
var tree = proc.parse(buf)
const tree = proc.parse(buf)
/** @type {Map} */
var map = {}
const map = {}
/** @type {Element[]} */
var nodes = q.selectAll('.property-table tr', tree)
const nodes = selectAll('.property-table tr', tree)

if (nodes.length === 0) {
throw new Error('Couldn’t find rows in SVG 1')
Expand All @@ -61,19 +58,14 @@ function onsvg1(response) {
*/
function each(node) {
/** @type {Element[]} */
var elements = q.selectAll('.element-name', node)
const elements = selectAll('.element-name', node)

q.selectAll('.attr-name', node).forEach(every)

/**
* @param {string} name
*/
function every(name) {
selectAll('.attr-name', node).forEach((name) => {
elements
.map(toString)
.map(clean)
.forEach(add(map, clean(toString(name))))
}
})
}

/**
Expand All @@ -96,11 +88,11 @@ function ontiny(response) {
* @param {Buffer} buf
*/
function onconcat(buf) {
var tree = proc.parse(buf)
const tree = proc.parse(buf)
/** @type {Map} */
var map = {}
const map = {}
/** @type {Element[]} */
var nodes = q.selectAll('#attributes .attribute', tree)
const nodes = selectAll('#attributes .attribute', tree)

if (nodes.length === 0) {
throw new Error('Couldn’t find nodes in SVG Tiny')
Expand All @@ -115,11 +107,11 @@ function ontiny(response) {
*/
function each(node) {
/** @type {Element[]} */
var all = q.selectAll('.element', node)
const all = selectAll('.element', node)

all
.map(toString)
.forEach(add(map, toString(q.select('.attribute-name', node))))
.forEach(add(map, toString(select('.attribute-name', node))))
}
}
}
Expand All @@ -134,11 +126,11 @@ function onsvg2(response) {
* @param {Buffer} buf
*/
function onconcat(buf) {
var tree = proc.parse(buf)
const tree = proc.parse(buf)
/** @type {Map} */
var map = {}
const map = {}
/** @type {Element[]} */
var nodes = q.selectAll('tbody tr', tree)
const nodes = selectAll('tbody tr', tree)

if (nodes.length === 0) {
throw new Error('Couldn’t find nodes in SVG 2')
Expand All @@ -153,11 +145,11 @@ function onsvg2(response) {
*/
function each(node) {
/** @type {Element[]} */
var all = q.selectAll('.element-name span', node)
const all = selectAll('.element-name span', node)

all
.map(toString)
.forEach(add(map, toString(q.select('.attr-name span', node))))
.forEach(add(map, toString(select('.attr-name span', node))))
}
}
}
Expand All @@ -176,7 +168,7 @@ function done(map) {
if (actual === expected) {
fs.writeFile(
'index.js',
'export var svgElementAttributes = ' +
'export const svgElementAttributes = ' +
JSON.stringify(sort(all), null, 2) +
'\n',
bail
Expand All @@ -192,7 +184,7 @@ function done(map) {
*/
function add(map, name) {
if (
ev(name) ||
isEventHandler(name) ||
name === 'role' ||
name.slice(0, 5) === 'aria-' ||
name.slice(0, 3) === 'ev:' ||
Expand All @@ -208,7 +200,7 @@ function add(map, name) {
* @param {string} tagName Element name
*/
function fn(tagName) {
var attributes = map[tagName] || (map[tagName] = [])
const attributes = map[tagName] || (map[tagName] = [])

if (!attributes.includes(name)) {
attributes.push(name)
Expand All @@ -224,11 +216,11 @@ function add(map, name) {
*/
function clean(map) {
/** @type {Map} */
var result = {}
let result = {}
/** @type {Array.<string>} */
var list = []
const list = []
/** @type {Array.<string>} */
var globals = []
const globals = []

// Find all used attributes.
Object.keys(map).forEach(function (tagName) {
Expand All @@ -241,9 +233,9 @@ function clean(map) {

// Find global attributes.
list.forEach(function (attribute) {
var global = true
let global = true
/** @type {string} */
var key
let key

for (key in map) {
if (!map[key].includes(attribute)) {
Expand All @@ -265,7 +257,7 @@ function clean(map) {
Object.keys(map)
.sort()
.forEach(function (tagName) {
var attributes = map[tagName]
const attributes = map[tagName]
.filter(function (attribute) {
return !globals.includes(attribute)
})
Expand Down Expand Up @@ -303,7 +295,7 @@ function merge(left, right) {
* @param {Map} map
*/
function cleanAll(map) {
var globals = map['*']
const globals = map['*']

Object.keys(map).forEach(function (tagName) {
if (tagName !== '*') {
Expand All @@ -320,7 +312,7 @@ function cleanAll(map) {
*/
function sort(map) {
/** @type {Map} */
var result = {}
const result = {}

Object.keys(map)
.sort(alphaSort())
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export var svgElementAttributes = {
export const svgElementAttributes = {
'*': [
'about',
'class',
Expand Down
35 changes: 16 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@
"index.js"
],
"devDependencies": {
"@types/concat-stream": "^1.6.0",
"@types/hast": "^2.3.1",
"@types/node": "^14.14.37",
"@types/tape": "^4.13.0",
"alpha-sort": "^4.0.0",
"@types/concat-stream": "^1.0.0",
"@types/hast": "^2.0.0",
"@types/node": "^16.0.0",
"@types/tape": "^4.0.0",
"alpha-sort": "^5.0.0",
"bail": "^2.0.0",
"c8": "^7.0.0",
"concat-stream": "^2.0.0",
"hast-util-is-event-handler": "^1.0.0",
"hast-util-select": "^4.0.0",
"hast-util-to-string": "^1.0.0",
"hast-util-is-event-handler": "^2.0.0",
"hast-util-select": "^5.0.0",
"hast-util-to-string": "^2.0.0",
"prettier": "^2.0.0",
"rehype-parse": "^7.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.2",
"rehype-parse": "^8.0.0",
"remark-cli": "^10.0.0",
"remark-preset-wooorm": "^9.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.17.0",
"typescript": "^4.2.3",
"unified": "^9.0.0",
"xo": "^0.38.0"
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unified": "^10.0.0",
"xo": "^0.46.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
Expand All @@ -73,9 +73,6 @@
"xo": {
"prettier": true,
"rules": {
"import/no-mutable-exports": "off",
"no-var": "off",
"prefer-arrow-callback": "off",
"unicorn/no-array-for-each": "off",
"unicorn/no-array-callback-reference": "off"
}
Expand Down
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'
import assert from 'node:assert'
import test from 'tape'
import {svgElementAttributes} from './index.js'

Expand All @@ -13,10 +13,10 @@ test('svgElementAttributes', function (t) {

t.doesNotThrow(function () {
for (const name of Object.keys(svgElementAttributes)) {
var props = svgElementAttributes[name]
const props = svgElementAttributes[name]

for (const prop of props) {
var label = prop + ' in ' + name
const label = prop + ' in ' + name
assert.strictEqual(typeof prop, 'string', label + ' should be string')
assert.strictEqual(prop, prop.trim(), label + ' should be trimmed')
assert.ok(/^[a-z][a-z\d-]*$/i.test(prop), label + ' should be `a-z-`')
Expand Down

0 comments on commit 5b74592

Please sign in to comment.