Skip to content

Commit

Permalink
Format using prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Dec 7, 2023
1 parent d171425 commit 97d4488
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
},
Expand All @@ -59,7 +57,9 @@
"typescript": "^5.3.3",
"vitest": "^1.0.1"
},
"typings": "dist/index.d.ts",
"publishConfig": {
"access": "public"
},
"ts-scripts": {
"src": [
"src",
Expand Down
2 changes: 1 addition & 1 deletion scripts/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Promise.all(
} catch {
return load();
}
})
}),
).catch((err) => {
console.error(err);
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion scripts/oembed-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("htmlmetaparser", () => {
},
{
url: meta.url,
}
},
);

const parser = new Parser(handler, { decodeEntities: true });
Expand Down
43 changes: 20 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]*$`,
);

/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -321,7 +321,7 @@ export class Handler {

constructor(
protected callback: (err: Error | null, result: Result) => void,
protected options: Options
protected options: Options,
) {}

onend() {
Expand Down Expand Up @@ -405,7 +405,7 @@ export class Handler {
last(this._microdataNodes)!,
id,
split(itempropAttr),
newNode
newNode,
);
} else {
this.result.microdata = this.result.microdata || [];
Expand All @@ -432,7 +432,7 @@ export class Handler {
normalizeJsonLdValue({
"@value": value,
"@language": last(this.langs),
})
}),
);
} else {
context.microdataTextProperty = props;
Expand Down Expand Up @@ -464,7 +464,7 @@ export class Handler {
last(this._microdataNodes)!,
id,
"@type",
type || itemtypeAttr
type || itemtypeAttr,
);
}

Expand Down Expand Up @@ -558,7 +558,7 @@ export class Handler {
"@value": value,
"@language": last(this.langs),
"@type": normalize(attributes["datatype"]),
})
}),
);
} else {
if (
Expand Down Expand Up @@ -683,7 +683,7 @@ export class Handler {
hreflang: hreflangAttr,
title: normalize(attributes["title"]),
href: resolvedHref,
}
},
);
}
} else if (rel === "meta") {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -836,7 +836,7 @@ export class Handler {
normalizeJsonLdValue({
"@value": text,
"@language": last(this.langs),
})
}),
);
}

Expand All @@ -849,7 +849,7 @@ export class Handler {
normalizeJsonLdValue({
"@value": text,
"@language": last(this.langs),
})
}),
);
}

Expand All @@ -869,7 +869,7 @@ export class Handler {
node: RdfaNode,
id: string | undefined,
itemprop: string | string[],
value: unknown
value: unknown,
) {
addJsonldProperty(node, itemprop, value);

Expand All @@ -889,7 +889,7 @@ export class Handler {
node: RdfaNode,
id: string | undefined,
key: string,
value: unknown
value: unknown,
) {
node[key] = value;

Expand All @@ -904,7 +904,7 @@ export class Handler {
private _addRdfaProperty(
node: RdfaNode,
property: string | string[],
value: unknown
value: unknown,
) {
addJsonldProperty(node, property, value);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1017,7 +1017,7 @@ function last<T>(arr: T[]): T | undefined {
function getValueMap(
url: string,
tagName: string,
attributes: { [key: string]: string }
attributes: { [key: string]: string },
) {
const value = normalize(attributes.content);

Expand All @@ -1032,11 +1032,8 @@ function getValueMap(
* Merge values together.
*/
function merge<T>(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);
}

Expand Down Expand Up @@ -1129,7 +1126,7 @@ export function copy<T extends { [key: string]: unknown }>(a: T, b: T) {
function appendAndDedupe<T extends { href: string }>(
list: T[],
props: Array<keyof T>,
value: T
value: T,
): void {
for (const entry of list) {
const matches = props.every((x) => entry[x] === value[x]);
Expand Down
8 changes: 4 additions & 4 deletions src/oembed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
};
Expand Down

0 comments on commit 97d4488

Please sign in to comment.