김대선

카카오 채용정보 기능을 개발할 kakao branch 생성 및 kakao.js 파일 생성

Showing 421 changed files with 3090 additions and 0 deletions
const express = require('express')
const puppeteer = require('puppeteer')
const naverRouter = require('./router/naver')
const app = express();
const server = app.listen(3000,()=>{
const host = server.address().address
......@@ -8,6 +12,8 @@ const server = app.listen(3000,()=>{
console.log("app listening at http://%s:%s", host, port)
})
app.use('/naver', naverRouter)
app.get('/', (req, res)=>{
res.send("this is home!")
})
\ No newline at end of file
......
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../nanoid/bin/nanoid.cjs" "$@"
ret=$?
else
node "$basedir/../nanoid/bin/nanoid.cjs" "$@"
ret=$?
fi
exit $ret
@ECHO off
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\node.exe" (
SET "_prog=%dp0%\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)
"%_prog%" "%dp0%\..\nanoid\bin\nanoid.cjs" %*
ENDLOCAL
EXIT /b %errorlevel%
:find_dp0
SET dp0=%~dp0
EXIT /b
#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
& "$basedir/node$exe" "$basedir/../nanoid/bin/nanoid.cjs" $args
$ret=$LASTEXITCODE
} else {
& "node$exe" "$basedir/../nanoid/bin/nanoid.cjs" $args
$ret=$LASTEXITCODE
}
exit $ret
This diff is collapsed. Click to expand it.
#boolbase
This very simple module provides two basic functions, one that always returns true (`trueFunc`) and one that always returns false (`falseFunc`).
###WTF?
By having only a single instance of these functions around, it's possible to do some nice optimizations. Eg. [`CSSselect`](https://github.com/fb55/CSSselect) uses these functions to determine whether a selector won't match any elements. If that's the case, the DOM doesn't even have to be touched.
###And why is this a separate module?
I'm trying to modularize `CSSselect` and most modules depend on these functions. IMHO, having a separate module is the easiest solution to this problem.
\ No newline at end of file
module.exports = {
trueFunc: function trueFunc(){
return true;
},
falseFunc: function falseFunc(){
return false;
}
};
\ No newline at end of file
{
"name": "boolbase",
"version": "1.0.0",
"description": "two functions: One that returns true, one that returns false",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/fb55/boolbase"
},
"keywords": [
"boolean",
"function"
],
"author": "Felix Boehm <me@feedic.com>",
"license": "ISC",
"bugs": {
"url": "https://github.com/fb55/boolbase/issues"
},
"homepage": "https://github.com/fb55/boolbase"
}
Copyright (c) Felix Böhm
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# cheerio-select [![NPM version](http://img.shields.io/npm/v/cheerio-select.svg)](https://npmjs.org/package/cheerio-select) [![Build Status](https://travis-ci.org/cheeriojs/cheerio-select.svg?branch=master)](http://travis-ci.org/cheeriojs/cheerio-select) [![Downloads](https://img.shields.io/npm/dm/cheerio-select.svg)](https://npmjs.org/package/cheerio-select) [![Coverage](https://coveralls.io/repos/cheeriojs/cheerio-select/badge.svg?branch=master)](https://coveralls.io/r/cheeriojs/cheerio-select)
CSS selector engine supporting jQuery selectors, based on [`css-select`](https://github.com/fb55/css-select).
Supports all jQuery positional pseudo-selectors:
- `:first`
- `:last`
- `:eq`
- `:nth`
- `:gt`
- `:lt`
- `:even`
- `:odd`
- `:not(:positional)`, where `:positional` is any of the above.
This library is a thin wrapper around [`css-select`](https://github.com/fb55/css-select).
Only use this module if you will actually use jQuery positional selectors.
import type { NodeWithChildren } from "domhandler";
import type { Selector } from "css-what";
export declare function getDocumentRoot(node: NodeWithChildren): NodeWithChildren;
export declare function groupSelectors(selectors: Selector[][]): [plain: Selector[][], filtered: Selector[][]];
//# sourceMappingURL=helpers.d.ts.map
\ No newline at end of file
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAGxE;AAED,wBAAgB,cAAc,CAC1B,SAAS,EAAE,QAAQ,EAAE,EAAE,GACxB,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC,CAa/C"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.groupSelectors = exports.getDocumentRoot = void 0;
var positionals_1 = require("./positionals");
function getDocumentRoot(node) {
while (node.parent)
node = node.parent;
return node;
}
exports.getDocumentRoot = getDocumentRoot;
function groupSelectors(selectors) {
var filteredSelectors = [];
var plainSelectors = [];
for (var _i = 0, selectors_1 = selectors; _i < selectors_1.length; _i++) {
var selector = selectors_1[_i];
if (selector.some(positionals_1.isFilter)) {
filteredSelectors.push(selector);
}
else {
plainSelectors.push(selector);
}
}
return [plainSelectors, filteredSelectors];
}
exports.groupSelectors = groupSelectors;
import { Options as CSSSelectOptions } from "css-select";
import type { Element, Node } from "domhandler";
export { filters, pseudos, aliases } from "css-select";
export declare type Options = CSSSelectOptions<Node, Element>;
export declare function is(element: Element, selector: string | ((el: Element) => boolean), options?: Options): boolean;
export declare function some(elements: Element[], selector: string | ((el: Element) => boolean), options?: Options): boolean;
export declare function filter(selector: string, elements: Element[], options?: Options): Element[];
export declare function select(selector: string | ((el: Element) => boolean), root: Node | Node[], options?: Options): Element[];
//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGH,OAAO,IAAI,gBAAgB,EAE9B,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAKhD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAYvD,oBAAY,OAAO,GAAG,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAEtD,wBAAgB,EAAE,CACd,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,EAC7C,OAAO,GAAE,OAAY,GACtB,OAAO,CAWT;AAED,wBAAgB,IAAI,CAChB,QAAQ,EAAE,OAAO,EAAE,EACnB,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,EAC7C,OAAO,GAAE,OAAY,GACtB,OAAO,CAWT;AAsCD,wBAAgB,MAAM,CAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,OAAY,GACtB,OAAO,EAAE,CAEX;AA0FD,wBAAgB,MAAM,CAClB,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,EAC7C,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,EACnB,OAAO,GAAE,OAAY,GACtB,OAAO,EAAE,CAuBX"}
\ No newline at end of file
This diff is collapsed. Click to expand it.
import type { Selector, PseudoSelector } from "css-what";
export declare type Filter = "first" | "last" | "eq" | "nth" | "gt" | "lt" | "even" | "odd" | "not";
export declare const filterNames: Set<string>;
export interface CheerioSelector extends PseudoSelector {
name: Filter;
data: string | null;
}
export declare function isFilter(s: Selector): s is CheerioSelector;
export declare function getLimit(filter: Filter, data: string | null): number;
//# sourceMappingURL=positionals.d.ts.map
\ No newline at end of file
{"version":3,"file":"positionals.d.ts","sourceRoot":"","sources":["../src/positionals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEzD,oBAAY,MAAM,GACZ,OAAO,GACP,MAAM,GACN,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,IAAI,GACJ,MAAM,GACN,KAAK,GACL,KAAK,CAAC;AACZ,eAAO,MAAM,WAAW,EAAE,GAAG,CAAC,MAAM,CASlC,CAAC;AAEH,MAAM,WAAW,eAAgB,SAAQ,cAAc;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,IAAI,eAAe,CAS1D;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAgBpE"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLimit = exports.isFilter = exports.filterNames = void 0;
exports.filterNames = new Set([
"first",
"last",
"eq",
"gt",
"nth",
"lt",
"even",
"odd",
]);
function isFilter(s) {
if (s.type !== "pseudo")
return false;
if (exports.filterNames.has(s.name))
return true;
if (s.name === "not" && Array.isArray(s.data)) {
// Only consider `:not` with embedded filters
return s.data.some(function (s) { return s.some(isFilter); });
}
return false;
}
exports.isFilter = isFilter;
function getLimit(filter, data) {
var num = data != null ? parseInt(data, 10) : NaN;
switch (filter) {
case "first":
return 1;
case "nth":
case "eq":
return isFinite(num) ? (num >= 0 ? num + 1 : Infinity) : 0;
case "lt":
return isFinite(num) ? (num >= 0 ? num : Infinity) : 0;
case "gt":
return isFinite(num) ? Infinity : 0;
default:
return Infinity;
}
}
exports.getLimit = getLimit;
{
"name": "cheerio-select",
"description": "CSS selector engine supporting jQuery selectors",
"version": "1.4.0",
"author": "Felix Boehm <me@feedic.com>",
"funding": {
"url": "https://github.com/sponsors/fb55"
},
"license": "BSD-2-Clause",
"sideEffects": false,
"repository": {
"type": "git",
"url": "git://github.com/cheeriojs/cheerio-select.git"
},
"directories": {
"lib": "lib/"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib/**/*"
],
"scripts": {
"test": "jest --coverage && npm run lint",
"coverage": "cat coverage/lcov.info | coveralls",
"lint": "npm run lint:es && npm run lint:prettier",
"lint:es": "eslint src",
"lint:prettier": "npm run format:prettier:raw -- --check",
"format": "npm run format:es && npm run format:prettier",
"format:es": "npm run lint:es -- --fix",
"format:prettier": "npm run format:prettier:raw -- --write",
"format:prettier:raw": "prettier '**/*.{ts,md,json,yml}'",
"build": "tsc",
"prepare": "npm run build"
},
"dependencies": {
"css-select": "^4.1.2",
"css-what": "^5.0.0",
"domelementtype": "^2.2.0",
"domhandler": "^4.2.0",
"domutils": "^2.6.0"
},
"devDependencies": {
"@types/jest": "^26.0.22",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"coveralls": "^3.1.0",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.2.0",
"htmlparser2": "^6.1.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"ts-jest": "^26.5.5",
"typescript": "^4.2.4"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
},
"prettier": {
"tabWidth": 4
}
}
This diff is collapsed. Click to expand it.
MIT License
Copyright (c) 2016 Matt Mueller
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/api/attributes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,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AC,EACF,MAAM,GACN,CAAC,CACC,IAAI,EAAE,OAAO,EACb,CAAC,EAAE,MAAM,EACT,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,OAAO,KACf,MAAM,CAAC,EAChB,QAAQ,CAAC,EAAE,OAAO,GACjB,CAAC,CA+CH;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,EAAE,CAAC,CAAC,SAAS,IAAI,EAC/B,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,QAAQ,CAAC,EACL,MAAM,GACN,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,GACpD,OAAO,CAAC,CAAC,CAAC,GACV,CAAC,GACD,IAAI,GACP,OAAO,CAKT"}
\ No newline at end of file
This diff is collapsed. Click to expand it.
import type { Element, Node } from 'domhandler';
import type { Cheerio } from '../cheerio';
/**
* Get the value of a style property for the first element in the set of matched elements.
*
* @category CSS
* @param names - Optionally the names of the property of interest.
* @returns A map of all of the style properties.
* @see {@link https://api.jquery.com/css/}
*/
export declare function css<T extends Node>(this: Cheerio<T>, names?: string[]): Record<string, string>;
/**
* Get the value of a style property for the first element in the set of matched elements.
*
* @category CSS
* @param names - The name of the property.
* @returns The property value for the given name.
* @see {@link https://api.jquery.com/css/}
*/
export declare function css<T extends Node>(this: Cheerio<T>, name: string): string | undefined;
/**
* Set one CSS property for every matched element.
*
* @category CSS
* @param prop - The name of the property.
* @param val - The new value.
* @returns The instance itself.
* @see {@link https://api.jquery.com/css/}
*/
export declare function css<T extends Node>(this: Cheerio<T>, prop: string, val: string | ((this: Element, i: number, style: string) => string | undefined)): Cheerio<T>;
/**
* Set multiple CSS properties for every matched element.
*
* @category CSS
* @param prop - The name of the property.
* @param val - The new value.
* @returns The instance itself.
* @see {@link https://api.jquery.com/css/}
*/
export declare function css<T extends Node>(this: Cheerio<T>, prop: Record<string, string>): Cheerio<T>;
//# sourceMappingURL=css.d.ts.map
\ No newline at end of file
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/api/css.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,KAAK,CAAC,EAAE,MAAM,EAAE,GACf,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1B;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAAC;AACtB;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,EACZ,GAAG,EACC,MAAM,GACN,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GACpE,OAAO,CAAC,CAAC,CAAC,CAAC;AACd;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,OAAO,CAAC,CAAC,CAAC,CAAC"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.css = void 0;
var utils_1 = require("../utils");
function css(prop, val) {
if ((prop != null && val != null) ||
// When `prop` is a "plain" object
(typeof prop === 'object' && !Array.isArray(prop))) {
return utils_1.domEach(this, function (idx, el) {
if (utils_1.isTag(el)) {
// `prop` can't be an array here anymore.
setCss(el, prop, val, idx);
}
});
}
return getCss(this[0], prop);
}
exports.css = css;
/**
* Set styles of all elements.
*
* @private
* @param el - Element to set style of.
* @param prop - Name of property.
* @param value - Value to set property to.
* @param idx - Optional index within the selection.
*/
function setCss(el, prop, value, idx) {
if (typeof prop === 'string') {
var styles = getCss(el);
var val = typeof value === 'function' ? value.call(el, idx, styles[prop]) : value;
if (val === '') {
delete styles[prop];
}
else if (val != null) {
styles[prop] = val;
}
el.attribs.style = stringify(styles);
}
else if (typeof prop === 'object') {
Object.keys(prop).forEach(function (k, i) {
setCss(el, k, prop[k], i);
});
}
}
function getCss(el, prop) {
if (!el || !utils_1.isTag(el))
return;
var styles = parse(el.attribs.style);
if (typeof prop === 'string') {
return styles[prop];
}
if (Array.isArray(prop)) {
var newStyles_1 = {};
prop.forEach(function (item) {
if (styles[item] != null) {
newStyles_1[item] = styles[item];
}
});
return newStyles_1;
}
return styles;
}
/**
* Stringify `obj` to styles.
*
* @private
* @category CSS
* @param obj - Object to stringify.
* @returns The serialized styles.
*/
function stringify(obj) {
return Object.keys(obj).reduce(function (str, prop) { return "" + str + (str ? ' ' : '') + prop + ": " + obj[prop] + ";"; }, '');
}
/**
* Parse `styles`.
*
* @private
* @category CSS
* @param styles - Styles to be parsed.
* @returns The parsed styles.
*/
function parse(styles) {
styles = (styles || '').trim();
if (!styles)
return {};
return styles.split(';').reduce(function (obj, str) {
var n = str.indexOf(':');
// Skip if there is no :, or if it is the first/last character
if (n < 1 || n === str.length - 1)
return obj;
obj[str.slice(0, n).trim()] = str.slice(n + 1).trim();
return obj;
}, {});
}
import type { Node } from 'domhandler';
import type { Cheerio } from '../cheerio';
/**
* Encode a set of form elements as a string for submission.
*
* @category Forms
* @returns The serialized form.
* @see {@link https://api.jquery.com/serialize/}
*/
export declare function serialize<T extends Node>(this: Cheerio<T>): string;
interface SerializedField {
name: string;
value: string;
}
/**
* Encode a set of form elements as an array of names and values.
*
* @category Forms
* @example
*
* ```js
* $('<form><input name="foo" value="bar" /></form>').serializeArray();
* //=> [ { name: 'foo', value: 'bar' } ]
* ```
*
* @returns The serialized form.
* @see {@link https://api.jquery.com/serializeArray/}
*/
export declare function serializeArray<T extends Node>(this: Cheerio<T>): SerializedField[];
export {};
//# sourceMappingURL=forms.d.ts.map
\ No newline at end of file
{"version":3,"file":"forms.d.ts","sourceRoot":"","sources":["../../src/api/forms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AAWtD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAYlE;AAED,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,IAAI,EAC3C,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GACf,eAAe,EAAE,CAuCnB"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeArray = exports.serialize = void 0;
var utils_1 = require("../utils");
/*
* https://github.com/jquery/jquery/blob/2.1.3/src/manipulation/var/rcheckableType.js
* https://github.com/jquery/jquery/blob/2.1.3/src/serialize.js
*/
var submittableSelector = 'input,select,textarea,keygen';
var r20 = /%20/g;
var rCRLF = /\r?\n/g;
/**
* Encode a set of form elements as a string for submission.
*
* @category Forms
* @returns The serialized form.
* @see {@link https://api.jquery.com/serialize/}
*/
function serialize() {
// Convert form elements into name/value objects
var arr = this.serializeArray();
// Serialize each element into a key/value string
var retArr = arr.map(function (data) {
return encodeURIComponent(data.name) + "=" + encodeURIComponent(data.value);
});
// Return the resulting serialization
return retArr.join('&').replace(r20, '+');
}
exports.serialize = serialize;
/**
* Encode a set of form elements as an array of names and values.
*
* @category Forms
* @example
*
* ```js
* $('<form><input name="foo" value="bar" /></form>').serializeArray();
* //=> [ { name: 'foo', value: 'bar' } ]
* ```
*
* @returns The serialized form.
* @see {@link https://api.jquery.com/serializeArray/}
*/
function serializeArray() {
// Resolve all form elements from either forms or collections of form elements
var Cheerio = this.constructor;
return this.map(function (_, elem) {
var $elem = Cheerio(elem);
if (utils_1.isTag(elem) && elem.name === 'form') {
return $elem.find(submittableSelector).toArray();
}
return $elem.filter(submittableSelector).toArray();
})
.filter(
// Verify elements have a name (`attr.name`) and are not disabled (`:enabled`)
'[name!=""]:enabled' +
// And cannot be clicked (`[type=submit]`) or are used in `x-www-form-urlencoded` (`[type=file]`)
':not(:submit, :button, :image, :reset, :file)' +
// And are either checked/don't have a checkable state
':matches([checked], :not(:checkbox, :radio))'
// Convert each of the elements to its value(s)
)
.map(function (_, elem) {
var _a;
var $elem = Cheerio(elem);
var name = $elem.attr('name'); // We have filtered for elements with a name before.
// If there is no value set (e.g. `undefined`, `null`), then default value to empty
var value = (_a = $elem.val()) !== null && _a !== void 0 ? _a : '';
// If we have an array of values (e.g. `<select multiple>`), return an array of key/value pairs
if (Array.isArray(value)) {
return value.map(function (val) {
/*
* We trim replace any line endings (e.g. `\r` or `\r\n` with `\r\n`) to guarantee consistency across platforms
* These can occur inside of `<textarea>'s`
*/
return ({ name: name, value: val.replace(rCRLF, '\r\n') });
});
}
// Otherwise (e.g. `<input type="text">`, return only one key/value pair
return { name: name, value: value.replace(rCRLF, '\r\n') };
})
.toArray();
}
exports.serializeArray = serializeArray;
This diff is collapsed. Click to expand it.
{"version":3,"file":"manipulation.d.ts","sourceRoot":"","sources":["../../src/api/manipulation.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAmC,MAAM,YAAY,CAAC;AAKnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO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AAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAEjE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAC/D,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,GAC9D,OAAO,CAAC,CAAC,CAAC,CAAC;AA6Bd;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAElE"}
\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
{"version":3,"file":"traversing.d.ts","sourceRoot":"","sources":["../../src/api/traversing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAe,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAI1C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,kBAAkB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GACvD,OAAO,CAAC,OAAO,CAAC,CA+BlB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,IAAI,EACnC,IAAI,EAAE,OAAO,C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AAE,MAAM,GACX,OAAO,CAAC,CAAC,CAAC,CAEZ;AAkBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,IAAI,EAChD,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EACpC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,GAC5B,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAIhB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,IAAI,EACpC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAIf"}
\ No newline at end of file
This diff is collapsed. Click to expand it.
import { CheerioOptions, InternalOptions } from './options';
import type { Node, Document, Element } from 'domhandler';
import * as Static from './static';
import type { load } from './load';
import { SelectorType, BasicAcceptedElems } from './types';
import * as Attributes from './api/attributes';
import * as Traversing from './api/traversing';
import * as Manipulation from './api/manipulation';
import * as Css from './api/css';
import * as Forms from './api/forms';
declare type AttributesType = typeof Attributes;
declare type TraversingType = typeof Traversing;
declare type ManipulationType = typeof Manipulation;
declare type CssType = typeof Css;
declare type FormsType = typeof Forms;
export declare class Cheerio<T> implements ArrayLike<T> {
length: number;
[index: number]: T;
options: InternalOptions;
/**
* The root of the document. Can be overwritten by using the `root` argument
* of the constructor.
*
* @private
*/
_root: Cheerio<Document> | undefined;
/** @function */
find: typeof Traversing.find;
/**
* The root the document was originally loaded with. Same as the static
* `_root` property.
*
* @private
*/
_originalRoot: Document | undefined;
/**
* The root the document was originally loaded with. Set in `.load`.
*
* @private
*/
static _root: Document | undefined;
/**
* The options the document was originally loaded with. Set in `.load`.
*
* @private
*/
static _options: InternalOptions | undefined;
static html: typeof Static.html;
static xml: typeof Static.xml;
static text: typeof Static.text;
static parseHTML: typeof Static.parseHTML;
static root: typeof Static.root;
static contains: typeof Static.contains;
static merge: typeof Static.merge;
static load: typeof load;
/** Mimic jQuery's prototype alias for plugin authors. */
static fn: Cheerio<any>;
/**
* Instance of cheerio. Methods are specified in the modules. Usage of this
* constructor is not recommended. Please use $.load instead.
*
* @private
* @param selector - The new selection.
* @param context - Context of the selection.
* @param root - Sets the root node.
* @param options - Options for the instance.
*/
constructor(selector?: T extends Node ? BasicAcceptedElems<T> : Cheerio<T> | T[], context?: BasicAcceptedElems<Node> | null, root?: BasicAcceptedElems<Document>, options?: CheerioOptions);
prevObject: Cheerio<Node> | undefined;
/**
* Make a cheerio object.
*
* @private
* @param dom - The contents of the new object.
* @param context - The context of the new object.
* @returns The new cheerio object.
*/
_make<T>(dom: Cheerio<T> | T[] | T | string, context?: BasicAcceptedElems<Node> | null, root?: BasicAcceptedElems<Document> | undefined): Cheerio<T>;
/**
* Retrieve all the DOM elements contained in the jQuery set as an array.
*
* @example
*
* ```js
* $('li').toArray();
* //=> [ {...}, {...}, {...} ]
* ```
*
* @returns The contained items.
*/
toArray(): T[];
}
export interface Cheerio<T> extends AttributesType, TraversingType, ManipulationType, CssType, FormsType {
cheerio: '[cheerio object]';
splice: typeof Array.prototype.slice;
[Symbol.iterator](): Iterator<T>;
}
declare type CheerioClassType = typeof Cheerio;
/**
* Wrapper around the `Cheerio` class, making it possible to create a new
* instance without using `new`.
*/
export interface CheerioAPI extends CheerioClassType {
<T extends Node, S extends string>(selector?: S | BasicAcceptedElems<T>, context?: BasicAcceptedElems<Node> | null, root?: BasicAcceptedElems<Document>, options?: CheerioOptions): Cheerio<S extends SelectorType ? Element : T>;
}
declare const _default: CheerioAPI;
export default _default;
//# sourceMappingURL=cheerio.d.ts.map
\ No newline at end of file
{"version":3,"file":"cheerio.d.ts","sourceRoot":"","sources":["../src/cheerio.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,eAAe,EAGhB,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AAErC,aAAK,cAAc,GAAG,OAAO,UAAU,CAAC;AACxC,aAAK,cAAc,GAAG,OAAO,UAAU,CAAC;AACxC,aAAK,gBAAgB,GAAG,OAAO,YAAY,CAAC;AAC5C,aAAK,OAAO,GAAG,OAAO,GAAG,CAAC;AAC1B,aAAK,SAAS,GAAG,OAAO,KAAK,CAAC;AAO9B,qBAAa,OAAO,CAAC,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC;IAC7C,MAAM,EAAG,MAAM,CAAC;IAChB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;IAEnB,OAAO,EAAG,eAAe,CAAC;IAC1B;;;;;OAKG;IACH,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;IACrC,gBAAgB;IAChB,IAAI,EAAG,OAAO,UAAU,CAAC,IAAI,CAAC;IAC9B;;;;;OAKG;IACH,aAAa,EAAE,QAAQ,GAAG,SAAS,CA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C;IAE5B,MAAM,EAAE,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;IACrC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;CAClC;AAyBD,aAAK,gBAAgB,GAAG,OAAO,OAAO,CAAC;AAEvC;;;GAGG;AACH,MAAM,WAAW,UAAW,SAAQ,gBAAgB;IAClD,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,MAAM,EAC/B,QAAQ,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,EACpC,OAAO,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAAG,IAAI,EACzC,IAAI,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EACnC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,SAAS,YAAY,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC;CAClD;;AAGD,wBAAkD"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cheerio = void 0;
var tslib_1 = require("tslib");
var parse_1 = tslib_1.__importDefault(require("./parse"));
var options_1 = tslib_1.__importStar(require("./options"));
var utils_1 = require("./utils");
var Static = tslib_1.__importStar(require("./static"));
var Attributes = tslib_1.__importStar(require("./api/attributes"));
var Traversing = tslib_1.__importStar(require("./api/traversing"));
var Manipulation = tslib_1.__importStar(require("./api/manipulation"));
var Css = tslib_1.__importStar(require("./api/css"));
var Forms = tslib_1.__importStar(require("./api/forms"));
/*
* The API
*/
var api = [Attributes, Traversing, Manipulation, Css, Forms];
var Cheerio = /** @class */ (function () {
/**
* Instance of cheerio. Methods are specified in the modules. Usage of this
* constructor is not recommended. Please use $.load instead.
*
* @private
* @param selector - The new selection.
* @param context - Context of the selection.
* @param root - Sets the root node.
* @param options - Options for the instance.
*/
function Cheerio(selector, context, root, options) {
var _this = this;
if (!(this instanceof Cheerio)) {
return new Cheerio(selector, context, root, options);
}
this.length = 0;
this.options = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, options_1.default), this.options), options_1.flatten(options));
// $(), $(null), $(undefined), $(false)
if (!selector)
return this;
if (root) {
if (typeof root === 'string')
root = parse_1.default(root, this.options, false);
this._root = Cheerio.call(this, root);
}
// $($)
if (utils_1.isCheerio(selector))
return selector;
var elements = typeof selector === 'string' && utils_1.isHtml(selector)
? // $(<html>)
parse_1.default(selector, this.options, false).children
: isNode(selector)
? // $(dom)
[selector]
: Array.isArray(selector)
? // $([dom])
selector
: null;
if (elements) {
elements.forEach(function (elem, idx) {
_this[idx] = elem;
});
this.length = elements.length;
return this;
}
// We know that our selector is a string now.
var search = selector;
var searchContext = !context
? // If we don't have a context, maybe we have a root, from loading
this._root
: typeof context === 'string'
? utils_1.isHtml(context)
? // $('li', '<ul>...</ul>')
new Cheerio(parse_1.default(context, this.options, false))
: // $('li', 'ul')
((search = context + " " + search), this._root)
: utils_1.isCheerio(context)
? // $('li', $)
context
: // $('li', node), $('li', [nodes])
new Cheerio(context);
// If we still don't have a context, return
if (!searchContext)
return this;
/*
* #id, .class, tag
*/
// @ts-expect-error No good way to type this — we will always return `Cheerio<Element>` here.
return searchContext.find(search);
}
/**
* Make a cheerio object.
*
* @private
* @param dom - The contents of the new object.
* @param context - The context of the new object.
* @returns The new cheerio object.
*/
Cheerio.prototype._make = function (dom, context, root) {
if (root === void 0) { root = this._root; }
var cheerio = new this.constructor(dom, context, root, this.options);
cheerio.prevObject = this;
return cheerio;
};
/**
* Retrieve all the DOM elements contained in the jQuery set as an array.
*
* @example
*
* ```js
* $('li').toArray();
* //=> [ {...}, {...}, {...} ]
* ```
*
* @returns The contained items.
*/
Cheerio.prototype.toArray = function () {
return this.get();
};
Cheerio.html = Static.html;
Cheerio.xml = Static.xml;
Cheerio.text = Static.text;
Cheerio.parseHTML = Static.parseHTML;
Cheerio.root = Static.root;
Cheerio.contains = Static.contains;
Cheerio.merge = Static.merge;
/** Mimic jQuery's prototype alias for plugin authors. */
Cheerio.fn = Cheerio.prototype;
return Cheerio;
}());
exports.Cheerio = Cheerio;
/** Set a signature of the object. */
Cheerio.prototype.cheerio = '[cheerio object]';
/*
* Make cheerio an array-like object
*/
Cheerio.prototype.splice = Array.prototype.splice;
// Support for (const element of $(...)) iteration:
Cheerio.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
// Plug in the API
api.forEach(function (mod) { return Object.assign(Cheerio.prototype, mod); });
function isNode(obj) {
return (!!obj.name ||
obj.type === 'root' ||
obj.type === 'text' ||
obj.type === 'comment');
}
// Make it possible to call Cheerio without using `new`.
exports.default = Cheerio;
import Cheerio from './cheerio';
/**
* The default cheerio instance.
*
* @deprecated Use the function returned by `load` instead.
*/
export default Cheerio;
/**
* The main types of Cheerio objects.
*
* @category Cheerio
*/
export type { Cheerio, CheerioAPI } from './cheerio';
/**
* Types used in signatures of Cheerio methods.
*
* @category Cheerio
*/
export * from './types';
export type { CheerioOptions, HTMLParser2Options, Parse5Options, } from './options';
/**
* Re-exporting all of the node types.
*
* @category DOM Node
*/
export type { Node, NodeWithChildren, Element, Document } from 'domhandler';
export * from './load';
import * as staticMethods from './static';
/**
* In order to promote consistency with the jQuery library, users are encouraged
* to instead use the static method of the same name.
*
* @deprecated
* @example
*
* ```js
* const $ = cheerio.load('<div><p></p></div>');
*
* $.contains($('div').get(0), $('p').get(0));
* //=> true
*
* $.contains($('p').get(0), $('div').get(0));
* //=> false
* ```
*
* @returns {boolean}
*/
export declare const contains: typeof staticMethods.contains;
/**
* In order to promote consistency with the jQuery library, users are encouraged
* to instead use the static method of the same name.
*
* @deprecated
* @example
*
* ```js
* const $ = cheerio.load('');
*
* $.merge([1, 2], [3, 4]);
* //=> [1, 2, 3, 4]
* ```
*/
export declare const merge: typeof staticMethods.merge;
/**
* In order to promote consistency with the jQuery library, users are encouraged
* to instead use the static method of the same name as it is defined on the
* "loaded" Cheerio factory function.
*
* @deprecated See {@link static/parseHTML}.
* @example
*
* ```js
* const $ = cheerio.load('');
* $.parseHTML('<b>markup</b>');
* ```
*/
export declare const parseHTML: typeof staticMethods.parseHTML;
/**
* Users seeking to access the top-level element of a parsed document should
* instead use the `root` static method of a "loaded" Cheerio function.
*
* @deprecated
* @example
*
* ```js
* const $ = cheerio.load('');
* $.root();
* ```
*/
export declare const root: typeof staticMethods.root;
//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC;;;;GAIG;AACH,eAAe,OAAO,CAAC;AAEvB;;;;GAIG;AACH,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACrD;;;;GAIG;AACH,cAAc,SAAS,CAAC;AACxB,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,aAAa,GACd,MAAM,WAAW,CAAC;AACnB;;;;GAIG;AACH,YAAY,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5E,cAAc,QAAQ,CAAC;AAIvB,OAAO,KAAK,aAAa,MAAM,UAAU,CAAC;AAE1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAQ,QAAQ,+BAAkB,CAAC;AAE1C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAQ,KAAK,4BAAkB,CAAC;AAEvC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAQ,SAAS,gCAAkB,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,eAAO,MAAQ,IAAI,2BAAkB,CAAC"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.root = exports.parseHTML = exports.merge = exports.contains = void 0;
var tslib_1 = require("tslib");
var cheerio_1 = tslib_1.__importDefault(require("./cheerio"));
/**
* The default cheerio instance.
*
* @deprecated Use the function returned by `load` instead.
*/
exports.default = cheerio_1.default;
/**
* Types used in signatures of Cheerio methods.
*
* @category Cheerio
*/
tslib_1.__exportStar(require("./types"), exports);
tslib_1.__exportStar(require("./load"), exports);
var load_1 = require("./load");
// We add this here, to avoid a cyclic depenency
cheerio_1.default.load = load_1.load;
var staticMethods = tslib_1.__importStar(require("./static"));
/**
* In order to promote consistency with the jQuery library, users are encouraged
* to instead use the static method of the same name.
*
* @deprecated
* @example
*
* ```js
* const $ = cheerio.load('<div><p></p></div>');
*
* $.contains($('div').get(0), $('p').get(0));
* //=> true
*
* $.contains($('p').get(0), $('div').get(0));
* //=> false
* ```
*
* @returns {boolean}
*/
exports.contains = staticMethods.contains;
/**
* In order to promote consistency with the jQuery library, users are encouraged
* to instead use the static method of the same name.
*
* @deprecated
* @example
*
* ```js
* const $ = cheerio.load('');
*
* $.merge([1, 2], [3, 4]);
* //=> [1, 2, 3, 4]
* ```
*/
exports.merge = staticMethods.merge;
/**
* In order to promote consistency with the jQuery library, users are encouraged
* to instead use the static method of the same name as it is defined on the
* "loaded" Cheerio factory function.
*
* @deprecated See {@link static/parseHTML}.
* @example
*
* ```js
* const $ = cheerio.load('');
* $.parseHTML('<b>markup</b>');
* ```
*/
exports.parseHTML = staticMethods.parseHTML;
/**
* Users seeking to access the top-level element of a parsed document should
* instead use the `root` static method of a "loaded" Cheerio function.
*
* @deprecated
* @example
*
* ```js
* const $ = cheerio.load('');
* $.root();
* ```
*/
exports.root = staticMethods.root;
/// <reference types="node" />
import { CheerioOptions } from './options';
import { CheerioAPI } from './cheerio';
import type { Node } from 'domhandler';
/**
* Create a querying function, bound to a document created from the provided
* markup. Note that similar to web browser contexts, this operation may
* introduce `<html>`, `<head>`, and `<body>` elements; set `isDocument` to
* `false` to switch to fragment mode and disable this.
*
* See the README section titled "Loading" for additional usage information.
*
* @param content - Markup to be loaded.
* @param options - Options for the created instance.
* @param isDocument - Allows parser to be switched to fragment mode.
* @returns The loaded document.
*/
export declare function load(content: string | Node | Node[] | Buffer, options?: CheerioOptions | null, isDocument?: boolean): CheerioAPI;
//# sourceMappingURL=load.d.ts.map
\ No newline at end of file
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,cAAc,EAGf,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,UAAU,EAAW,MAAM,WAAW,CAAC;AAEhD,OAAO,KAAK,EAAE,IAAI,EAAY,MAAM,YAAY,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,wBAAgB,IAAI,CAClB,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAAE,GAAG,MAAM,EACxC,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,EAC/B,UAAU,CAAC,EAAE,OAAO,GACnB,UAAU,CA8CZ"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.load = void 0;
var tslib_1 = require("tslib");
var options_1 = tslib_1.__importStar(require("./options"));
var staticMethods = tslib_1.__importStar(require("./static"));
var cheerio_1 = require("./cheerio");
var parse_1 = tslib_1.__importDefault(require("./parse"));
/**
* Create a querying function, bound to a document created from the provided
* markup. Note that similar to web browser contexts, this operation may
* introduce `<html>`, `<head>`, and `<body>` elements; set `isDocument` to
* `false` to switch to fragment mode and disable this.
*
* See the README section titled "Loading" for additional usage information.
*
* @param content - Markup to be loaded.
* @param options - Options for the created instance.
* @param isDocument - Allows parser to be switched to fragment mode.
* @returns The loaded document.
*/
function load(content, options, isDocument) {
if (content == null) {
throw new Error('cheerio.load() expects a string');
}
options = tslib_1.__assign(tslib_1.__assign({}, options_1.default), options_1.flatten(options));
if (typeof isDocument === 'undefined')
isDocument = true;
var root = parse_1.default(content, options, isDocument);
var initialize = /** @class */ (function (_super) {
tslib_1.__extends(initialize, _super);
function initialize(selector, context, r, opts) {
if (r === void 0) { r = root; }
var _this = this;
// @ts-expect-error Using `this` before calling the constructor.
if (!(_this instanceof initialize)) {
return new initialize(selector, context, r, opts);
}
_this = _super.call(this, selector, context, r, tslib_1.__assign(tslib_1.__assign({}, options), opts)) || this;
return _this;
}
// Mimic jQuery's prototype alias for plugin authors.
initialize.fn = initialize.prototype;
return initialize;
}(cheerio_1.Cheerio));
/*
* Keep a reference to the top-level scope so we can chain methods that implicitly
* resolve selectors; e.g. $("<span>").(".bar"), which otherwise loses ._root
*/
initialize.prototype._originalRoot = root;
// Add in the static methods
Object.assign(initialize, staticMethods, { load: load });
// Add in the root
initialize._root = root;
// Store options
initialize._options = options;
return initialize;
}
exports.load = load;
import type { DomHandlerOptions } from 'domhandler';
import type { ParserOptions } from 'htmlparser2';
/** Options accepted by htmlparser2, the default parser for XML. */
export interface HTMLParser2Options extends DomHandlerOptions, ParserOptions {
}
/** Options for parse5, the default parser for HTML. */
export interface Parse5Options {
/** Disable scripting in parse5, so noscript tags would be parsed. */
scriptingEnabled?: boolean;
/** Enable location support for parse5. */
sourceCodeLocationInfo?: boolean;
}
/** Internal options for Cheerio. */
export interface InternalOptions extends HTMLParser2Options, Parse5Options {
_useHtmlParser2?: boolean;
}
/**
* Options accepted by Cheerio. Please note that parser-specific options are
* *only recognized* if the relevant parser is used.
*/
export interface CheerioOptions extends HTMLParser2Options, Parse5Options {
/** Suggested way of configuring htmlparser2 when wanting to parse XML. */
xml?: HTMLParser2Options | boolean;
}
declare const defaultOpts: CheerioOptions;
/** Cheerio default options. */
export default defaultOpts;
export declare function flatten(options?: CheerioOptions | null): InternalOptions | undefined;
//# sourceMappingURL=options.d.ts.map
\ No newline at end of file
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,mEAAmE;AACnE,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB,EAAE,aAAa;CAAG;AAC/E,uDAAuD;AACvD,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,0CAA0C;IAC1C,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,oCAAoC;AACpC,MAAM,WAAW,eAAgB,SAAQ,kBAAkB,EAAE,aAAa;IACxE,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,kBAAkB,EAAE,aAAa;IACvE,0EAA0E;IAC1E,GAAG,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC;CACpC;AAED,QAAA,MAAM,WAAW,EAAE,cAGlB,CAAC;AAEF,+BAA+B;AAC/B,eAAe,WAAW,CAAC;AAO3B,wBAAgB,OAAO,CACrB,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,GAC9B,eAAe,GAAG,SAAS,CAM7B"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.flatten = void 0;
var tslib_1 = require("tslib");
var defaultOpts = {
xml: false,
decodeEntities: true,
};
/** Cheerio default options. */
exports.default = defaultOpts;
var xmlModeDefault = {
_useHtmlParser2: true,
xmlMode: true,
};
function flatten(options) {
return (options === null || options === void 0 ? void 0 : options.xml)
? typeof options.xml === 'boolean'
? xmlModeDefault
: tslib_1.__assign(tslib_1.__assign({}, xmlModeDefault), options.xml)
: options !== null && options !== void 0 ? options : undefined;
}
exports.flatten = flatten;
/// <reference types="node" />
import { Node, Document, NodeWithChildren } from 'domhandler';
import type { InternalOptions } from './options';
export default function parse(content: string | Document | Node | Node[] | Buffer, options: InternalOptions, isDocument: boolean): Document;
/**
* Update the dom structure, for one changed layer.
*
* @param newChilds - The new children.
* @param parent - The new parent.
* @returns The parent node.
*/
export declare function update(newChilds: Node[] | Node, parent: NodeWithChildren | null): Node | null;
//# sourceMappingURL=parse.d.ts.map
\ No newline at end of file
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":";AAGA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,gBAAgB,EAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAKjD,MAAM,CAAC,OAAO,UAAU,KAAK,CAC3B,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,GAAG,IAAI,EAAE,GAAG,MAAM,EACnD,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,OAAO,GAClB,QAAQ,CAyBV;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,SAAS,EAAE,IAAI,EAAE,GAAG,IAAI,EACxB,MAAM,EAAE,gBAAgB,GAAG,IAAI,GAC9B,IAAI,GAAG,IAAI,CA+Bb"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.update = void 0;
var htmlparser2_1 = require("htmlparser2");
var htmlparser2_2 = require("./parsers/htmlparser2");
var parse5_1 = require("./parsers/parse5");
var domhandler_1 = require("domhandler");
/*
* Parser
*/
function parse(content, options, isDocument) {
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(content)) {
content = content.toString();
}
if (typeof content === 'string') {
return options.xmlMode || options._useHtmlParser2
? htmlparser2_2.parse(content, options)
: parse5_1.parse(content, options, isDocument);
}
var doc = content;
if (!Array.isArray(doc) && domhandler_1.isDocument(doc)) {
// If `doc` is already a root, just return it
return doc;
}
// Add conent to new root element
var root = new domhandler_1.Document([]);
// Update the DOM using the root
update(doc, root);
return root;
}
exports.default = parse;
/**
* Update the dom structure, for one changed layer.
*
* @param newChilds - The new children.
* @param parent - The new parent.
* @returns The parent node.
*/
function update(newChilds, parent) {
// Normalize
var arr = Array.isArray(newChilds) ? newChilds : [newChilds];
// Update parent
if (parent) {
parent.children = arr;
}
else {
parent = null;
}
// Update neighbors
for (var i = 0; i < arr.length; i++) {
var node = arr[i];
// Cleanly remove existing nodes from their previous structures.
if (node.parent && node.parent.children !== arr) {
htmlparser2_1.DomUtils.removeElement(node);
}
if (parent) {
node.prev = arr[i - 1] || null;
node.next = arr[i + 1] || null;
}
else {
node.prev = node.next = null;
}
node.parent = parent;
}
return parent;
}
exports.update = update;
export { parseDocument as parse } from 'htmlparser2';
export { default as render } from 'dom-serializer';
//# sourceMappingURL=htmlparser2.d.ts.map
\ No newline at end of file
{"version":3,"file":"htmlparser2.d.ts","sourceRoot":"","sources":["../../src/parsers/htmlparser2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,gBAAgB,CAAC"}
\ No newline at end of file
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.render = exports.parse = void 0;
var htmlparser2_1 = require("htmlparser2");
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return htmlparser2_1.parseDocument; } });
var dom_serializer_1 = require("dom-serializer");
Object.defineProperty(exports, "render", { enumerable: true, get: function () { return __importDefault(dom_serializer_1).default; } });
import { Node, Document } from 'domhandler';
import type { InternalOptions } from '../options';
interface Parse5Options extends InternalOptions {
context?: Node;
}
export declare function parse(content: string, options: Parse5Options, isDocument?: boolean): Document;
export declare function render(dom: Node | ArrayLike<Node>): string;
export {};
//# sourceMappingURL=parse5.d.ts.map
\ No newline at end of file
{"version":3,"file":"parse5.d.ts","sourceRoot":"","sources":["../../src/parsers/parse5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAc,MAAM,YAAY,CAAC;AAGxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,UAAU,aAAc,SAAQ,eAAe;IAC7C,OAAO,CAAC,EAAE,IAAI,CAAC;CAChB;AAED,wBAAgB,KAAK,CACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,EACtB,UAAU,CAAC,EAAE,OAAO,GACnB,QAAQ,CAiBV;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,CAgB1D"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.render = exports.parse = void 0;
var tslib_1 = require("tslib");
var domhandler_1 = require("domhandler");
var parse5_1 = require("parse5");
var parse5_htmlparser2_tree_adapter_1 = tslib_1.__importDefault(require("parse5-htmlparser2-tree-adapter"));
function parse(content, options, isDocument) {
var opts = {
scriptingEnabled: typeof options.scriptingEnabled === 'boolean'
? options.scriptingEnabled
: true,
treeAdapter: parse5_htmlparser2_tree_adapter_1.default,
sourceCodeLocationInfo: options.sourceCodeLocationInfo,
};
var context = options.context;
// @ts-expect-error The tree adapter unfortunately doesn't return the exact types.
return isDocument
? parse5_1.parse(content, opts)
: // @ts-expect-error Same issue again.
parse5_1.parseFragment(context, content, opts);
}
exports.parse = parse;
function render(dom) {
var _a;
/*
* `dom-serializer` passes over the special "root" node and renders the
* node's children in its place. To mimic this behavior with `parse5`, an
* equivalent operation must be applied to the input array.
*/
var nodes = 'length' in dom ? dom : [dom];
for (var index = 0; index < nodes.length; index += 1) {
var node = nodes[index];
if (domhandler_1.isDocument(node)) {
(_a = Array.prototype.splice).call.apply(_a, tslib_1.__spreadArray([nodes, index, 1], node.children));
}
}
// @ts-expect-error Types don't align here either.
return parse5_1.serialize({ children: nodes }, { treeAdapter: parse5_htmlparser2_tree_adapter_1.default });
}
exports.render = render;
import type { Cheerio } from './cheerio';
import { Node, Document } from 'domhandler';
import { CheerioOptions } from './options';
/**
* Renders the document.
*
* @param options - Options for the renderer.
* @returns The rendered document.
*/
export declare function html(this: typeof Cheerio | void, options?: CheerioOptions): string;
/**
* Renders the document.
*
* @param dom - Element to render.
* @param options - Options for the renderer.
* @returns The rendered document.
*/
export declare function html(this: typeof Cheerio | void, dom?: string | ArrayLike<Node> | Node, options?: CheerioOptions): string;
/**
* Render the document as XML.
*
* @param dom - Element to render.
* @returns THe rendered document.
*/
export declare function xml(this: typeof Cheerio, dom?: string | ArrayLike<Node> | Node): string;
/**
* Render the document as text.
*
* @param elements - Elements to render.
* @returns The rendered document.
*/
export declare function text(this: typeof Cheerio | void, elements?: ArrayLike<Node>): string;
/**
* Parses a string into an array of DOM nodes. The `context` argument has no
* meaning for Cheerio, but it is maintained for API compatibility with jQuery.
*
* @param data - Markup that will be parsed.
* @param context - Will be ignored. If it is a boolean it will be used as the
* value of `keepScripts`.
* @param keepScripts - If false all scripts will be removed.
* @returns The parsed DOM.
* @alias Cheerio.parseHTML
* @see {@link https://api.jquery.com/jQuery.parseHTML/}
*/
export declare function parseHTML(this: typeof Cheerio, data: string, context?: unknown | boolean, keepScripts?: boolean): Node[];
export declare function parseHTML(this: typeof Cheerio, data?: '' | null): null;
/**
* Sometimes you need to work with the top-level root element. To query it, you
* can use `$.root()`.
*
* @example
*
* ```js
* $.root().append('<ul id="vegetables"></ul>').html();
* //=> <ul id="fruits">...</ul><ul id="vegetables"></ul>
* ```
*
* @returns Cheerio instance wrapping the root node.
* @alias Cheerio.root
*/
export declare function root(this: typeof Cheerio): Cheerio<Document>;
/**
* Checks to see if the `contained` DOM element is a descendant of the
* `container` DOM element.
*
* @param container - Potential parent node.
* @param contained - Potential child node.
* @returns Indicates if the nodes contain one another.
* @alias Cheerio.contains
* @see {@link https://api.jquery.com/jQuery.contains/}
*/
export declare function contains(container: Node, contained: Node): boolean;
interface WritableArrayLike<T> extends ArrayLike<T> {
length: number;
[n: number]: T;
}
/**
* $.merge().
*
* @param arr1 - First array.
* @param arr2 - Second array.
* @returns `arr1`, with elements of `arr2` inserted.
* @alias Cheerio.merge
* @see {@link https://api.jquery.com/jQuery.merge/}
*/
export declare function merge<T>(arr1: WritableArrayLike<T>, arr2: ArrayLike<T>): ArrayLike<T> | undefined;
export {};
//# sourceMappingURL=static.d.ts.map
\ No newline at end of file
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../src/static.ts"],"names":[],"mappings":"AAA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G;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,CAmBlE;AAED,UAAU,iBAAiB,CAAC,CAAC,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACrB,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC1B,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,GACjB,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAY1B"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.merge = exports.contains = exports.root = exports.parseHTML = exports.text = exports.xml = exports.html = void 0;
var tslib_1 = require("tslib");
var options_1 = tslib_1.__importStar(require("./options"));
var cheerio_select_1 = require("cheerio-select");
var htmlparser2_1 = require("htmlparser2");
var parse5_1 = require("./parsers/parse5");
var htmlparser2_2 = require("./parsers/htmlparser2");
/**
* Helper function to render a DOM.
*
* @param that - Cheerio instance to render.
* @param dom - The DOM to render. Defaults to `that`'s root.
* @param options - Options for rendering.
* @returns The rendered document.
*/
function render(that, dom, options) {
var _a, _b;
if (!dom) {
if ((_a = that === null || that === void 0 ? void 0 : that._root) === null || _a === void 0 ? void 0 : _a.children) {
dom = that._root.children;
}
else {
return '';
}
}
else if (typeof dom === 'string') {
dom = cheerio_select_1.select(dom, (_b = that === null || that === void 0 ? void 0 : that._root) !== null && _b !== void 0 ? _b : [], options);
}
return options.xmlMode || options._useHtmlParser2
? // FIXME: Pull in new version of dom-serializer to fix this.
htmlparser2_2.render(dom, options)
: parse5_1.render(dom);
}
/**
* Checks if a passed object is an options object.
*
* @param dom - Object to check if it is an options object.
* @returns Whether the object is an options object.
*/
function isOptions(dom) {
return (typeof dom === 'object' &&
dom != null &&
!('length' in dom) &&
!('type' in dom));
}
function html(dom, options) {
/*
* Be flexible about parameters, sometimes we call html(),
* with options as only parameter
* check dom argument for dom element specific properties
* assume there is no 'length' or 'type' properties in the options object
*/
if (!options && isOptions(dom)) {
options = dom;
dom = undefined;
}
/*
* Sometimes `$.html()` is used without preloading html,
* so fallback non-existing options to the default ones.
*/
options = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, options_1.default), (this ? this._options : {})), options_1.flatten(options !== null && options !== void 0 ? options : {}));
return render(this || undefined, dom, options);
}
exports.html = html;
/**
* Render the document as XML.
*
* @param dom - Element to render.
* @returns THe rendered document.
*/
function xml(dom) {
var options = tslib_1.__assign(tslib_1.__assign({}, this._options), { xmlMode: true });
return render(this, dom, options);
}
exports.xml = xml;
/**
* Render the document as text.
*
* @param elements - Elements to render.
* @returns The rendered document.
*/
function text(elements) {
var elems = elements ? elements : this ? this.root() : [];
var ret = '';
for (var i = 0; i < elems.length; i++) {
var elem = elems[i];
if (htmlparser2_1.DomUtils.isText(elem))
ret += elem.data;
else if (htmlparser2_1.DomUtils.hasChildren(elem) &&
elem.type !== htmlparser2_1.ElementType.Comment &&
elem.type !== htmlparser2_1.ElementType.Script &&
elem.type !== htmlparser2_1.ElementType.Style) {
ret += text(elem.children);
}
}
return ret;
}
exports.text = text;
function parseHTML(data, context, keepScripts) {
if (keepScripts === void 0) { keepScripts = typeof context === 'boolean' ? context : false; }
if (!data || typeof data !== 'string') {
return null;
}
if (typeof context === 'boolean') {
keepScripts = context;
}
var parsed = this.load(data, options_1.default, false);
if (!keepScripts) {
parsed('script').remove();
}
/*
* The `children` array is used by Cheerio internally to group elements that
* share the same parents. When nodes created through `parseHTML` are
* inserted into previously-existing DOM structures, they will be removed
* from the `children` array. The results of `parseHTML` should remain
* constant across these operations, so a shallow copy should be returned.
*/
return parsed.root()[0].children.slice();
}
exports.parseHTML = parseHTML;
/**
* Sometimes you need to work with the top-level root element. To query it, you
* can use `$.root()`.
*
* @example
*
* ```js
* $.root().append('<ul id="vegetables"></ul>').html();
* //=> <ul id="fruits">...</ul><ul id="vegetables"></ul>
* ```
*
* @returns Cheerio instance wrapping the root node.
* @alias Cheerio.root
*/
function root() {
var fn = this;
return fn(this._root);
}
exports.root = root;
/**
* Checks to see if the `contained` DOM element is a descendant of the
* `container` DOM element.
*
* @param container - Potential parent node.
* @param contained - Potential child node.
* @returns Indicates if the nodes contain one another.
* @alias Cheerio.contains
* @see {@link https://api.jquery.com/jQuery.contains/}
*/
function contains(container, contained) {
// According to the jQuery API, an element does not "contain" itself
if (contained === container) {
return false;
}
/*
* Step up the descendants, stopping when the root element is reached
* (signaled by `.parent` returning a reference to the same object)
*/
var next = contained;
while (next && next !== next.parent) {
next = next.parent;
if (next === container) {
return true;
}
}
return false;
}
exports.contains = contains;
/**
* $.merge().
*
* @param arr1 - First array.
* @param arr2 - Second array.
* @returns `arr1`, with elements of `arr2` inserted.
* @alias Cheerio.merge
* @see {@link https://api.jquery.com/jQuery.merge/}
*/
function merge(arr1, arr2) {
if (!isArrayLike(arr1) || !isArrayLike(arr2)) {
return;
}
var newLength = arr1.length;
var len = +arr2.length;
for (var i = 0; i < len; i++) {
arr1[newLength++] = arr2[i];
}
arr1.length = newLength;
return arr1;
}
exports.merge = merge;
/**
* @param item - Item to check.
* @returns Indicates if the item is array-like.
*/
function isArrayLike(item) {
if (Array.isArray(item)) {
return true;
}
if (typeof item !== 'object' ||
!Object.prototype.hasOwnProperty.call(item, 'length') ||
typeof item.length !== 'number' ||
item.length < 0) {
return false;
}
for (var i = 0; i < item.length; i++) {
if (!(i in item)) {
return false;
}
}
return true;
}
declare type LowercaseLetters = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
declare type AlphaNumeric = LowercaseLetters | Uppercase<LowercaseLetters> | `${number}`;
declare type SelectorSpecial = '.' | '#' | ':' | '|' | '>' | '+' | '~' | '[';
/**
* Type for identifying selectors. Allows us to "upgrade" queries using
* selectors to return `Element`s.
*/
export declare type SelectorType = `${SelectorSpecial}${AlphaNumeric}${string}` | `${AlphaNumeric}${string}`;
import type { Cheerio } from './cheerio';
import type { Node, Element } from 'domhandler';
/** Elements that can be passed to manipulation methods. */
export declare type BasicAcceptedElems<T extends Node> = Cheerio<T> | T[] | T | string;
/** Elements that can be passed to manipulation methods, including functions. */
export declare type AcceptedElems<T extends Node> = BasicAcceptedElems<T> | ((this: T, i: number, el: T) => BasicAcceptedElems<T>);
/** Function signature, for traversal methods. */
export declare type FilterFunction<T> = (this: T, i: number, el: T) => boolean;
/** Supported filter types, for traversal methods. */
export declare type AcceptedFilters = string | FilterFunction<Element> | Node | Cheerio<Node>;
export {};
//# sourceMappingURL=types.d.ts.map
\ No newline at end of file
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,aAAK,gBAAgB,GACjB,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,CAAC;AAER,aAAK,YAAY,GACb,gBAAgB,GAChB,SAAS,CAAC,gBAAgB,CAAC,GAC3B,GAAG,MAAM,EAAE,CAAC;AAEhB,aAAK,eAAe,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACrE;;;GAGG;AACH,oBAAY,YAAY,GACpB,GAAG,eAAe,GAAG,YAAY,GAAG,MAAM,EAAE,GAC5C,GAAG,YAAY,GAAG,MAAM,EAAE,CAAC;AAE/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEhD,2DAA2D;AAC3D,oBAAY,kBAAkB,CAAC,CAAC,SAAS,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC;AAC/E,gFAAgF;AAChF,oBAAY,aAAa,CAAC,CAAC,SAAS,IAAI,IACpC,kBAAkB,CAAC,CAAC,CAAC,GACrB,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3D,iDAAiD;AACjD,oBAAY,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,OAAO,CAAC;AACvE,qDAAqD;AACrD,oBAAY,eAAe,GACvB,MAAM,GACN,cAAc,CAAC,OAAO,CAAC,GACvB,IAAI,GACJ,OAAO,CAAC,IAAI,CAAC,CAAC"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
import { DomUtils } from 'htmlparser2';
import { Node } from 'domhandler';
import type { Cheerio } from './cheerio';
/**
* Check if the DOM element is a tag.
*
* `isTag(type)` includes `<script>` and `<style>` tags.
*
* @private
* @category Utils
* @param type - DOM node to check.
* @returns Whether the node is a tag.
*/
export declare const isTag: typeof DomUtils.isTag;
/**
* Checks if an object is a Cheerio instance.
*
* @category Utils
* @param maybeCheerio - The object to check.
* @returns Whether the object is a Cheerio instance.
*/
export declare function isCheerio<T>(maybeCheerio: any): maybeCheerio is Cheerio<T>;
/**
* Convert a string to camel case notation.
*
* @private
* @category Utils
* @param str - String to be converted.
* @returns String in camel case notation.
*/
export declare function camelCase(str: string): string;
/**
* Convert a string from camel case to "CSS case", where word boundaries are
* described by hyphens ("-") and all characters are lower-case.
*
* @private
* @category Utils
* @param str - String to be converted.
* @returns String in "CSS case".
*/
export declare function cssCase(str: string): string;
/**
* Iterate over each DOM element without creating intermediary Cheerio instances.
*
* This is indented for use internally to avoid otherwise unnecessary memory
* pressure introduced by _make.
*
* @category Utils
* @param array - Array to iterate over.
* @param fn - Function to call.
* @returns The original instance.
*/
export declare function domEach<T extends Node, Arr extends ArrayLike<T> = Cheerio<T>>(array: Arr, fn: (index: number, elem: T) => void | false): Arr;
/**
* Create a deep copy of the given DOM structure. Sets the parents of the copies
* of the passed nodes to `null`.
*
* @private
* @category Utils
* @param dom - The htmlparser2-compliant DOM structure.
* @returns - The cloned DOM.
*/
export declare function cloneDom<T extends Node>(dom: T | T[]): T[];
/**
* Check if string is HTML.
*
* @private
* @category Utils
* @param str - String to check.
* @returns Indicates if `str` is HTML.
*/
export declare function isHtml(str: string): boolean;
//# sourceMappingURL=utils.d.ts.map
\ No newline at end of file
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,IAAI,EAAuB,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAQ,KAAK,uBAAa,CAAC;AAElC;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,GAAG,YAAY,IAAI,OAAO,CAAC,CAAC,CAAC,CAE1E;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,IAAI,EAAE,GAAG,SAAS,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAC3E,KAAK,EAAE,GAAG,EACV,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,GAC3C,GAAG,CAIL;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAa1D;AAUD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAG3C"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isHtml = exports.cloneDom = exports.domEach = exports.cssCase = exports.camelCase = exports.isCheerio = exports.isTag = void 0;
var htmlparser2_1 = require("htmlparser2");
var domhandler_1 = require("domhandler");
/**
* Check if the DOM element is a tag.
*
* `isTag(type)` includes `<script>` and `<style>` tags.
*
* @private
* @category Utils
* @param type - DOM node to check.
* @returns Whether the node is a tag.
*/
exports.isTag = htmlparser2_1.DomUtils.isTag;
/**
* Checks if an object is a Cheerio instance.
*
* @category Utils
* @param maybeCheerio - The object to check.
* @returns Whether the object is a Cheerio instance.
*/
function isCheerio(maybeCheerio) {
return maybeCheerio.cheerio != null;
}
exports.isCheerio = isCheerio;
/**
* Convert a string to camel case notation.
*
* @private
* @category Utils
* @param str - String to be converted.
* @returns String in camel case notation.
*/
function camelCase(str) {
return str.replace(/[_.-](\w|$)/g, function (_, x) { return x.toUpperCase(); });
}
exports.camelCase = camelCase;
/**
* Convert a string from camel case to "CSS case", where word boundaries are
* described by hyphens ("-") and all characters are lower-case.
*
* @private
* @category Utils
* @param str - String to be converted.
* @returns String in "CSS case".
*/
function cssCase(str) {
return str.replace(/[A-Z]/g, '-$&').toLowerCase();
}
exports.cssCase = cssCase;
/**
* Iterate over each DOM element without creating intermediary Cheerio instances.
*
* This is indented for use internally to avoid otherwise unnecessary memory
* pressure introduced by _make.
*
* @category Utils
* @param array - Array to iterate over.
* @param fn - Function to call.
* @returns The original instance.
*/
function domEach(array, fn) {
var len = array.length;
for (var i = 0; i < len && fn(i, array[i]) !== false; i++)
;
return array;
}
exports.domEach = domEach;
/**
* Create a deep copy of the given DOM structure. Sets the parents of the copies
* of the passed nodes to `null`.
*
* @private
* @category Utils
* @param dom - The htmlparser2-compliant DOM structure.
* @returns - The cloned DOM.
*/
function cloneDom(dom) {
var clone = 'length' in dom
? Array.prototype.map.call(dom, function (el) { return domhandler_1.cloneNode(el, true); })
: [domhandler_1.cloneNode(dom, true)];
// Add a root node around the cloned nodes
var root = new domhandler_1.Document(clone);
clone.forEach(function (node) {
node.parent = root;
});
return clone;
}
exports.cloneDom = cloneDom;
/**
* A simple way to check for HTML strings. Tests for a `<` within a string,
* immediate followed by a letter and eventually followed by a `>`.
*
* @private
*/
var quickExpr = /<[a-zA-Z][^]*>/;
/**
* Check if string is HTML.
*
* @private
* @category Utils
* @param str - String to check.
* @returns Indicates if `str` is HTML.
*/
function isHtml(str) {
// Run the regex
return quickExpr.test(str);
}
exports.isHtml = isHtml;
{
"name": "cheerio",
"version": "1.0.0-rc.9",
"description": "Tiny, fast, and elegant implementation of core jQuery designed specifically for the server",
"author": "Matt Mueller <mattmuelle@gmail.com> (mat.io)",
"funding": "https://github.com/cheeriojs/cheerio?sponsor=1",
"license": "MIT",
"keywords": [
"htmlparser",
"jquery",
"selector",
"scraper",
"parser",
"html"
],
"repository": {
"type": "git",
"url": "git://github.com/cheeriojs/cheerio.git"
},
"bugs": {
"url": "https://github.com/cheeriojs/cheerio/issues"
},
"homepage": "https://cheerio.js.org/",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib"
],
"engines": {
"node": ">= 6"
},
"dependencies": {
"cheerio-select": "^1.4.0",
"dom-serializer": "^1.3.1",
"domhandler": "^4.2.0",
"htmlparser2": "^6.1.0",
"parse5": "^6.0.1",
"parse5-htmlparser2-tree-adapter": "^6.0.1",
"tslib": "^2.2.0"
},
"devDependencies": {
"@octokit/graphql": "^4.6.1",
"@types/benchmark": "^2.1.0",
"@types/jest": "^26.0.23",
"@types/jsdom": "^16.2.10",
"@types/node": "^15.0.2",
"@types/node-fetch": "^2.5.10",
"@types/parse5": "^6.0.0",
"@types/parse5-htmlparser2-tree-adapter": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^4.22.1",
"@typescript-eslint/parser": "^4.22.1",
"benchmark": "^2.1.4",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-jsdoc": "^33.1.0",
"eslint-plugin-node": "^11.1.0",
"husky": "^4.3.8",
"jest": "^26.6.3",
"jquery": "^3.6.0",
"jsdom": "^16.5.3",
"lint-staged": "^10.5.4",
"node-fetch": "^2.6.1",
"prettier": "^2.2.1",
"prettier-plugin-jsdoc": "0.3.22",
"ts-jest": "^26.5.6",
"ts-node": "^9.1.1",
"typedoc": "^0.20.36",
"typescript": "^4.2.4"
},
"scripts": {
"test": "npm run lint && npm run test:jest",
"test:jest": "jest",
"test:jest:cov": "npm run test:jest -- --coverage",
"lint": "npm run lint:es && npm run lint:prettier",
"lint:es": "eslint --ignore-path .gitignore .",
"lint:prettier": "npm run format:prettier:raw -- --check",
"format": "npm run format:es && npm run format:prettier",
"format:es": "npm run lint:es -- --fix",
"format:prettier": "npm run format:prettier:raw -- --write",
"format:prettier:raw": "prettier \"**/*.{js,ts,md,json,yml}\" --ignore-path .gitignore",
"build:docs": "typedoc --hideGenerator src/index.ts",
"benchmark": "ts-node benchmark/benchmark.ts --regex \"^(?!.*highmem)\"",
"update-sponsors": "ts-node scripts/fetch-sponsors.ts",
"bench": "npm run benchmark",
"pre-commit": "lint-staged",
"build": "tsc",
"prepublishOnly": "npm run build"
},
"prettier": {
"singleQuote": true,
"tabWidth": 2,
"tsdoc": true
},
"lint-staged": {
"*.js": [
"prettier --write",
"npm run test:lint -- --fix"
],
"*.{json,md,ts,yml}": [
"prettier --write"
]
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testPathIgnorePatterns": [
"/__fixtures__/"
]
}
}
Copyright © Jorge Bucaran <<https://jorgebucaran.com>>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Colorette
> Easily set the color and style of text in the terminal.
- No wonky prototype method-chain API.
- Automatic color support detection.
- Up to [2x faster](#benchmarks) than alternatives.
- [`NO_COLOR`](https://no-color.org) friendly. 👌
Here's the first example to get you started.
```js
import { blue, bold, underline } from "colorette"
console.log(
blue("I'm blue"),
bold(blue("da ba dee")),
underline(bold(blue("da ba daa")))
)
```
Here's an example using [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals).
```js
console.log(`
There's a ${underline(blue("house"))},
With a ${bold(blue("window"))},
And a ${blue("corvette")}
And everything is blue
`)
```
Of course, you can nest styles without breaking existing color sequences.
```js
console.log(bold(`I'm ${blue(`da ba ${underline("dee")} da ba`)} daa`))
```
Feeling adventurous? Try the [pipeline operator](https://github.com/tc39/proposal-pipeline-operator).
```js
console.log("Da ba dee da ba daa" |> blue |> bold)
```
## Installation
```console
npm install colorette
```
## API
### `<style>(string)`
```js
import { blue } from "colorette"
blue("I'm blue") //=> \x1b[34mI'm blue\x1b[39m
```
See [supported styles]().
### `options.enabled`
Colorette automatically detects if your terminal can display color, but you can toggle color as needed.
```js
import { options } from "colorette"
options.enabled = false
```
You can also force the use of color globally by setting `FORCE_COLOR=` or `NO_COLOR=` from the CLI.
```console
$ FORCE_COLOR= node example.js >log
$ NO_COLOR= node example.js
```
## Supported styles
| Colors | Background Colors | Bright Colors | Bright Background Colors | Modifiers |
| ------- | ----------------- | ------------- | ------------------------ | ----------------- |
| black | bgBlack | blackBright | bgBlackBright | dim |
| red | bgRed | redBright | bgRedBright | **bold** |
| green | bgGreen | greenBright | bgGreenBright | hidden |
| yellow | bgYellow | yellowBright | bgYellowBright | _italic_ |
| blue | bgBlue | blueBright | bgBlueBright | <u>underline</u> |
| magenta | bgMagenta | magentaBright | bgMagentaBright | ~~strikethrough~~ |
| cyan | bgCyan | cyanBright | bgCyanBright | reset |
| white | bgWhite | whiteBright | bgWhiteBright | |
| gray | | | | |
## Benchmarks
```console
npm --prefix bench start
```
## License
[MIT](LICENSE.md)
let enabled =
!("NO_COLOR" in process.env) &&
("FORCE_COLOR" in process.env ||
process.platform === "win32" ||
(process.stdout != null &&
process.stdout.isTTY &&
process.env.TERM &&
process.env.TERM !== "dumb"))
const raw = (open, close, searchRegex, replaceValue) => (s) =>
enabled
? open +
(~(s += "").indexOf(close, 4) // skip opening \x1b[
? s.replace(searchRegex, replaceValue)
: s) +
close
: s
const init = (open, close) => {
return raw(
`\x1b[${open}m`,
`\x1b[${close}m`,
new RegExp(`\\x1b\\[${close}m`, "g"),
`\x1b[${open}m`
)
}
exports.options = Object.defineProperty({}, "enabled", {
get: () => enabled,
set: (value) => (enabled = value),
})
exports.reset = init(0, 0)
exports.bold = raw("\x1b[1m", "\x1b[22m", /\x1b\[22m/g, "\x1b[22m\x1b[1m")
exports.dim = raw("\x1b[2m", "\x1b[22m", /\x1b\[22m/g, "\x1b[22m\x1b[2m")
exports.italic = init(3, 23)
exports.underline = init(4, 24)
exports.inverse = init(7, 27)
exports.hidden = init(8, 28)
exports.strikethrough = init(9, 29)
exports.black = init(30, 39)
exports.red = init(31, 39)
exports.green = init(32, 39)
exports.yellow = init(33, 39)
exports.blue = init(34, 39)
exports.magenta = init(35, 39)
exports.cyan = init(36, 39)
exports.white = init(37, 39)
exports.gray = init(90, 39)
exports.bgBlack = init(40, 49)
exports.bgRed = init(41, 49)
exports.bgGreen = init(42, 49)
exports.bgYellow = init(43, 49)
exports.bgBlue = init(44, 49)
exports.bgMagenta = init(45, 49)
exports.bgCyan = init(46, 49)
exports.bgWhite = init(47, 49)
exports.blackBright = init(90, 39)
exports.redBright = init(91, 39)
exports.greenBright = init(92, 39)
exports.yellowBright = init(93, 39)
exports.blueBright = init(94, 39)
exports.magentaBright = init(95, 39)
exports.cyanBright = init(96, 39)
exports.whiteBright = init(97, 39)
exports.bgBlackBright = init(100, 49)
exports.bgRedBright = init(101, 49)
exports.bgGreenBright = init(102, 49)
exports.bgYellowBright = init(103, 49)
exports.bgBlueBright = init(104, 49)
exports.bgMagentaBright = init(105, 49)
exports.bgCyanBright = init(106, 49)
exports.bgWhiteBright = init(107, 49)
interface Style {
(string: string): string
}
export const options: {
enabled: boolean
}
export const reset: Style
export const bold: Style
export const dim: Style
export const italic: Style
export const underline: Style
export const inverse: Style
export const hidden: Style
export const strikethrough: Style
export const black: Style
export const red: Style
export const green: Style
export const yellow: Style
export const blue: Style
export const magenta: Style
export const cyan: Style
export const white: Style
export const gray: Style
export const bgBlack: Style
export const bgRed: Style
export const bgGreen: Style
export const bgYellow: Style
export const bgBlue: Style
export const bgMagenta: Style
export const bgCyan: Style
export const bgWhite: Style
export const blackBright: Style
export const redBright: Style
export const greenBright: Style
export const yellowBright: Style
export const blueBright: Style
export const magentaBright: Style
export const cyanBright: Style
export const whiteBright: Style
export const bgBlackBright: Style
export const bgRedBright: Style
export const bgGreenBright: Style
export const bgYellowBright: Style
export const bgBlueBright: Style
export const bgMagentaBright: Style
export const bgCyanBright: Style
export const bgWhiteBright: Style
let enabled =
!("NO_COLOR" in process.env) &&
("FORCE_COLOR" in process.env ||
process.platform === "win32" ||
(process.stdout != null &&
process.stdout.isTTY &&
process.env.TERM &&
process.env.TERM !== "dumb"))
const raw = (open, close, searchRegex, replaceValue) => (s) =>
enabled
? open +
(~(s += "").indexOf(close, 4) // skip opening \x1b[
? s.replace(searchRegex, replaceValue)
: s) +
close
: s
const init = (open, close) => {
return raw(
`\x1b[${open}m`,
`\x1b[${close}m`,
new RegExp(`\\x1b\\[${close}m`, "g"),
`\x1b[${open}m`
)
}
export const options = Object.defineProperty({}, "enabled", {
get: () => enabled,
set: (value) => (enabled = value),
})
export const reset = init(0, 0)
export const bold = raw("\x1b[1m", "\x1b[22m", /\x1b\[22m/g, "\x1b[22m\x1b[1m")
export const dim = raw("\x1b[2m", "\x1b[22m", /\x1b\[22m/g, "\x1b[22m\x1b[2m")
export const italic = init(3, 23)
export const underline = init(4, 24)
export const inverse = init(7, 27)
export const hidden = init(8, 28)
export const strikethrough = init(9, 29)
export const black = init(30, 39)
export const red = init(31, 39)
export const green = init(32, 39)
export const yellow = init(33, 39)
export const blue = init(34, 39)
export const magenta = init(35, 39)
export const cyan = init(36, 39)
export const white = init(37, 39)
export const gray = init(90, 39)
export const bgBlack = init(40, 49)
export const bgRed = init(41, 49)
export const bgGreen = init(42, 49)
export const bgYellow = init(43, 49)
export const bgBlue = init(44, 49)
export const bgMagenta = init(45, 49)
export const bgCyan = init(46, 49)
export const bgWhite = init(47, 49)
export const blackBright = init(90, 39)
export const redBright = init(91, 39)
export const greenBright = init(92, 39)
export const yellowBright = init(93, 39)
export const blueBright = init(94, 39)
export const magentaBright = init(95, 39)
export const cyanBright = init(96, 39)
export const whiteBright = init(97, 39)
export const bgBlackBright = init(100, 49)
export const bgRedBright = init(101, 49)
export const bgGreenBright = init(102, 49)
export const bgYellowBright = init(103, 49)
export const bgBlueBright = init(104, 49)
export const bgMagentaBright = init(105, 49)
export const bgCyanBright = init(106, 49)
export const bgWhiteBright = init(107, 49)
{
"name": "colorette",
"version": "1.2.2",
"type": "module",
"main": "index.cjs",
"module": "index.js",
"types": "index.d.ts",
"description": "Easily set the color and style of text in the terminal.",
"repository": "jorgebucaran/colorette",
"license": "MIT",
"exports": {
"./package.json": "./package.json",
".": {
"require": "./index.cjs",
"import": "./index.js"
}
},
"files": [
"*.*(c)[tj]s*"
],
"author": "Jorge Bucaran",
"keywords": [
"terminal",
"styles",
"color",
"ansi"
],
"scripts": {
"test": "c8 twist tests/*.js",
"build": "node -e \"fs.writeFileSync('index.cjs',fs.readFileSync('index.js','utf8').replace(/export const /g,'exports.'),'utf8')\"",
"deploy": "npm test && git commit --all --message $tag && git tag --sign $tag --message $tag && git push && git push --tags",
"release": "tag=$npm_package_version npm run deploy && npm publish --access public",
"prepare": "npm run build"
},
"devDependencies": {
"c8": "*",
"twist": "*"
}
}
Copyright (c) Felix Böhm
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This diff is collapsed. Click to expand it.
import { CompiledQuery, InternalOptions } from "./types";
import type { AttributeSelector, AttributeAction } from "css-what";
/**
* Attribute selectors
*/
export declare const attributeRules: Record<AttributeAction, <Node, ElementNode extends Node>(next: CompiledQuery<ElementNode>, data: AttributeSelector, options: InternalOptions<Node, ElementNode>) => CompiledQuery<ElementNode>>;
//# sourceMappingURL=attributes.d.ts.map
\ No newline at end of file
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAanE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAC/B,eAAe,EACf,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAC3B,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAChC,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,KAC1C,aAAa,CAAC,WAAW,CAAC,CA8KlC,CAAC"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.attributeRules = void 0;
var boolbase_1 = require("boolbase");
/**
* All reserved characters in a regex, used for escaping.
*
* Taken from XRegExp, (c) 2007-2020 Steven Levithan under the MIT license
* https://github.com/slevithan/xregexp/blob/95eeebeb8fac8754d54eafe2b4743661ac1cf028/src/xregexp.js#L794
*/
var reChars = /[-[\]{}()*+?.,\\^$|#\s]/g;
function escapeRegex(value) {
return value.replace(reChars, "\\$&");
}
/**
* Attribute selectors
*/
exports.attributeRules = {
equals: function (next, data, _a) {
var adapter = _a.adapter;
var name = data.name;
var value = data.value;
if (data.ignoreCase) {
value = value.toLowerCase();
return function (elem) {
var attr = adapter.getAttributeValue(elem, name);
return (attr != null &&
attr.length === value.length &&
attr.toLowerCase() === value &&
next(elem));
};
}
return function (elem) {
return adapter.getAttributeValue(elem, name) === value && next(elem);
};
},
hyphen: function (next, data, _a) {
var adapter = _a.adapter;
var name = data.name;
var value = data.value;
var len = value.length;
if (data.ignoreCase) {
value = value.toLowerCase();
return function hyphenIC(elem) {
var attr = adapter.getAttributeValue(elem, name);
return (attr != null &&
(attr.length === len || attr.charAt(len) === "-") &&
attr.substr(0, len).toLowerCase() === value &&
next(elem));
};
}
return function hyphen(elem) {
var attr = adapter.getAttributeValue(elem, name);
return (attr != null &&
(attr.length === len || attr.charAt(len) === "-") &&
attr.substr(0, len) === value &&
next(elem));
};
},
element: function (next, _a, _b) {
var name = _a.name, value = _a.value, ignoreCase = _a.ignoreCase;
var adapter = _b.adapter;
if (/\s/.test(value)) {
return boolbase_1.falseFunc;
}
var regex = new RegExp("(?:^|\\s)" + escapeRegex(value) + "(?:$|\\s)", ignoreCase ? "i" : "");
return function element(elem) {
var attr = adapter.getAttributeValue(elem, name);
return (attr != null &&
attr.length >= value.length &&
regex.test(attr) &&
next(elem));
};
},
exists: function (next, _a, _b) {
var name = _a.name;
var adapter = _b.adapter;
return function (elem) { return adapter.hasAttrib(elem, name) && next(elem); };
},
start: function (next, data, _a) {
var adapter = _a.adapter;
var name = data.name;
var value = data.value;
var len = value.length;
if (len === 0) {
return boolbase_1.falseFunc;
}
if (data.ignoreCase) {
value = value.toLowerCase();
return function (elem) {
var attr = adapter.getAttributeValue(elem, name);
return (attr != null &&
attr.length >= len &&
attr.substr(0, len).toLowerCase() === value &&
next(elem));
};
}
return function (elem) {
var _a;
return !!((_a = adapter.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.startsWith(value)) &&
next(elem);
};
},
end: function (next, data, _a) {
var adapter = _a.adapter;
var name = data.name;
var value = data.value;
var len = -value.length;
if (len === 0) {
return boolbase_1.falseFunc;
}
if (data.ignoreCase) {
value = value.toLowerCase();
return function (elem) {
var _a;
return ((_a = adapter
.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.substr(len).toLowerCase()) === value && next(elem);
};
}
return function (elem) {
var _a;
return !!((_a = adapter.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.endsWith(value)) &&
next(elem);
};
},
any: function (next, data, _a) {
var adapter = _a.adapter;
var name = data.name, value = data.value;
if (value === "") {
return boolbase_1.falseFunc;
}
if (data.ignoreCase) {
var regex_1 = new RegExp(escapeRegex(value), "i");
return function anyIC(elem) {
var attr = adapter.getAttributeValue(elem, name);
return (attr != null &&
attr.length >= value.length &&
regex_1.test(attr) &&
next(elem));
};
}
return function (elem) {
var _a;
return !!((_a = adapter.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.includes(value)) &&
next(elem);
};
},
not: function (next, data, _a) {
var adapter = _a.adapter;
var name = data.name;
var value = data.value;
if (value === "") {
return function (elem) {
return !!adapter.getAttributeValue(elem, name) && next(elem);
};
}
else if (data.ignoreCase) {
value = value.toLowerCase();
return function (elem) {
var attr = adapter.getAttributeValue(elem, name);
return ((attr == null ||
attr.length !== value.length ||
attr.toLowerCase() !== value) &&
next(elem));
};
}
return function (elem) {
return adapter.getAttributeValue(elem, name) !== value && next(elem);
};
},
};
import { InternalSelector } from "./types";
import { Selector } from "css-what";
import type { CompiledQuery, InternalOptions } from "./types";
/**
* Compiles a selector to an executable function.
*
* @param selector Selector to compile.
* @param options Compilation options.
* @param context Optional context for the selector.
*/
export declare function compile<Node, ElementNode extends Node>(selector: string | Selector[][], options: InternalOptions<Node, ElementNode>, context?: Node[] | Node): CompiledQuery<ElementNode>;
export declare function compileUnsafe<Node, ElementNode extends Node>(selector: string | Selector[][], options: InternalOptions<Node, ElementNode>, context?: Node[] | Node): CompiledQuery<ElementNode>;
export declare function compileToken<Node, ElementNode extends Node>(token: InternalSelector[][], options: InternalOptions<Node, ElementNode>, context?: Node[] | Node): CompiledQuery<ElementNode>;
//# sourceMappingURL=compile.d.ts.map
\ No newline at end of file
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAS,QAAQ,EAAE,MAAM,UAAU,CAAC;AAS3C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAClD,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,EAAE,EAC/B,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,GACxB,aAAa,CAAC,WAAW,CAAC,CAG5B;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EACxD,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,EAAE,EAC/B,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,GACxB,aAAa,CAAC,WAAW,CAAC,CAI5B;AA6CD,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EACvD,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAC3B,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,GACxB,aAAa,CAAC,WAAW,CAAC,CA2C5B"}
\ No newline at end of file
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.compileToken = exports.compileUnsafe = exports.compile = void 0;
var css_what_1 = require("css-what");
var boolbase_1 = require("boolbase");
var sort_1 = __importDefault(require("./sort"));
var procedure_1 = require("./procedure");
var general_1 = require("./general");
var subselects_1 = require("./pseudo-selectors/subselects");
/**
* Compiles a selector to an executable function.
*
* @param selector Selector to compile.
* @param options Compilation options.
* @param context Optional context for the selector.
*/
function compile(selector, options, context) {
var next = compileUnsafe(selector, options, context);
return subselects_1.ensureIsTag(next, options.adapter);
}
exports.compile = compile;
function compileUnsafe(selector, options, context) {
var token = typeof selector === "string" ? css_what_1.parse(selector, options) : selector;
return compileToken(token, options, context);
}
exports.compileUnsafe = compileUnsafe;
function includesScopePseudo(t) {
return (t.type === "pseudo" &&
(t.name === "scope" ||
(Array.isArray(t.data) &&
t.data.some(function (data) { return data.some(includesScopePseudo); }))));
}
var DESCENDANT_TOKEN = { type: "descendant" };
var FLEXIBLE_DESCENDANT_TOKEN = {
type: "_flexibleDescendant",
};
var SCOPE_TOKEN = { type: "pseudo", name: "scope", data: null };
/*
* CSS 4 Spec (Draft): 3.3.1. Absolutizing a Scope-relative Selector
* http://www.w3.org/TR/selectors4/#absolutizing
*/
function absolutize(token, _a, context) {
var adapter = _a.adapter;
// TODO Use better check if the context is a document
var hasContext = !!(context === null || context === void 0 ? void 0 : context.every(function (e) {
var parent = adapter.isTag(e) && adapter.getParent(e);
return e === subselects_1.PLACEHOLDER_ELEMENT || (parent && adapter.isTag(parent));
}));
for (var _i = 0, token_1 = token; _i < token_1.length; _i++) {
var t = token_1[_i];
if (t.length > 0 && procedure_1.isTraversal(t[0]) && t[0].type !== "descendant") {
// Don't continue in else branch
}
else if (hasContext && !t.some(includesScopePseudo)) {
t.unshift(DESCENDANT_TOKEN);
}
else {
continue;
}
t.unshift(SCOPE_TOKEN);
}
}
function compileToken(token, options, context) {
var _a;
token = token.filter(function (t) { return t.length > 0; });
token.forEach(sort_1.default);
context = (_a = options.context) !== null && _a !== void 0 ? _a : context;
var isArrayContext = Array.isArray(context);
var finalContext = context && (Array.isArray(context) ? context : [context]);
absolutize(token, options, finalContext);
var shouldTestNextSiblings = false;
var query = token
.map(function (rules) {
if (rules.length >= 2) {
var first = rules[0], second = rules[1];
if (first.type !== "pseudo" || first.name !== "scope") {
// Ignore
}
else if (isArrayContext && second.type === "descendant") {
rules[1] = FLEXIBLE_DESCENDANT_TOKEN;
}
else if (second.type === "adjacent" ||
second.type === "sibling") {
shouldTestNextSiblings = true;
}
}
return compileRules(rules, options, finalContext);
})
.reduce(reduceRules, boolbase_1.falseFunc);
query.shouldTestNextSiblings = shouldTestNextSiblings;
return query;
}
exports.compileToken = compileToken;
function compileRules(rules, options, context) {
var _a;
return rules.reduce(function (previous, rule) {
return previous === boolbase_1.falseFunc
? boolbase_1.falseFunc
: general_1.compileGeneralSelector(previous, rule, options, context, compileToken);
}, (_a = options.rootFunc) !== null && _a !== void 0 ? _a : boolbase_1.trueFunc);
}
function reduceRules(a, b) {
if (b === boolbase_1.falseFunc || a === boolbase_1.trueFunc) {
return a;
}
if (a === boolbase_1.falseFunc || b === boolbase_1.trueFunc) {
return b;
}
return function combine(elem) {
return a(elem) || b(elem);
};
}
import type { CompiledQuery, InternalOptions, InternalSelector, CompileToken } from "./types";
export declare function compileGeneralSelector<Node, ElementNode extends Node>(next: CompiledQuery<ElementNode>, selector: InternalSelector, options: InternalOptions<Node, ElementNode>, context: Node[] | undefined, compileToken: CompileToken<Node, ElementNode>): CompiledQuery<ElementNode>;
//# sourceMappingURL=general.d.ts.map
\ No newline at end of file
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../src/general.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,YAAY,EACf,MAAM,SAAS,CAAC;AAMjB,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EACjE,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAChC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,EAAE,IAAI,EAAE,GAAG,SAAS,EAC3B,YAAY,EAAE,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,GAC9C,aAAa,CAAC,WAAW,CAAC,CAwH5B"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compileGeneralSelector = void 0;
var attributes_1 = require("./attributes");
var pseudo_selectors_1 = require("./pseudo-selectors");
/*
* All available rules
*/
function compileGeneralSelector(next, selector, options, context, compileToken) {
var adapter = options.adapter, equals = options.equals;
switch (selector.type) {
case "pseudo-element":
throw new Error("Pseudo-elements are not supported by css-select");
case "attribute":
return attributes_1.attributeRules[selector.action](next, selector, options);
case "pseudo":
return pseudo_selectors_1.compilePseudoSelector(next, selector, options, context, compileToken);
// Tags
case "tag":
return function tag(elem) {
return adapter.getName(elem) === selector.name && next(elem);
};
// Traversal
case "descendant":
if (options.cacheResults === false ||
typeof WeakSet === "undefined") {
return function descendant(elem) {
var current = elem;
while ((current = adapter.getParent(current))) {
if (adapter.isTag(current) && next(current)) {
return true;
}
}
return false;
};
}
// @ts-expect-error `ElementNode` is not extending object
// eslint-disable-next-line no-case-declarations
var isFalseCache_1 = new WeakSet();
return function cachedDescendant(elem) {
var current = elem;
while ((current = adapter.getParent(current))) {
if (!isFalseCache_1.has(current)) {
if (adapter.isTag(current) && next(current)) {
return true;
}
isFalseCache_1.add(current);
}
}
return false;
};
case "_flexibleDescendant":
// Include element itself, only used while querying an array
return function flexibleDescendant(elem) {
var current = elem;
do {
if (adapter.isTag(current) && next(current))
return true;
} while ((current = adapter.getParent(current)));
return false;
};
case "parent":
return function parent(elem) {
return adapter
.getChildren(elem)
.some(function (elem) { return adapter.isTag(elem) && next(elem); });
};
case "child":
return function child(elem) {
var parent = adapter.getParent(elem);
return parent != null && adapter.isTag(parent) && next(parent);
};
case "sibling":
return function sibling(elem) {
var siblings = adapter.getSiblings(elem);
for (var i = 0; i < siblings.length; i++) {
var currentSibling = siblings[i];
if (equals(elem, currentSibling))
break;
if (adapter.isTag(currentSibling) && next(currentSibling)) {
return true;
}
}
return false;
};
case "adjacent":
return function adjacent(elem) {
var siblings = adapter.getSiblings(elem);
var lastElement;
for (var i = 0; i < siblings.length; i++) {
var currentSibling = siblings[i];
if (equals(elem, currentSibling))
break;
if (adapter.isTag(currentSibling)) {
lastElement = currentSibling;
}
}
return !!lastElement && next(lastElement);
};
case "universal":
return next;
}
}
exports.compileGeneralSelector = compileGeneralSelector;
import type { CompiledQuery, Options, Query, Adapter } from "./types";
export type { Options };
/**
* Compiles the query, returns a function.
*/
export declare const compile: <Node_1, ElementNode extends Node_1>(selector: string | import("css-what").Selector[][], options?: Options<Node_1, ElementNode> | undefined, context?: Node_1 | Node_1[] | undefined) => CompiledQuery<ElementNode>;
export declare const _compileUnsafe: <Node_1, ElementNode extends Node_1>(selector: string | import("css-what").Selector[][], options?: Options<Node_1, ElementNode> | undefined, context?: Node_1 | Node_1[] | undefined) => CompiledQuery<ElementNode>;
export declare const _compileToken: <Node_1, ElementNode extends Node_1>(selector: import("./types").InternalSelector[][], options?: Options<Node_1, ElementNode> | undefined, context?: Node_1 | Node_1[] | undefined) => CompiledQuery<ElementNode>;
export declare function prepareContext<Node, ElementNode extends Node>(elems: Node | Node[], adapter: Adapter<Node, ElementNode>, shouldTestNextSiblings?: boolean): Node[];
/**
* @template Node The generic Node type for the DOM adapter being used.
* @template ElementNode The Node type for elements for the DOM adapter being used.
* @param elems Elements to query. If it is an element, its children will be queried..
* @param query can be either a CSS selector string or a compiled query function.
* @param [options] options for querying the document.
* @see compile for supported selector queries.
* @returns All matching elements.
*
*/
export declare const selectAll: <Node_1, ElementNode extends Node_1>(query: Query<ElementNode>, elements: Node_1 | Node_1[], options?: Options<Node_1, ElementNode> | undefined) => ElementNode[];
/**
* @template Node The generic Node type for the DOM adapter being used.
* @template ElementNode The Node type for elements for the DOM adapter being used.
* @param elems Elements to query. If it is an element, its children will be queried..
* @param query can be either a CSS selector string or a compiled query function.
* @param [options] options for querying the document.
* @see compile for supported selector queries.
* @returns the first match, or null if there was no match.
*/
export declare const selectOne: <Node_1, ElementNode extends Node_1>(query: Query<ElementNode>, elements: Node_1 | Node_1[], options?: Options<Node_1, ElementNode> | undefined) => ElementNode | null;
/**
* Tests whether or not an element is matched by query.
*
* @template Node The generic Node type for the DOM adapter being used.
* @template ElementNode The Node type for elements for the DOM adapter being used.
* @param elem The element to test if it matches the query.
* @param query can be either a CSS selector string or a compiled query function.
* @param [options] options for querying the document.
* @see compile for supported selector queries.
* @returns
*/
export declare function is<Node, ElementNode extends Node>(elem: ElementNode, query: Query<ElementNode>, options?: Options<Node, ElementNode>): boolean;
/**
* Alias for selectAll(query, elems, options).
* @see [compile] for supported selector queries.
*/
export default selectAll;
export { filters, pseudos, aliases } from "./pseudo-selectors";
//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,aAAa,EACb,OAAO,EAEP,KAAK,EACL,OAAO,EAEV,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,OAAO,EAAE,CAAC;AA0CxB;;GAEG;AACH,eAAO,MAAM,OAAO,qNAA0B,CAAC;AAC/C,eAAO,MAAM,cAAc,qNAA6B,CAAC;AACzD,eAAO,MAAM,aAAa,mNAA4B,CAAC;AA6BvD,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EACzD,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,EACpB,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,EACnC,sBAAsB,UAAQ,GAC/B,IAAI,EAAE,CAYR;AAgBD;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,mKASrB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,wKASrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,EAAE,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAC7C,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,EACzB,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,GACrC,OAAO,CAKT;AAED;;;GAGG;AACH,eAAe,SAAS,CAAC;AAGzB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC"}
\ No newline at end of file
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.aliases = exports.pseudos = exports.filters = exports.is = exports.selectOne = exports.selectAll = exports.prepareContext = exports._compileToken = exports._compileUnsafe = exports.compile = void 0;
var DomUtils = __importStar(require("domutils"));
var boolbase_1 = require("boolbase");
var compile_1 = require("./compile");
var subselects_1 = require("./pseudo-selectors/subselects");
var defaultEquals = function (a, b) { return a === b; };
var defaultOptions = {
adapter: DomUtils,
equals: defaultEquals,
};
function convertOptionFormats(options) {
var _a, _b, _c, _d;
/*
* We force one format of options to the other one.
*/
// @ts-expect-error Default options may have incompatible `Node` / `ElementNode`.
var opts = options !== null && options !== void 0 ? options : defaultOptions;
// @ts-expect-error Same as above.
(_a = opts.adapter) !== null && _a !== void 0 ? _a : (opts.adapter = DomUtils);
// @ts-expect-error `equals` does not exist on `Options`
(_b = opts.equals) !== null && _b !== void 0 ? _b : (opts.equals = (_d = (_c = opts.adapter) === null || _c === void 0 ? void 0 : _c.equals) !== null && _d !== void 0 ? _d : defaultEquals);
return opts;
}
function wrapCompile(func) {
return function addAdapter(selector, options, context) {
var opts = convertOptionFormats(options);
return func(selector, opts, context);
};
}
/**
* Compiles the query, returns a function.
*/
exports.compile = wrapCompile(compile_1.compile);
exports._compileUnsafe = wrapCompile(compile_1.compileUnsafe);
exports._compileToken = wrapCompile(compile_1.compileToken);
function getSelectorFunc(searchFunc) {
return function select(query, elements, options) {
var opts = convertOptionFormats(options);
if (typeof query !== "function") {
query = compile_1.compileUnsafe(query, opts, elements);
}
var filteredElements = prepareContext(elements, opts.adapter, query.shouldTestNextSiblings);
return searchFunc(query, filteredElements, opts);
};
}
function prepareContext(elems, adapter, shouldTestNextSiblings) {
if (shouldTestNextSiblings === void 0) { shouldTestNextSiblings = false; }
/*
* Add siblings if the query requires them.
* See https://github.com/fb55/css-select/pull/43#issuecomment-225414692
*/
if (shouldTestNextSiblings) {
elems = appendNextSiblings(elems, adapter);
}
return Array.isArray(elems)
? adapter.removeSubsets(elems)
: adapter.getChildren(elems);
}
exports.prepareContext = prepareContext;
function appendNextSiblings(elem, adapter) {
// Order matters because jQuery seems to check the children before the siblings
var elems = Array.isArray(elem) ? elem.slice(0) : [elem];
for (var i = 0; i < elems.length; i++) {
var nextSiblings = subselects_1.getNextSiblings(elems[i], adapter);
elems.push.apply(elems, nextSiblings);
}
return elems;
}
/**
* @template Node The generic Node type for the DOM adapter being used.
* @template ElementNode The Node type for elements for the DOM adapter being used.
* @param elems Elements to query. If it is an element, its children will be queried..
* @param query can be either a CSS selector string or a compiled query function.
* @param [options] options for querying the document.
* @see compile for supported selector queries.
* @returns All matching elements.
*
*/
exports.selectAll = getSelectorFunc(function (query, elems, options) {
return query === boolbase_1.falseFunc || !elems || elems.length === 0
? []
: options.adapter.findAll(query, elems);
});
/**
* @template Node The generic Node type for the DOM adapter being used.
* @template ElementNode The Node type for elements for the DOM adapter being used.
* @param elems Elements to query. If it is an element, its children will be queried..
* @param query can be either a CSS selector string or a compiled query function.
* @param [options] options for querying the document.
* @see compile for supported selector queries.
* @returns the first match, or null if there was no match.
*/
exports.selectOne = getSelectorFunc(function (query, elems, options) {
return query === boolbase_1.falseFunc || !elems || elems.length === 0
? null
: options.adapter.findOne(query, elems);
});
/**
* Tests whether or not an element is matched by query.
*
* @template Node The generic Node type for the DOM adapter being used.
* @template ElementNode The Node type for elements for the DOM adapter being used.
* @param elem The element to test if it matches the query.
* @param query can be either a CSS selector string or a compiled query function.
* @param [options] options for querying the document.
* @see compile for supported selector queries.
* @returns
*/
function is(elem, query, options) {
var opts = convertOptionFormats(options);
return (typeof query === "function" ? query : compile_1.compile(query, opts))(elem);
}
exports.is = is;
/**
* Alias for selectAll(query, elems, options).
* @see [compile] for supported selector queries.
*/
exports.default = exports.selectAll;
// Export filters, pseudos and aliases to allow users to supply their own.
var pseudo_selectors_1 = require("./pseudo-selectors");
Object.defineProperty(exports, "filters", { enumerable: true, get: function () { return pseudo_selectors_1.filters; } });
Object.defineProperty(exports, "pseudos", { enumerable: true, get: function () { return pseudo_selectors_1.pseudos; } });
Object.defineProperty(exports, "aliases", { enumerable: true, get: function () { return pseudo_selectors_1.aliases; } });
import type { Traversal } from "css-what";
import type { InternalSelector } from "./types";
export declare const procedure: Record<InternalSelector["type"], number>;
export declare function isTraversal(t: InternalSelector): t is Traversal;
//# sourceMappingURL=procedure.d.ts.map
\ No newline at end of file
{"version":3,"file":"procedure.d.ts","sourceRoot":"","sources":["../src/procedure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,CAY9D,CAAC;AAEF,wBAAgB,WAAW,CAAC,CAAC,EAAE,gBAAgB,GAAG,CAAC,IAAI,SAAS,CAE/D"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTraversal = exports.procedure = void 0;
exports.procedure = {
universal: 50,
tag: 30,
attribute: 1,
pseudo: 0,
"pseudo-element": 0,
descendant: -1,
child: -1,
parent: -1,
sibling: -1,
adjacent: -1,
_flexibleDescendant: -1,
};
function isTraversal(t) {
return exports.procedure[t.type] < 0;
}
exports.isTraversal = isTraversal;
/**
* Aliases are pseudos that are expressed as selectors.
*/
export declare const aliases: Record<string, string>;
//# sourceMappingURL=aliases.d.ts.map
\ No newline at end of file
{"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../../src/pseudo-selectors/aliases.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAwC1C,CAAC"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.aliases = void 0;
/**
* Aliases are pseudos that are expressed as selectors.
*/
exports.aliases = {
// Links
"any-link": ":is(a, area, link)[href]",
link: ":any-link:not(:visited)",
// Forms
// https://html.spec.whatwg.org/multipage/scripting.html#disabled-elements
disabled: ":is(\n :is(button, input, select, textarea, optgroup, option)[disabled],\n optgroup[disabled] > option,\n fieldset[disabled]:not(fieldset[disabled] legend:first-of-type *)\n )",
enabled: ":not(:disabled)",
checked: ":is(:is(input[type=radio], input[type=checkbox])[checked], option:selected)",
required: ":is(input, select, textarea)[required]",
optional: ":is(input, select, textarea):not([required])",
// JQuery extensions
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-selectedness
selected: "option:is([selected], select:not([multiple]):not(:has(> option[selected])) > :first-of-type)",
checkbox: "[type=checkbox]",
file: "[type=file]",
password: "[type=password]",
radio: "[type=radio]",
reset: "[type=reset]",
image: "[type=image]",
submit: "[type=submit]",
parent: ":not(:empty)",
header: ":is(h1, h2, h3, h4, h5, h6)",
button: ":is(button, input[type=button])",
input: ":is(input, textarea, select, button)",
text: "input:is(:not([type!='']), [type=text])",
};
import type { CompiledQuery, InternalOptions } from "../types";
export declare type Filter = <Node, ElementNode extends Node>(next: CompiledQuery<ElementNode>, text: string, options: InternalOptions<Node, ElementNode>, context?: Node[]) => CompiledQuery<ElementNode>;
export declare const filters: Record<string, Filter>;
//# sourceMappingURL=filters.d.ts.map
\ No newline at end of file
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../src/pseudo-selectors/filters.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAW,MAAM,UAAU,CAAC;AAExE,oBAAY,MAAM,GAAG,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAChD,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,KACf,aAAa,CAAC,WAAW,CAAC,CAAC;AAYhC,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA2I1C,CAAC"}
\ No newline at end of file
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.filters = void 0;
var nth_check_1 = __importDefault(require("nth-check"));
var boolbase_1 = require("boolbase");
function getChildFunc(next, adapter) {
return function (elem) {
var parent = adapter.getParent(elem);
return parent != null && adapter.isTag(parent) && next(elem);
};
}
exports.filters = {
contains: function (next, text, _a) {
var adapter = _a.adapter;
return function contains(elem) {
return next(elem) && adapter.getText(elem).includes(text);
};
},
icontains: function (next, text, _a) {
var adapter = _a.adapter;
var itext = text.toLowerCase();
return function icontains(elem) {
return (next(elem) &&
adapter.getText(elem).toLowerCase().includes(itext));
};
},
// Location specific methods
"nth-child": function (next, rule, _a) {
var adapter = _a.adapter, equals = _a.equals;
var func = nth_check_1.default(rule);
if (func === boolbase_1.falseFunc)
return boolbase_1.falseFunc;
if (func === boolbase_1.trueFunc)
return getChildFunc(next, adapter);
return function nthChild(elem) {
var siblings = adapter.getSiblings(elem);
var pos = 0;
for (var i = 0; i < siblings.length; i++) {
if (equals(elem, siblings[i]))
break;
if (adapter.isTag(siblings[i])) {
pos++;
}
}
return func(pos) && next(elem);
};
},
"nth-last-child": function (next, rule, _a) {
var adapter = _a.adapter, equals = _a.equals;
var func = nth_check_1.default(rule);
if (func === boolbase_1.falseFunc)
return boolbase_1.falseFunc;
if (func === boolbase_1.trueFunc)
return getChildFunc(next, adapter);
return function nthLastChild(elem) {
var siblings = adapter.getSiblings(elem);
var pos = 0;
for (var i = siblings.length - 1; i >= 0; i--) {
if (equals(elem, siblings[i]))
break;
if (adapter.isTag(siblings[i])) {
pos++;
}
}
return func(pos) && next(elem);
};
},
"nth-of-type": function (next, rule, _a) {
var adapter = _a.adapter, equals = _a.equals;
var func = nth_check_1.default(rule);
if (func === boolbase_1.falseFunc)
return boolbase_1.falseFunc;
if (func === boolbase_1.trueFunc)
return getChildFunc(next, adapter);
return function nthOfType(elem) {
var siblings = adapter.getSiblings(elem);
var pos = 0;
for (var i = 0; i < siblings.length; i++) {
var currentSibling = siblings[i];
if (equals(elem, currentSibling))
break;
if (adapter.isTag(currentSibling) &&
adapter.getName(currentSibling) === adapter.getName(elem)) {
pos++;
}
}
return func(pos) && next(elem);
};
},
"nth-last-of-type": function (next, rule, _a) {
var adapter = _a.adapter, equals = _a.equals;
var func = nth_check_1.default(rule);
if (func === boolbase_1.falseFunc)
return boolbase_1.falseFunc;
if (func === boolbase_1.trueFunc)
return getChildFunc(next, adapter);
return function nthLastOfType(elem) {
var siblings = adapter.getSiblings(elem);
var pos = 0;
for (var i = siblings.length - 1; i >= 0; i--) {
var currentSibling = siblings[i];
if (equals(elem, currentSibling))
break;
if (adapter.isTag(currentSibling) &&
adapter.getName(currentSibling) === adapter.getName(elem)) {
pos++;
}
}
return func(pos) && next(elem);
};
},
// TODO determine the actual root element
root: function (next, _rule, _a) {
var adapter = _a.adapter;
return function (elem) {
var parent = adapter.getParent(elem);
return (parent == null || !adapter.isTag(parent)) && next(elem);
};
},
scope: function (next, rule, options, context) {
var equals = options.equals;
if (!context || context.length === 0) {
// Equivalent to :root
return exports.filters.root(next, rule, options);
}
if (context.length === 1) {
// NOTE: can't be unpacked, as :has uses this for side-effects
return function (elem) { return equals(context[0], elem) && next(elem); };
}
return function (elem) { return context.includes(elem) && next(elem); };
},
hover: dynamicStatePseudo("isHovered"),
visited: dynamicStatePseudo("isVisited"),
active: dynamicStatePseudo("isActive"),
};
/**
* Dynamic state pseudos. These depend on optional Adapter methods.
*
* @param name The name of the adapter method to call.
* @returns Pseudo for the `filters` object.
*/
function dynamicStatePseudo(name) {
return function dynamicPseudo(next, _rule, _a) {
var adapter = _a.adapter;
var func = adapter[name];
if (typeof func !== "function") {
return boolbase_1.falseFunc;
}
return function active(elem) {
return func(elem) && next(elem);
};
};
}
import type { CompiledQuery, InternalOptions, CompileToken } from "../types";
import { PseudoSelector } from "css-what";
import { filters } from "./filters";
import { pseudos } from "./pseudos";
import { aliases } from "./aliases";
export { filters, pseudos, aliases };
export declare function compilePseudoSelector<Node, ElementNode extends Node>(next: CompiledQuery<ElementNode>, selector: PseudoSelector, options: InternalOptions<Node, ElementNode>, context: Node[] | undefined, compileToken: CompileToken<Node, ElementNode>): CompiledQuery<ElementNode>;
//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pseudo-selectors/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAS,cAAc,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAoB,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAErC,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAChE,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAChC,QAAQ,EAAE,cAAc,EACxB,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,EAAE,IAAI,EAAE,GAAG,SAAS,EAC3B,YAAY,EAAE,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,GAC9C,aAAa,CAAC,WAAW,CAAC,CA6B5B"}
\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.