Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"@typescript-eslint/prefer-includes": 2,
"@typescript-eslint/switch-exhaustiveness-check": 2,

"dot-notation": 0,

"jsdoc/require-param-type": 0,
"jsdoc/require-returns-type": 0
}
Expand Down
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"sideEffects": false,
"main": "lib/index.js",
"types": "lib/index.d.ts",
"module": "lib/esm/index.js",
"exports": {
"require": "./lib/index.js",
"import": "./lib/esm/index.js"
},
"files": [
"lib/**/*"
],
Expand All @@ -23,8 +28,9 @@
"format:es": "npm run lint:es -- --fix",
"format:prettier": "npm run prettier -- --write",
"prettier": "prettier \"**/*.{ts,md,json,yml}\" --ignore-path .gitignore",
"build": "tsc",
"build:docs": "typedoc --hideGenerator --exclude \"**/*+(index|.spec).ts\" --categorizeByGroup false --sort enum-value-ascending --sort alphabetical src",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc --sourceRoot https://raw.githubusercontent.com/fb55/domutils/$(git rev-parse HEAD)/src/",
"build:esm": "npm run build:cjs -- --module esnext --target es2019 --outDir lib/esm && echo '{\"type\":\"module\"}' > lib/esm/package.json",
"prepare": "npm run build"
},
"repository": {
Expand Down Expand Up @@ -57,7 +63,11 @@
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
"testEnvironment": "node",
"coverageProvider": "v8",
"moduleNameMapper": {
"^(.*)\\.js$": "$1"
}
},
"prettier": {
"tabWidth": 4
Expand Down
19 changes: 10 additions & 9 deletions src/feeds.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AnyNode, Element } from "domhandler";
import { textContent } from "./stringify";
import { getElementsByTagName } from "./legacy";
import { textContent } from "./stringify.js";
import { getElementsByTagName } from "./legacy.js";

/**
* The type of a media item.
Expand Down Expand Up @@ -108,7 +108,7 @@ function getAtomFeed(feedRoot: Element) {
addConditionally(entry, "id", "id", children);
addConditionally(entry, "title", "title", children);

const href = getOneElement("link", children)?.attribs.href;
const href = getOneElement("link", children)?.attribs["href"];
if (href) {
entry.link = href;
}
Expand All @@ -130,7 +130,7 @@ function getAtomFeed(feedRoot: Element) {

addConditionally(feed, "id", "id", childs);
addConditionally(feed, "title", "title", childs);
const href = getOneElement("link", childs)?.attribs.href;
const href = getOneElement("link", childs)?.attribs["href"];
if (href) {
feed.link = href;
}
Expand Down Expand Up @@ -211,10 +211,10 @@ function getMediaElements(where: AnyNode[]): FeedItemMedia[] {
const { attribs } = elem;

const media: FeedItemMedia = {
medium: attribs.medium as unknown as
medium: attribs["medium"] as unknown as
| FeedItemMediaMedium
| undefined,
isDefault: !!attribs.isDefault,
isDefault: !!attribs["isDefault"],
};

for (const attrib of MEDIA_KEYS_STRING) {
Expand All @@ -229,9 +229,10 @@ function getMediaElements(where: AnyNode[]): FeedItemMedia[] {
}
}

if (attribs.expression) {
media.expression =
attribs.expression as unknown as FeedItemMediaExpression;
if (attribs["expression"]) {
media.expression = attribs[
"expression"
] as unknown as FeedItemMediaExpression;
}

return media;
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export * from "./stringify";
export * from "./traversal";
export * from "./manipulation";
export * from "./querying";
export * from "./legacy";
export * from "./helpers";
export * from "./feeds";
export * from "./stringify.js";
export * from "./traversal.js";
export * from "./manipulation.js";
export * from "./querying.js";
export * from "./legacy.js";
export * from "./helpers.js";
export * from "./feeds.js";
/** @deprecated Use these methods from `domhandler` directly. */
export {
isTag,
Expand Down
13 changes: 9 additions & 4 deletions src/legacy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isTag, isText, AnyNode, Element } from "domhandler";
import { ElementType } from "domelementtype";
import { filter, findOne } from "./querying";
import type { ElementType } from "domelementtype";
import { filter, findOne } from "./querying.js";

type TestType = (elem: AnyNode) => boolean;

Expand Down Expand Up @@ -148,7 +148,12 @@ export function getElementsByTagName(
recurse = true,
limit = Infinity
): Element[] {
return filter(Checks.tag_name(tagName), nodes, recurse, limit) as Element[];
return filter(
Checks["tag_name"](tagName),
nodes,
recurse,
limit
) as Element[];
}

/**
Expand All @@ -165,5 +170,5 @@ export function getElementsByTagType(
recurse = true,
limit = Infinity
): AnyNode[] {
return filter(Checks.tag_type(type as string), nodes, recurse, limit);
return filter(Checks["tag_type"](type as string), nodes, recurse, limit);
}
35 changes: 20 additions & 15 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
// "sourceMap": true, /* Generates corresponding '.map' file. */
"outDir": "lib" /* Redirect output structure to the directory. */,
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
"target": "es5",
"module": "commonjs",
"lib": ["ES2015.Core"],
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "lib",

/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
"strict": true,

/* Additional Checks */
"noUnusedLocals": true /* Report errors on unused locals. */,
"noUnusedParameters": true /* Report errors on unused parameters. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"importsNotUsedAsValues": "error",
"isolatedModules": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUnusedLocals": true,
"noUnusedParameters": true,

/* Module Resolution Options */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true
},
"include": ["src"],
Expand Down