From 97d448845d19bcdb03acbf9b52ab7d7fce8d2b9e Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Thu, 7 Dec 2023 17:44:31 +0900 Subject: [PATCH] Format using prettier --- README.md | 2 +- package.json | 50 ++++++++++++++++++------------------- scripts/fixtures.ts | 2 +- scripts/oembed-providers.ts | 2 +- src/index.spec.ts | 2 +- src/index.ts | 43 +++++++++++++++---------------- src/oembed.ts | 8 +++--- 7 files changed, 53 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index b855c10..caf8678 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ const handler = new Handler( }, { url, // The HTML pages URL is used to resolve relative URLs. - } + }, ); // Create a HTML parser with the handler. diff --git a/package.json b/package.json index f2661bd..ae357fd 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,39 @@ { "name": "htmlmetaparser", "version": "2.1.2", - "publishConfig": { - "access": "public" - }, "description": "A `htmlparser2` handler for parsing rich metadata from HTML. Includes HTML metadata, JSON-LD, RDFa, microdata, OEmbed, Twitter cards and AppLinks.", - "license": "Apache-2.0", + "keywords": [ + "metadata", + "scraper", + "rich", + "html", + "info", + "rdfa", + "open graph", + "oembed", + "microdata", + "json-ld" + ], + "homepage": "https://github.com/blakeembrey/node-htmlmetaparser", + "bugs": { + "url": "https://github.com/blakeembrey/node-htmlmetaparser/issues" + }, "repository": { "type": "git", "url": "git://github.com/blakeembrey/node-htmlmetaparser.git" }, + "license": "Apache-2.0", "author": { "name": "Blake Embrey", "email": "hello@blakeembrey.com", "url": "http://blakeembrey.me" }, - "homepage": "https://github.com/blakeembrey/node-htmlmetaparser", - "bugs": { - "url": "https://github.com/blakeembrey/node-htmlmetaparser/issues" - }, "main": "dist/index.js", + "typings": "dist/index.d.ts", + "files": [ + "dist/", + "vendor/" + ], "scripts": { "fixtures": "tsx scripts/fixtures.ts", "format": "ts-scripts format", @@ -29,22 +43,6 @@ "test": "ts-scripts test", "vendor": "tsx scripts/oembed-providers.ts" }, - "files": [ - "dist/", - "vendor/" - ], - "keywords": [ - "metadata", - "scraper", - "rich", - "html", - "info", - "rdfa", - "open graph", - "oembed", - "microdata", - "json-ld" - ], "dependencies": { "setvalue": "^1.0.0" }, @@ -59,7 +57,9 @@ "typescript": "^5.3.3", "vitest": "^1.0.1" }, - "typings": "dist/index.d.ts", + "publishConfig": { + "access": "public" + }, "ts-scripts": { "src": [ "src", diff --git a/scripts/fixtures.ts b/scripts/fixtures.ts index 2a14a3d..a235129 100644 --- a/scripts/fixtures.ts +++ b/scripts/fixtures.ts @@ -189,7 +189,7 @@ Promise.all( } catch { return load(); } - }) + }), ).catch((err) => { console.error(err); process.exit(1); diff --git a/scripts/oembed-providers.ts b/scripts/oembed-providers.ts index ce92dc5..4ac7147 100644 --- a/scripts/oembed-providers.ts +++ b/scripts/oembed-providers.ts @@ -10,7 +10,7 @@ fetch("http://oembed.com/providers.json") .then((data) => { return writeFile( join(__dirname, "../vendor/providers.json"), - JSON.stringify(data, null, 2) + JSON.stringify(data, null, 2), ); }) .catch((err) => { diff --git a/src/index.spec.ts b/src/index.spec.ts index f9c42ac..f1d1462 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -25,7 +25,7 @@ describe("htmlmetaparser", () => { }, { url: meta.url, - } + }, ); const parser = new Parser(handler, { decodeEntities: true }); diff --git a/src/index.ts b/src/index.ts index 30a8937..86bd107 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,11 +11,11 @@ const RDF_VALID_NAME_START_CHAR_RANGE = "\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u10000-\uEFFFF"; const RDF_NAME_START_CHAR_REGEXP = new RegExp( - `^[${RDF_VALID_NAME_START_CHAR_RANGE}]$` + `^[${RDF_VALID_NAME_START_CHAR_RANGE}]$`, ); const RDF_NAME_CHAR_REGEXP = new RegExp( - `^[${RDF_VALID_NAME_START_CHAR_RANGE}\\-\\.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$` + `^[${RDF_VALID_NAME_START_CHAR_RANGE}\\-\\.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$`, ); /** @@ -89,7 +89,7 @@ function resolveUrl(baseUrl: string, newUrl: string) { export interface HtmlValueMap { [tagName: string]: ( attrs: { [key: string]: string }, - baseUrl: string + baseUrl: string, ) => string | undefined; } @@ -321,7 +321,7 @@ export class Handler { constructor( protected callback: (err: Error | null, result: Result) => void, - protected options: Options + protected options: Options, ) {} onend() { @@ -405,7 +405,7 @@ export class Handler { last(this._microdataNodes)!, id, split(itempropAttr), - newNode + newNode, ); } else { this.result.microdata = this.result.microdata || []; @@ -432,7 +432,7 @@ export class Handler { normalizeJsonLdValue({ "@value": value, "@language": last(this.langs), - }) + }), ); } else { context.microdataTextProperty = props; @@ -464,7 +464,7 @@ export class Handler { last(this._microdataNodes)!, id, "@type", - type || itemtypeAttr + type || itemtypeAttr, ); } @@ -558,7 +558,7 @@ export class Handler { "@value": value, "@language": last(this.langs), "@type": normalize(attributes["datatype"]), - }) + }), ); } else { if ( @@ -683,7 +683,7 @@ export class Handler { hreflang: hreflangAttr, title: normalize(attributes["title"]), href: resolvedHref, - } + }, ); } } else if (rel === "meta") { @@ -768,7 +768,7 @@ export class Handler { if (typeof jsonld === "object" && jsonld !== null) { this.result.jsonld = merge( this.result.jsonld, - jsonld as RdfaNode | RdfaNode[] + jsonld as RdfaNode | RdfaNode[], ); } } catch (e) { @@ -836,7 +836,7 @@ export class Handler { normalizeJsonLdValue({ "@value": text, "@language": last(this.langs), - }) + }), ); } @@ -849,7 +849,7 @@ export class Handler { normalizeJsonLdValue({ "@value": text, "@language": last(this.langs), - }) + }), ); } @@ -869,7 +869,7 @@ export class Handler { node: RdfaNode, id: string | undefined, itemprop: string | string[], - value: unknown + value: unknown, ) { addJsonldProperty(node, itemprop, value); @@ -889,7 +889,7 @@ export class Handler { node: RdfaNode, id: string | undefined, key: string, - value: unknown + value: unknown, ) { node[key] = value; @@ -904,7 +904,7 @@ export class Handler { private _addRdfaProperty( node: RdfaNode, property: string | string[], - value: unknown + value: unknown, ) { addJsonldProperty(node, property, value); @@ -981,7 +981,7 @@ function normalize(value?: string): string | undefined { function addJsonldProperty( obj: RdfaNode, key: string | string[], - value: unknown + value: unknown, ) { // Skip empty keys. if (!key) return; @@ -1017,7 +1017,7 @@ function last(arr: T[]): T | undefined { function getValueMap( url: string, tagName: string, - attributes: { [key: string]: string } + attributes: { [key: string]: string }, ) { const value = normalize(attributes.content); @@ -1032,11 +1032,8 @@ function getValueMap( * Merge values together. */ function merge(target: undefined | T | T[], value: T | T[]): T[] { - return (Array.isArray(target) - ? target - : target === undefined - ? [] - : [target] + return ( + Array.isArray(target) ? target : target === undefined ? [] : [target] ).concat(value); } @@ -1129,7 +1126,7 @@ export function copy(a: T, b: T) { function appendAndDedupe( list: T[], props: Array, - value: T + value: T, ): void { for (const entry of list) { const matches = props.every((x) => entry[x] === value[x]); diff --git a/src/oembed.ts b/src/oembed.ts index 025372f..1f1a7af 100644 --- a/src/oembed.ts +++ b/src/oembed.ts @@ -53,18 +53,18 @@ export class OEmbedMatch { formatResult( oembedUrl: string, url: string, - formats?: string[] + formats?: string[], ): MatchResult { const type = formats === undefined ? "json" : formats.includes("json") - ? "json" - : formats[0]; + ? "json" + : formats[0]; return { href: `${oembedUrl}?type=${encodeURIComponent( - type + type, )}&url=${encodeURIComponent(url)}`, type: `application/${type}+oembed`, };