Skip to content

Commit

Permalink
Use strict types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 29, 2021
1 parent c38fc93 commit 9f640d4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
*.d.ts
*.log
coverage/
node_modules/
*.d.ts
*.log
.DS_Store
yarn.lock
35 changes: 22 additions & 13 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
import fs from 'node:fs'
import https from 'node:https'
import {bail} from 'bail'
import concat from 'concat-stream'
import concatStream from 'concat-stream'

https.get('https://www.w3.org/TR/html4/sgml/entities.html', onconnection)

function onconnection(response) {
response.pipe(concat(onconcat)).on('error', bail)
}
https.get('https://www.w3.org/TR/html4/sgml/entities.html', (response) => {
response.pipe(concatStream(onconcat)).on('error', bail)
})

/**
* @param {Buffer} data
*/
function onconcat(data) {
const value = String(data)
/** @type {Record.<string, string>} */
const entities = {}
const re = /&lt;!ENTITY([\s\S]+?)--&gt;/g
let match = re.exec(data)
let list
let match = re.exec(value)

while (match) {
list = match[1].split('--', 1)[0].split(/\s+/).filter(Boolean)
const list = match[1].split('--', 1)[0].split(/\s+/).filter(Boolean)

if (list[1] === 'CDATA') {
entities[list[0]] = String.fromCharCode(
Number(list[2].split('#')[1].split(';')[0])
)
}

match = re.exec(data)
match = re.exec(value)
}

fs.writeFile(
'index.js',
'export const characterEntitiesHtml4 = ' +
JSON.stringify(entities, null, 2) +
'\n',
[
'/**',
' * Map of named character references from HTML 4.',
' *',
' * @type {Record<string, string>}',
' */',
'export const characterEntitiesHtml4 = ' +
JSON.stringify(entities, null, 2),
''
].join('\n'),
bail
)
}
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Map of named character references from HTML 4.
*
* @type {Record<string, string>}
*/
export const characterEntitiesHtml4 = {
nbsp: ' ',
iexcl: '¡',
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@
"remark-preset-wooorm": "^9.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.46.0"
},
"scripts": {
"prepublishOnly": "npm run build && npm run format",
"generate": "node build",
"prebuild": "rimraf \"*.d.ts\"",
"build": "tsc",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test": "npm run generate && npm run build && npm run format && npm run test-coverage"
},
"prettier": {
Expand All @@ -69,5 +69,11 @@
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]

HTML4 character entity information.
Map of named character references from HTML 4.

## Install

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"files": ["index.js"],
"include": ["*.js"],
"compilerOptions": {
"target": "ES2020",
Expand All @@ -11,6 +10,7 @@
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
"skipLibCheck": true,
"strict": true
}
}

0 comments on commit 9f640d4

Please sign in to comment.