diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a58e4343..df3532e6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -38,7 +38,6 @@ updates: - 'eslint' - 'eslint-*' - 'lint-staged' - - 'globals' - '@eslint/*' unist: patterns: diff --git a/package-lock.json b/package-lock.json index 3c578bc3..e74d33a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,6 +23,7 @@ "estree-util-visit": "^2.0.0", "github-slugger": "^2.0.0", "glob": "^11.0.3", + "globals": "^16.3.0", "hast-util-to-string": "^3.0.1", "hastscript": "^9.0.1", "lightningcss": "^1.30.1", @@ -65,7 +66,6 @@ "eslint": "^9.31.0", "eslint-plugin-import-x": "^4.16.1", "eslint-plugin-jsdoc": "^51.4.1", - "globals": "^16.3.0", "husky": "^9.1.7", "lint-staged": "^16.1.2", "prettier": "3.6.2" @@ -5155,7 +5155,7 @@ "version": "16.3.0", "resolved": "https://registry.npmjs.org/globals/-/globals-16.3.0.tgz", "integrity": "sha512-bqWEnJ1Nt3neqx2q5SFfGS8r/ahumIakg3HcwtNlrVlwXIeNumWn/c7Pn/wKzGhf6SaW6H6uWXLqC30STCMchQ==", - "dev": true, + "license": "MIT", "engines": { "node": ">=18" }, diff --git a/package.json b/package.json index c760cc1a..2e20d68d 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "eslint": "^9.31.0", "eslint-plugin-import-x": "^4.16.1", "eslint-plugin-jsdoc": "^51.4.1", - "globals": "^16.3.0", "husky": "^9.1.7", "lint-staged": "^16.1.2", "prettier": "3.6.2" @@ -55,6 +54,7 @@ "estree-util-visit": "^2.0.0", "github-slugger": "^2.0.0", "glob": "^11.0.3", + "globals": "^16.3.0", "hast-util-to-string": "^3.0.1", "hastscript": "^9.0.1", "lightningcss": "^1.30.1", diff --git a/src/utils/parser/__tests__/index.test.mjs b/src/utils/parser/__tests__/index.test.mjs index 944d3de6..e51c0309 100644 --- a/src/utils/parser/__tests__/index.test.mjs +++ b/src/utils/parser/__tests__/index.test.mjs @@ -12,7 +12,7 @@ describe('transformTypeToReferenceLink', () => { it('should transform a JavaScript primitive type into a Markdown link', () => { strictEqual( transformTypeToReferenceLink('string'), - '[``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)' + '[``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type)' ); }); diff --git a/src/utils/parser/constants.mjs b/src/utils/parser/constants.mjs index 46ad3628..8c481217 100644 --- a/src/utils/parser/constants.mjs +++ b/src/utils/parser/constants.mjs @@ -1,4 +1,4 @@ -'use strict'; +import globals from 'globals'; // These are string replacements specific to Node.js API docs for anchor IDs export const DOC_API_SLUGS_REPLACEMENTS = [ @@ -71,16 +71,16 @@ export const DOC_API_HEADING_TYPES = [ // This is a mapping for types within the Markdown content and their respective // JavaScript primitive types within the MDN JavaScript docs -// @see DOC_MDN_BASE_URL_JS_PRIMITIVES -export const DOC_TYPES_MAPPING_PRIMITIVES = { - boolean: 'Boolean', - integer: 'Number', // Not a primitive, used for clarification. - null: 'Null', - number: 'Number', - string: 'String', - symbol: 'Symbol', - undefined: 'Undefined', -}; +// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data_structures#primitive_values +export const DOC_TYPES_MAPPING_PRIMITIVES = [ + 'null', + 'undefined', + 'boolean', + 'number', + 'bigint', + 'string', + 'symbol', +]; // This is a mapping for types within the Markdown content and their respective // JavaScript globals types within the MDN JavaScript docs @@ -88,45 +88,15 @@ export const DOC_TYPES_MAPPING_PRIMITIVES = { export const DOC_TYPES_MAPPING_GLOBALS = { ...Object.fromEntries( [ - 'AggregateError', - 'Array', - 'ArrayBuffer', - 'DataView', - 'Date', - 'Error', - 'EvalError', - 'Function', - 'Map', - 'NaN', - 'Object', - 'Promise', - 'Proxy', - 'RangeError', - 'ReferenceError', - 'RegExp', - 'Set', - 'SharedArrayBuffer', - 'SyntaxError', - 'Symbol', - 'TypeError', - 'URIError', - 'WeakMap', - 'WeakSet', - - 'TypedArray', - 'Float16Array', - 'Float32Array', - 'Float64Array', - 'Int8Array', - 'Int16Array', - 'Int32Array', - 'Uint8Array', - 'Uint8ClampedArray', - 'Uint16Array', - 'Uint32Array', + // This is updated with every ES-spec, so, as long as the + // `globals` package is up-to-date, so will our globals + // list. + ...Object.keys(globals.builtin), + 'AsyncGeneratorFunction', + 'AsyncIterator', + 'AsyncFunction', ].map(e => [e, e]) ), - bigint: 'BigInt', 'WebAssembly.Instance': 'WebAssembly/Instance', }; @@ -331,18 +301,12 @@ export const DOC_TYPES_MAPPING_OTHER = { ArrayBufferView: `${DOC_MDN_BASE_URL}/API/ArrayBufferView`, - AsyncIterator: 'https://tc39.github.io/ecma262/#sec-asynciterator-interface', AsyncIterable: 'https://tc39.github.io/ecma262/#sec-asynciterable-interface', - AsyncFunction: 'https://tc39.es/ecma262/#sec-async-function-constructor', 'Module Namespace Object': 'https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects', - AsyncGeneratorFunction: - 'https://tc39.es/proposal-async-iteration/#sec-asyncgeneratorfunction-constructor', - Iterable: `${DOC_MDN_BASE_URL_JS}Reference/Iteration_protocols#The_iterable_protocol`, - Iterator: `${DOC_MDN_BASE_URL_JS}Reference/Iteration_protocols#The_iterator_protocol`, CloseEvent: `${DOC_MDN_BASE_URL}/API/CloseEvent`, EventSource: `${DOC_MDN_BASE_URL}/API/EventSource`, diff --git a/src/utils/parser/index.mjs b/src/utils/parser/index.mjs index 8a91a071..0700d75c 100644 --- a/src/utils/parser/index.mjs +++ b/src/utils/parser/index.mjs @@ -81,10 +81,8 @@ export const transformTypeToReferenceLink = type => { */ const transformType = lookupPiece => { // Transform JS primitive type references into Markdown links (MDN) - if (lookupPiece.toLowerCase() in DOC_TYPES_MAPPING_PRIMITIVES) { - const typeValue = DOC_TYPES_MAPPING_PRIMITIVES[lookupPiece.toLowerCase()]; - - return `${DOC_MDN_BASE_URL_JS_PRIMITIVES}#${typeValue}_type`; + if (DOC_TYPES_MAPPING_PRIMITIVES.includes(lookupPiece.toLowerCase())) { + return `${DOC_MDN_BASE_URL_JS_PRIMITIVES}#${lookupPiece.toLowerCase()}_type`; } // Transforms JS Global type references into Markdown links (MDN)