Skip to content

Commit 68f87bc

Browse files
committed
Refactor
1 parent 2f576c3 commit 68f87bc

File tree

9 files changed

+35
-34
lines changed

9 files changed

+35
-34
lines changed

.gitignore

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

lib/core.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
* @typedef _Env A hidden Prism environment
99
* @property {string} type
1010
* @property {string} tag
11-
* @property {Text|RefractorElement|Array.<Text|RefractorElement>} content
12-
* @property {Array.<string>} classes
13-
* @property {Object.<string, string>} attributes
11+
* @property {Text|RefractorElement|Array<Text|RefractorElement>} content
12+
* @property {Array<string>} classes
13+
* @property {Record<string, string>} attributes
1414
* @property {string} language
1515
*
1616
* @typedef {import('hast').Root} Root
1717
* @typedef {import('hast').Element} Element
1818
* @typedef {import('hast').Text} Text
19-
* @typedef {Omit<Element, 'children'> & {children: Array.<RefractorElement|Text>}} RefractorElement
20-
* @typedef {Omit<Root, 'children'> & {children: Array.<RefractorElement|Text>}} RefractorRoot
19+
* @typedef {Omit<Element, 'children'> & {children: Array<RefractorElement|Text>}} RefractorElement
20+
* @typedef {Omit<Root, 'children'> & {children: Array<RefractorElement|Text>}} RefractorRoot
2121
*
2222
* @typedef {import('prismjs').Languages} Languages
2323
* @typedef {import('prismjs').Grammar} Grammar Whatever this is, Prism handles it.
@@ -122,13 +122,13 @@ function register(syntax) {
122122
/**
123123
* Register a new `alias` for the `name` language.
124124
*
125-
* @param {Object.<string, string|Array.<string>>|string} name
126-
* @param {string|Array.<string>} [alias]
125+
* @param {Record<string, string|Array<string>>|string} name
126+
* @param {string|Array<string>} [alias]
127127
* @returns {void}
128128
*/
129129
function alias(name, alias) {
130130
const languages = refractor.languages
131-
/** @type {Object.<string, string|Array.<string>>} */
131+
/** @type {Record<string, string|Array<string>>} */
132132
let map = {}
133133

134134
if (typeof name === 'string') {
@@ -215,11 +215,11 @@ function registered(language) {
215215
/**
216216
* List all registered languages (names and aliases).
217217
*
218-
* @returns {Array.<string>}
218+
* @returns {Array<string>}
219219
*/
220220
function listLanguages() {
221221
const languages = refractor.languages
222-
/** @type {Array.<string>} */
222+
/** @type {Array<string>} */
223223
const list = []
224224
/** @type {string} */
225225
let language
@@ -237,17 +237,17 @@ function listLanguages() {
237237
}
238238

239239
/**
240-
* @param {string|_Token|Array.<string|_Token>} value
240+
* @param {string|_Token|Array<string|_Token>} value
241241
* @param {string} language
242-
* @returns {Text|RefractorElement|Array.<Text|RefractorElement>}
242+
* @returns {Text|RefractorElement|Array<Text|RefractorElement>}
243243
*/
244244
function stringify(value, language) {
245245
if (typeof value === 'string') {
246246
return {type: 'text', value}
247247
}
248248

249249
if (Array.isArray(value)) {
250-
/** @type {Array.<Text|RefractorElement>} */
250+
/** @type {Array<Text|RefractorElement>} */
251251
const result = []
252252
let index = -1
253253

@@ -302,8 +302,8 @@ function encode(tokens) {
302302
}
303303

304304
/**
305-
* @param {Object.<string, string>} attrs
306-
* @returns {Object.<string, string>}
305+
* @param {Record<string, string>} attrs
306+
* @returns {Record<string, string>}
307307
*/
308308
function attributes(attrs) {
309309
/** @type {string} */

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@
7878
"xo": "^0.46.0"
7979
},
8080
"scripts": {
81-
"prepack": "npm run build && npm run format",
82-
"build": "rimraf \"{lang/**,lib/**,script/**,test/**,}*.d.ts\" && tsc && type-coverage",
8381
"generate": "node script/languages.js && node script/list.js && node script/fixtures.js",
82+
"prepublishOnly": "npm run build && npm run format",
83+
"build": "rimraf \"{lang,lib,script,test}/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
8484
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
85-
"test-api": "node test/index.js",
86-
"test-coverage": "c8 -x \"lang/*.js\" --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
87-
"test": "npm run build && npm run generate && npm run format && npm run test-coverage"
85+
"test-api": "node --conditions development test/index.js",
86+
"test-coverage": "c8 -x \"lang/*.js\" --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
87+
"test": "npm run generate && npm run build && npm run format && npm run test-coverage"
8888
},
8989
"prettier": {
9090
"tabWidth": 2,
@@ -117,6 +117,7 @@
117117
"atLeast": 100,
118118
"detail": true,
119119
"strict": true,
120+
"ignoreCatch": true,
120121
"ignoreFiles": [
121122
"lang/*.d.ts"
122123
]

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ Register a new `alias` for the `name` language.
144144

145145
* `name` (`string`) — [Name][names] of a registered language
146146
* `alias` (`string`) — New alias for the registered language
147-
* `list` (`Array.<alias>`) — List of aliases
148-
* `aliases` (`Object.<alias|list>`) — Map where each key is a `name` and each
147+
* `list` (`Array<alias>`) — List of aliases
148+
* `aliases` (`Record<alias|list>`) — Map where each key is a `name` and each
149149
value an `alias` or a `list`
150150

151151
###### Example
@@ -228,7 +228,7 @@ List all registered languages ([names and aliases][syntax]).
228228

229229
###### Returns
230230

231-
`Array.<string>`.
231+
`Array<string>`.
232232

233233
###### Example
234234

script/data.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path'
33
// @ts-expect-error: untyped.
44
import getLoader from 'prismjs/dependencies.js'
55

6-
/** @type {{languages: Object.<string, unknown>}} */
6+
/** @type {{languages: Record<string, unknown>}} */
77
const components = JSON.parse(
88
String(
99
fs.readFileSync(path.join('node_modules', 'prismjs', 'components.json'))
@@ -14,10 +14,10 @@ const allLanguages = Object.keys(components.languages).filter(
1414
(d) => d !== 'meta'
1515
)
1616

17-
/** @type {Array.<string>} */
17+
/** @type {Array<string>} */
1818
export const all = getLoader(components, allLanguages).getIds()
1919

20-
/** @type {Array.<string>} */
20+
/** @type {Array<string>} */
2121
export const common = getLoader(components, [
2222
// These are alphabetical, but they are exported in registration order.
2323
// They are based on the languages that lowlight exports as common,

script/languages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import alphaSort from 'alpha-sort'
1414
import {all} from './data.js'
1515
import {toId} from './to-id.js'
1616

17-
/** @type {{languages: Object.<string, {require: string|string[], alias: string|string[]}>}} */
17+
/** @type {{languages: Record<string, {require: string|string[], alias: string|string[]}>}} */
1818
const components = JSON.parse(
1919
String(
2020
fs.readFileSync(path.join('node_modules', 'prismjs', 'components.json'))

script/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ console.log(
1818
)
1919

2020
/**
21-
* @param {Array.<string>} list
21+
* @param {Array<string>} list
2222
*/
2323
function generate(list) {
2424
return [

script/support.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ async function transformer(tree) {
3333
* @param {string} name
3434
*/
3535
async function one(name) {
36-
/** @type {Array.<string>} */
36+
/** @type {Array<string>} */
3737
// Unknown stuff to TS.
3838
// type-coverage:ignore-next-line
3939
const aliases = (await import('../lang/' + name + '.js')).default.aliases
40-
/** @type {Array.<PhrasingContent>} */
40+
/** @type {Array<PhrasingContent>} */
4141
const content = [
4242
u(
4343
'link',

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["index.js", "lib/**/*.js", "script/**/*.js", "test/**/*.js"],
2+
"include": ["lib/**/*.js", "script/**/*.js", "test/**/*.js", "*.js"],
33
"compilerOptions": {
44
"target": "ES2020",
55
"lib": ["ES2020"],

0 commit comments

Comments
 (0)