fix
This commit is contained in:
21
book/node_modules/juice/LICENSE.md
generated
vendored
Normal file
21
book/node_modules/juice/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# MIT License
|
||||
|
||||
Copyright (c) 2021 Automattic
|
||||
|
||||
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.
|
||||
199
book/node_modules/juice/README.md
generated
vendored
Normal file
199
book/node_modules/juice/README.md
generated
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
[](https://travis-ci.org/Automattic/juice)
|
||||
[](https://david-dm.org/Automattic/juice)
|
||||
|
||||
# Juice 
|
||||
|
||||
Given HTML, juice will inline your CSS properties into the `style` attribute.
|
||||
|
||||
[Some projects using Juice](PROJECTS.md)
|
||||
|
||||
## How to use
|
||||
|
||||
Juice has a number of functions based on whether you want to process a file, HTML string, or a cheerio document, and whether you want juice to automatically get remote stylesheets, scripts and image dataURIs to inline.
|
||||
|
||||
To inline HTML without getting remote resources, using default options:
|
||||
|
||||
```js
|
||||
var juice = require('juice');
|
||||
var result = juice("<style>div{color:red;}</style><div/>");
|
||||
```
|
||||
|
||||
result will be:
|
||||
```html
|
||||
<div style="color: red;"></div>
|
||||
```
|
||||
|
||||
[Try out the web client version](https://automattic.github.io/juice/)
|
||||
|
||||
## What is this useful for ?
|
||||
|
||||
- HTML emails. For a comprehensive list of supported selectors see [here](https://www.campaignmonitor.com/css/)
|
||||
- Embedding HTML in 3rd-party websites.
|
||||
|
||||
## Documentation
|
||||
|
||||
Juice is exposed as a standard module, and from CLI with a smaller set of options.
|
||||
|
||||
### Options
|
||||
|
||||
All juice methods take an options object that can contain any of these properties, though not every method uses all of these:
|
||||
|
||||
* `applyAttributesTableElements` - whether to create attributes for styles in `juice.styleToAttribute` on elements set in `juice.tableElements`. Defaults to `true`.
|
||||
|
||||
* `applyHeightAttributes` - whether to use any CSS pixel heights to create `height` attributes on elements set in `juice.heightElements`. Defaults to `true`.
|
||||
|
||||
* `applyStyleTags` - whether to inline styles in `<style></style>` Defaults to `true`.
|
||||
|
||||
* `applyWidthAttributes` - whether to use any CSS pixel widths to create `width` attributes on elements set in `juice.widthElements`. Defaults to `true`.
|
||||
|
||||
* `extraCss` - extra css to apply to the file. Defaults to `""`.
|
||||
|
||||
* `insertPreservedExtraCss` - whether to insert into the document any preserved `@media` or `@font-face` content from `extraCss` when using `preserveMediaQueries`, `preserveFontFaces` or `preserveKeyFrames`. When `true` order of preference to append the `<style>` element is into `head`, then `body`, then at the end of the document. When a `string` the value is treated as a CSS/jQuery/cheerio selector, and when found, the `<style>` tag will be appended to the end of the first match. Defaults to `true`.
|
||||
|
||||
* `inlinePseudoElements` - Whether to insert pseudo elements (`::before` and `::after`) as `<span>` into the DOM. *Note*: Inserting pseudo elements will modify the DOM and may conflict with CSS selectors elsewhere on the page (e.g., `:last-child`).
|
||||
|
||||
* `preserveFontFaces` - preserves all `@font-face` within `<style></style>` tags as a refinement when `removeStyleTags` is `true`. Other styles are removed. Defaults to `true`.
|
||||
|
||||
* `preserveImportant` - preserves `!important` in values. Defaults to `false`.
|
||||
|
||||
* `preserveMediaQueries` - preserves all media queries (and contained styles) within `<style></style>` tags as a refinement when `removeStyleTags` is `true`. Other styles are removed. Defaults to `true`.
|
||||
|
||||
* `preserveKeyFrames` - preserves all key frames within `<style></style>` tags as a refinement when `removeStyleTags` is `true`. Other styles are removed. Defaults to `true`.
|
||||
|
||||
* `preservePseudos` - preserves all rules containing pseudo selectors defined in `ignoredPseudos` within `<style></style>` tags as a refinement when `removeStyleTags` is `true`. Other styles are removed. Defaults to `true`.
|
||||
|
||||
* `removeStyleTags` - whether to remove the original `<style></style>` tags after (possibly) inlining the css from them. Defaults to `true`.
|
||||
|
||||
* `webResources` - An options object that will be passed to [web-resource-inliner](https://www.npmjs.com/package/web-resource-inliner) for juice functions that will get remote resources (`juiceResources` and `juiceFile`). Defaults to `{}`.
|
||||
|
||||
* `xmlMode` - whether to output XML/XHTML with all tags closed. Note that the input *must* also be valid XML/XHTML or you will get undesirable results. Defaults to `false`.
|
||||
|
||||
|
||||
### Methods
|
||||
|
||||
#### juice(html [, options])
|
||||
|
||||
Returns string containing inlined HTML. Does not fetch remote resources.
|
||||
|
||||
* `html` - html string, accepts complete documents as well as fragments
|
||||
* `options` - optional, see Options above
|
||||
|
||||
#### juice.juiceResources(html, options, callback)
|
||||
|
||||
Callback returns string containing inlined HTML. Fetches remote resources.
|
||||
|
||||
* `html` - html string
|
||||
* `options` - see Options above
|
||||
* `callback(err, html)`
|
||||
- `err` - `Error` object or `null`
|
||||
- `html` - inlined HTML
|
||||
|
||||
#### juice.juiceFile(filePath, options, callback)
|
||||
|
||||
Callback returns string containing inlined HTML. Fetches remote resources.
|
||||
|
||||
* `filePath` - path to the html file to be juiced
|
||||
* `options` - see Options above
|
||||
* `callback(err, html)`
|
||||
- `err` - `Error` object or `null`
|
||||
- `html` - inlined HTML
|
||||
|
||||
#### juice.juiceDocument($ [, options])
|
||||
|
||||
This takes a cheerio instance and performs inlining in-place. Returns the
|
||||
same cheerio instance. Does not fetch remote resources.
|
||||
|
||||
* `$` - a cheerio instance, be sure to use the same cheerio version that juice uses
|
||||
* `options` - optional, see Options above`
|
||||
|
||||
#### juice.inlineContent(html, css [, options])
|
||||
|
||||
This takes html and css and returns new html with the provided css inlined.
|
||||
It does not look at `<style>` or `<link rel="stylesheet">` elements at all.
|
||||
|
||||
* `html` - html string
|
||||
* `css` - css string
|
||||
* `options` - optional, see Options above
|
||||
|
||||
#### juice.inlineDocument($, css [, options])
|
||||
|
||||
Given a cheerio instance and css, this modifies the cheerio instance so that the provided css is inlined. It does not look at `<style>` or `<link rel="stylesheet">` elements at all.
|
||||
|
||||
* `$` - a cheerio instance, be sure to use the same cheerio version that juice uses
|
||||
* `css` - css string
|
||||
* `options` - optional, see Options above
|
||||
|
||||
### Global settings
|
||||
|
||||
#### juice.codeBlocks
|
||||
|
||||
An object where each value has a `start` and `end` to specify fenced code blocks that should be ignored during parsing and inlining. For example, Handlebars (hbs) templates are `juice.codeBlocks.HBS = {start: '{{', end: '}}'}`. `codeBlocks` can fix problems where otherwise juice might interpret code like `<=` as HTML, when it is meant to be template language code. Note that `codeBlocks` is a dictionary which can contain many different code blocks, so don't do `juice.codeBlocks = {...}` do `juice.codeBlocks.myBlock = {...}`
|
||||
|
||||
#### juice.ignoredPseudos
|
||||
|
||||
Array of ignored pseudo-selectors such as 'hover' and 'active'.
|
||||
|
||||
#### juice.widthElements
|
||||
|
||||
Array of HTML elements that can receive `width` attributes.
|
||||
|
||||
#### juice.heightElements
|
||||
|
||||
Array of HTML elements that can receive `height` attributes.
|
||||
|
||||
#### juice.styleToAttribute
|
||||
|
||||
Object of style property names (key) to their respective attribute names (value).
|
||||
|
||||
#### juice.tableElements
|
||||
|
||||
Array of table HTML elements that can receive attributes defined in `juice.styleToAttribute`.
|
||||
|
||||
#### juice.nonVisualElements
|
||||
|
||||
Array of elements that will not have styles inlined because they are not intended to render.
|
||||
|
||||
#### juiceClient.excludedProperties
|
||||
|
||||
Array of css properties that won't be inlined.
|
||||
|
||||
### Special markup
|
||||
|
||||
#### data-embed
|
||||
When a `data-embed` attribute is present on a stylesheet `<link>` that has been inlined into the document as a `<style></style>` tag by the web-resource-inliner juice will not inline the styles and will not remove the `<style></style>` tags.
|
||||
|
||||
This can be used to embed email client support hacks that rely on css selectors into your email templates.
|
||||
|
||||
### CLI Options
|
||||
|
||||
To use Juice from CLI, run `juice [options] input.html output.html`
|
||||
|
||||
For a listing of all available options, just type `juice -h`.
|
||||
|
||||
> Note that if you want to just type `juice` from the command line, you should `npm install juice -g` so it is globally available.
|
||||
|
||||
CLI Options:
|
||||
|
||||
The CLI should have all the above [options](#options) with the names changed from camel case to hyphen-delimited, so for example `extraCss` becomes `extra-css` and `webResources.scripts` becomes `web-resources-scripts`.
|
||||
|
||||
These are additional options not included in the standard `juice` options listed above:
|
||||
|
||||
- `--css [filepath]` will load and inject CSS into `extraCss`.
|
||||
- `--options-file [filepath]` will load and inject options from a JSON file. Options from the CLI will be given priority over options in the file when there is a conflict.
|
||||
- `codeBlocks` is optionally supported in the options file if you include it. This will allow you to support different template languages in a build process.
|
||||
|
||||
### Running Juice in the Browser
|
||||
|
||||
Attempting to Browserify `require('juice')` fails because portions of Juice and its dependencies interact with the file system using the standard `require('fs')`. However, you can `require('juice/client')` via Browserify which has support for `juiceDocument`, `inlineDocument`, and `inlineContent`, but not `juiceFile`, `juiceResources`, or `inlineExternal`. *Note that automated tests are not running in the browser yet.*
|
||||
|
||||
## License
|
||||
|
||||
MIT Licensed, see License.md
|
||||
|
||||
### 3rd-party
|
||||
|
||||
- Uses [cheerio](https://github.com/cheeriojs/cheerio) for the underlying DOM
|
||||
representation.
|
||||
- Uses [mensch](https://github.com/brettstimmerman/mensch) to parse out CSS and
|
||||
[Slick](https://github.com/subtleGradient/slick) to tokenize them.
|
||||
- Icon by [UnheardSounds](http://unheardsounds.deviantart.com/gallery/26536908#/d2ngozi)
|
||||
64
book/node_modules/juice/bin/juice
generated
vendored
Executable file
64
book/node_modules/juice/bin/juice
generated
vendored
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var juice = require('..');
|
||||
var cli = require('../lib/cli');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var program = cli.getProgram();
|
||||
|
||||
if (program.args.length < 2) {
|
||||
program.help();
|
||||
}
|
||||
|
||||
var [inputFile, outputFile] = program.args;
|
||||
var options = cli.argsToOptions(program);
|
||||
var queue = [];
|
||||
|
||||
if (options.optionsFile) {
|
||||
var optionsFromFile = require(path.resolve(process.cwd(),options.optionsFile));
|
||||
options = Object.assign({}, optionsFromFile, options, {
|
||||
webResources: Object.assign(
|
||||
{},
|
||||
optionsFromFile && optionsFromFile.webResources,
|
||||
options && options.webResources
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
if (options.cssFile) {
|
||||
queue.push(function() {
|
||||
fs.readFile(options.cssFile, function(err, css) {
|
||||
if (handleError(err)) { return; }
|
||||
options.extraCss = css.toString();
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
function doJuice() {
|
||||
delete options.cssFile;
|
||||
delete options.optionsFile;
|
||||
|
||||
juice.juiceFile(inputFile, options, function(err, html) {
|
||||
if (handleError(err)) { return; }
|
||||
fs.writeFile(outputFile, html, handleError);
|
||||
});
|
||||
}
|
||||
|
||||
function next() {
|
||||
if (queue.length) {
|
||||
return queue.pop()();
|
||||
}
|
||||
doJuice();
|
||||
}
|
||||
|
||||
function handleError(err) {
|
||||
if (err) {
|
||||
console.error(err.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
return !!err;
|
||||
}
|
||||
27
book/node_modules/juice/client.js
generated
vendored
Normal file
27
book/node_modules/juice/client.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
var cheerio = require('./lib/cheerio');
|
||||
var makeJuiceClient = require('./lib/inline');
|
||||
|
||||
/**
|
||||
* Note that makeJuiceClient will take a base object (in this case a function) and enhance it
|
||||
* with a lot of useful properties and functions.
|
||||
*
|
||||
* This client adopts cheerio as a DOM parser and adds an "inlineContent" function that let
|
||||
* users to specify the CSS to be inlined instead of extracting it from the html.
|
||||
*
|
||||
* The weird "makeJuiceClient" behaviour is there in order to keep backward API compatibility.
|
||||
*/
|
||||
var juiceClient = makeJuiceClient(function(html,options) {
|
||||
return cheerio(html, { xmlMode: options && options.xmlMode}, juiceDocument, [options]);
|
||||
});
|
||||
|
||||
var juiceDocument = function(html, options) {
|
||||
return juiceClient.juiceDocument(html, options);
|
||||
}
|
||||
|
||||
juiceClient.inlineContent = function(html, css, options) {
|
||||
return cheerio(html, { xmlMode: options && options.xmlMode}, juiceClient.inlineDocument, [css, options]);
|
||||
};
|
||||
|
||||
module.exports = juiceClient;
|
||||
81
book/node_modules/juice/index.js
generated
vendored
Normal file
81
book/node_modules/juice/index.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var utils = require('./lib/utils');
|
||||
var packageJson = require('./package.json');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var inline = require('web-resource-inliner');
|
||||
var juiceClient = require('./client');
|
||||
var cheerio = require('./lib/cheerio');
|
||||
var juice = juiceClient;
|
||||
|
||||
module.exports = juice;
|
||||
|
||||
juice.version = packageJson.version;
|
||||
|
||||
juice.Selector = utils.Selector;
|
||||
juice.Property = utils.Property;
|
||||
juice.utils = utils;
|
||||
|
||||
juice.ignoredPseudos = juiceClient.ignoredPseudos;
|
||||
juice.widthElements = juiceClient.widthElements;
|
||||
juice.tableElements = juiceClient.tableElements;
|
||||
juice.nonVisualElements = juiceClient.nonVisualElements;
|
||||
juice.styleToAttribute = juiceClient.styleToAttribute;
|
||||
|
||||
juice.juiceDocument = juiceClient.juiceDocument;
|
||||
juice.inlineDocument = juiceClient.inlineDocument;
|
||||
juice.inlineContent = juiceClient.inlineContent;
|
||||
|
||||
juice.juiceFile = juiceFile;
|
||||
juice.juiceResources = juiceResources;
|
||||
juice.inlineExternal = inlineExternal;
|
||||
|
||||
juice.codeBlocks = cheerio.codeBlocks;
|
||||
|
||||
function juiceFile(filePath, options, callback) {
|
||||
// set default options
|
||||
fs.readFile(filePath, 'utf8', function(err, content) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
options = utils.getDefaultOptions(options); // so we can mutate options without guilt
|
||||
// Optional support for codeBlocks within optionsFile
|
||||
if (options.codeBlocks) {
|
||||
Object.keys(options.codeBlocks).forEach(function(key) {
|
||||
juice.codeBlocks[key] = options.codeBlocks[key];
|
||||
});
|
||||
}
|
||||
if (!options.webResources.relativeTo) {
|
||||
var rel = path.dirname(path.relative(process.cwd(),filePath));
|
||||
options.webResources.relativeTo = rel;
|
||||
}
|
||||
juiceResources(content, options, callback);
|
||||
});
|
||||
}
|
||||
|
||||
function inlineExternal(html, inlineOptions, callback) {
|
||||
var options = Object.assign({fileContent: html}, inlineOptions);
|
||||
inline.html(options, callback);
|
||||
}
|
||||
|
||||
function juiceResources(html, options, callback) {
|
||||
options = utils.getDefaultOptions(options);
|
||||
|
||||
var onInline = function(err, html) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
return callback(null,
|
||||
cheerio(html, { xmlMode: options && options.xmlMode}, juiceClient.juiceDocument, [options])
|
||||
);
|
||||
};
|
||||
|
||||
options.webResources.relativeTo = options.webResources.relativeTo || options.url; // legacy support
|
||||
inlineExternal(html, options.webResources, onInline);
|
||||
}
|
||||
65
book/node_modules/juice/juice.d.ts
generated
vendored
Normal file
65
book/node_modules/juice/juice.d.ts
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
// Type definitions for Juice 3.0.0
|
||||
// Project: https://github.com/Automattic/juice
|
||||
// Definitions by: Kamil Nikel <https://github.com/knikel>
|
||||
|
||||
/* =================== USAGE ===================
|
||||
import juice = require('juice');
|
||||
=============================================== */
|
||||
|
||||
export = juice;
|
||||
|
||||
declare function juice(html: string, options?: juice.Options): string;
|
||||
|
||||
declare namespace juice {
|
||||
|
||||
export function juiceResources(html: string, options: Options, callback: Callback): string
|
||||
|
||||
export function juiceFile(filePath: string, options: Options, callback: Callback): string
|
||||
|
||||
export function juiceDocument($: any, options?: Options): any
|
||||
|
||||
export function inlineContent(html: string, css: string, options?: Options): string
|
||||
|
||||
export function inlineDocument($: any, css: string, options?: Options): any
|
||||
|
||||
export let codeBlocks: { [index: string]: { start: string, end: string } };
|
||||
export let excludedProperties: string[];
|
||||
export let heightElements: HTMLElement[];
|
||||
export let ignoredPseudos: string[];
|
||||
export let nonVisualElements: HTMLElement[];
|
||||
export let styleToAttribute: { [index: string]: string };
|
||||
export let tableElements: HTMLElement[];
|
||||
export let widthElements: HTMLElement[];
|
||||
|
||||
export interface Callback { (err: Error, html: string): any; }
|
||||
|
||||
interface Options {
|
||||
extraCss?: string;
|
||||
applyStyleTags?: boolean;
|
||||
removeStyleTags?: boolean;
|
||||
preserveMediaQueries?: boolean;
|
||||
preserveFontFaces?: boolean;
|
||||
preserveKeyFrames?: boolean;
|
||||
preservePseudos?: boolean;
|
||||
insertPreservedExtraCss?: boolean;
|
||||
applyWidthAttributes?: boolean;
|
||||
applyHeightAttributes?: boolean;
|
||||
applyAttributesTableElements?: boolean;
|
||||
webResources?: WebResourcesOptions;
|
||||
inlinePseudoElements?: boolean;
|
||||
xmlMode?: boolean;
|
||||
preserveImportant?: boolean;
|
||||
}
|
||||
|
||||
interface WebResourcesOptions {
|
||||
fileContent?: string;
|
||||
inlineAttribute?: string;
|
||||
images?: boolean | number;
|
||||
svgs?: boolean | number;
|
||||
scripts?: boolean | number;
|
||||
links?: boolean | number;
|
||||
relativeTo?: string;
|
||||
rebaseRelativeTo?: string;
|
||||
strict?: boolean;
|
||||
}
|
||||
}
|
||||
72
book/node_modules/juice/lib/cheerio.js
generated
vendored
Normal file
72
book/node_modules/juice/lib/cheerio.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var cheerio = require('cheerio');
|
||||
var utils = require('./utils');
|
||||
|
||||
var cheerioLoad = function(html, options, encodeEntities) {
|
||||
options = Object.assign({decodeEntities: false, _useHtmlParser2:true}, options);
|
||||
html = encodeEntities(html);
|
||||
return cheerio.load(html, options);
|
||||
};
|
||||
|
||||
var createEntityConverters = function () {
|
||||
var codeBlockLookup = [];
|
||||
|
||||
var encodeCodeBlocks = function(html) {
|
||||
var blocks = module.exports.codeBlocks;
|
||||
Object.keys(blocks).forEach(function(key) {
|
||||
var re = new RegExp(blocks[key].start + '([\\S\\s]*?)' + blocks[key].end, 'g');
|
||||
html = html.replace(re, function(match, subMatch) {
|
||||
codeBlockLookup.push(match);
|
||||
return 'JUICE_CODE_BLOCK_' + (codeBlockLookup.length - 1) + '_';
|
||||
});
|
||||
});
|
||||
return html;
|
||||
};
|
||||
|
||||
var decodeCodeBlocks = function(html) {
|
||||
for(var index = 0; index < codeBlockLookup.length; index++) {
|
||||
var re = new RegExp('JUICE_CODE_BLOCK_' + index + '_(="")?', 'gi');
|
||||
html = html.replace(re, function() {
|
||||
return codeBlockLookup[index];
|
||||
});
|
||||
}
|
||||
return html;
|
||||
};
|
||||
|
||||
return {
|
||||
encodeEntities: encodeCodeBlocks,
|
||||
decodeEntities: decodeCodeBlocks,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses the input, calls the callback on the parsed DOM, and generates the output
|
||||
*
|
||||
* @param {String} html input html to be processed
|
||||
* @param {Object} options for the parser
|
||||
* @param {Function} callback to be invoked on the DOM
|
||||
* @param {Array} callbackExtraArguments to be passed to the callback
|
||||
* @return {String} resulting html
|
||||
*/
|
||||
module.exports = function(html, options, callback, callbackExtraArguments) {
|
||||
var entityConverters = createEntityConverters();
|
||||
|
||||
var $ = cheerioLoad(html, options, entityConverters.encodeEntities);
|
||||
var args = [ $ ];
|
||||
args.push.apply(args, callbackExtraArguments);
|
||||
var doc = callback.apply(undefined, args) || $;
|
||||
|
||||
if (options && options.xmlMode) {
|
||||
return entityConverters.decodeEntities(doc.xml());
|
||||
}
|
||||
return entityConverters.decodeEntities(doc.html());
|
||||
};
|
||||
|
||||
module.exports.codeBlocks = {
|
||||
EJS: { start: '<%', end: '%>' },
|
||||
HBS: { start: '{{', end: '}}' }
|
||||
};
|
||||
138
book/node_modules/juice/lib/cli.js
generated
vendored
Normal file
138
book/node_modules/juice/lib/cli.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
'use strict';
|
||||
|
||||
var { program } = require('commander');
|
||||
var pkg = require('../package');
|
||||
|
||||
var cli = {};
|
||||
|
||||
module.exports = cli;
|
||||
|
||||
cli.getProgram = function() {
|
||||
program.name = pkg.name;
|
||||
|
||||
program.version(pkg.version)
|
||||
.usage('[options] input.html output.html');
|
||||
|
||||
Object.keys(cli.options).forEach(function(key) {
|
||||
program.option('--' + key + ' [value]', cli.options[key].def);
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
return program;
|
||||
};
|
||||
|
||||
cli.options = {
|
||||
'css': {
|
||||
pMap: 'css',
|
||||
map: 'cssFile',
|
||||
def: 'Add an extra CSS file by name' },
|
||||
'options-file': {
|
||||
pMap: 'optionsFile',
|
||||
def: 'Load options from a JSON file' },
|
||||
'extra-css': {
|
||||
pMap: 'extraCss',
|
||||
def: 'Add extra CSS' },
|
||||
'insert-preserved-extra-css': {
|
||||
pMap: 'insertPreservedExtraCss',
|
||||
def: 'insert preserved @font-face and @media into document?',
|
||||
coercion: JSON.parse },
|
||||
'apply-style-tags': {
|
||||
pMap: 'applyStyleTags',
|
||||
def: 'inline from style tags?',
|
||||
coercion: JSON.parse },
|
||||
'remove-style-tags': {
|
||||
pMap: 'removeStyleTags',
|
||||
def: 'remove style tags?',
|
||||
coercion: JSON.parse },
|
||||
'preserve-important': {
|
||||
pMap: 'preserveImportant',
|
||||
def: 'preserve important?',
|
||||
coercion: JSON.parse },
|
||||
'preserve-media-queries': {
|
||||
pMap: 'preserveMediaQueries',
|
||||
def: 'preserve media queries?',
|
||||
coercion: JSON.parse },
|
||||
'preserve-font-faces': {
|
||||
pMap: 'preserveFontFaces',
|
||||
def: 'preserve font faces?',
|
||||
coercion: JSON.parse },
|
||||
'preserve-key-frames': {
|
||||
pMap: 'preserveKeyFrames',
|
||||
def: 'preserve key frames?',
|
||||
coercion: JSON.parse },
|
||||
'preserve-pseudos': {
|
||||
pMap: 'preservePseudos',
|
||||
def: 'preserve pseudo selectors?',
|
||||
coercion: JSON.parse },
|
||||
'apply-width-attributes': {
|
||||
pMap: 'applyWidthAttributes',
|
||||
def: 'apply width attributes to relevent elements?',
|
||||
coercion: JSON.parse },
|
||||
'apply-height-attributes': {
|
||||
pMap: 'applyHeightAttributes',
|
||||
def: 'apply height attributes to relevent elements?',
|
||||
coercion: JSON.parse },
|
||||
'apply-attributes-table-elements': {
|
||||
pMap: 'applyAttributesTableElements',
|
||||
def: 'apply attributes with and equivalent CSS value to table elements?',
|
||||
coercion: JSON.parse },
|
||||
'xml-mode': {
|
||||
pMap: 'xmlMode',
|
||||
def: 'generate output with tags closed? input must be valid XML',
|
||||
coercion: JSON.parse },
|
||||
'web-resources-inline-attribute': {
|
||||
pMap: 'webResourcesInlineAttribute',
|
||||
map: 'inlineAttribute',
|
||||
def: 'see docs for web-resource-inliner inlineAttribute',
|
||||
coercion: JSON.parse },
|
||||
'web-resources-images': {
|
||||
pMap: 'webResourcesImages',
|
||||
map: 'images',
|
||||
def: 'see docs for web-resource-inliner images',
|
||||
coercion: JSON.parse },
|
||||
'web-resources-links': {
|
||||
pMap: 'webResourcesLinks',
|
||||
map: 'links',
|
||||
def: 'see docs for web-resource-inliner links',
|
||||
coercion: JSON.parse },
|
||||
'web-resources-scripts': {
|
||||
pMap: 'webResourcesScripts',
|
||||
map: 'scripts',
|
||||
def: 'see docs for web-resource-inliner scripts',
|
||||
coercion: JSON.parse },
|
||||
'web-resources-relative-to': {
|
||||
pMap: 'webResourcesRelativeTo',
|
||||
map: 'relativeTo',
|
||||
def: 'see docs for web-resource-inliner relativeTo' },
|
||||
'web-resources-rebase-relative-to': {
|
||||
pMap: 'webResourcesRebaseRelativeTo',
|
||||
map: 'rebaseRelativeTo',
|
||||
def: 'see docs for web-resource-inliner rebaseRelativeTo' },
|
||||
'web-resources-strict': {
|
||||
pMap: 'webResourcesStrict',
|
||||
map: 'strict',
|
||||
def: 'see docs for web-resource-inliner strict',
|
||||
coercion: JSON.parse }
|
||||
};
|
||||
|
||||
cli.argsToOptions = function(program) {
|
||||
var result = { webResources: {} };
|
||||
Object.keys(cli.options).forEach(function(key) {
|
||||
var option = cli.options[key];
|
||||
var value = program[option.pMap];
|
||||
if (value !== undefined) {
|
||||
if (option.coercion) {
|
||||
value = option.coercion(value);
|
||||
}
|
||||
|
||||
if (option.pMap.match(/webResources/)) {
|
||||
result.webResources[option.map] = value;
|
||||
} else {
|
||||
result[option.map || option.pMap] = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
514
book/node_modules/juice/lib/inline.js
generated
vendored
Normal file
514
book/node_modules/juice/lib/inline.js
generated
vendored
Normal file
@@ -0,0 +1,514 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./utils');
|
||||
var numbers = require('./numbers');
|
||||
|
||||
module.exports = function makeJuiceClient(juiceClient) {
|
||||
|
||||
juiceClient.ignoredPseudos = ['hover', 'active', 'focus', 'visited', 'link'];
|
||||
juiceClient.widthElements = ['TABLE', 'TD', 'TH', 'IMG'];
|
||||
juiceClient.heightElements = ['TABLE', 'TD', 'TH', 'IMG'];
|
||||
juiceClient.tableElements = ['TABLE', 'TH', 'TR', 'TD', 'CAPTION', 'COLGROUP', 'COL', 'THEAD', 'TBODY', 'TFOOT'];
|
||||
juiceClient.nonVisualElements = [ 'HEAD', 'TITLE', 'BASE', 'LINK', 'STYLE', 'META', 'SCRIPT', 'NOSCRIPT' ];
|
||||
juiceClient.styleToAttribute = {
|
||||
'background-color': 'bgcolor',
|
||||
'background-image': 'background',
|
||||
'text-align': 'align',
|
||||
'vertical-align': 'valign'
|
||||
};
|
||||
juiceClient.excludedProperties = [];
|
||||
|
||||
juiceClient.juiceDocument = juiceDocument;
|
||||
juiceClient.inlineDocument = inlineDocument;
|
||||
|
||||
function inlineDocument($, css, options) {
|
||||
|
||||
options = options || {};
|
||||
var rules = utils.parseCSS(css);
|
||||
var editedElements = [];
|
||||
var styleAttributeName = 'style';
|
||||
var counters = {};
|
||||
|
||||
if (options.styleAttributeName) {
|
||||
styleAttributeName = options.styleAttributeName;
|
||||
}
|
||||
|
||||
rules.forEach(handleRule);
|
||||
editedElements.forEach(setStyleAttrs);
|
||||
|
||||
if (options.inlinePseudoElements) {
|
||||
editedElements.forEach(inlinePseudoElements);
|
||||
}
|
||||
|
||||
if (options.applyWidthAttributes) {
|
||||
editedElements.forEach(function(el) {
|
||||
setDimensionAttrs(el, 'width');
|
||||
});
|
||||
}
|
||||
|
||||
if (options.applyHeightAttributes) {
|
||||
editedElements.forEach(function(el) {
|
||||
setDimensionAttrs(el, 'height');
|
||||
});
|
||||
}
|
||||
|
||||
if (options.applyAttributesTableElements) {
|
||||
editedElements.forEach(setAttributesOnTableElements);
|
||||
}
|
||||
|
||||
if (options.insertPreservedExtraCss && options.extraCss) {
|
||||
var preservedText = utils.getPreservedText(options.extraCss, {
|
||||
mediaQueries: options.preserveMediaQueries,
|
||||
fontFaces: options.preserveFontFaces,
|
||||
keyFrames: options.preserveKeyFrames
|
||||
});
|
||||
if (preservedText) {
|
||||
var $appendTo = null;
|
||||
if (options.insertPreservedExtraCss !== true) {
|
||||
$appendTo = $(options.insertPreservedExtraCss);
|
||||
} else {
|
||||
$appendTo = $('head');
|
||||
if (!$appendTo.length) { $appendTo = $('body'); }
|
||||
if (!$appendTo.length) { $appendTo = $.root(); }
|
||||
}
|
||||
|
||||
$appendTo.first().append('<style>' + preservedText + '</style>');
|
||||
}
|
||||
}
|
||||
|
||||
function handleRule(rule) {
|
||||
var sel = rule[0];
|
||||
var style = rule[1];
|
||||
var selector = new utils.Selector(sel);
|
||||
var parsedSelector = selector.parsed();
|
||||
|
||||
if (!parsedSelector) {
|
||||
return;
|
||||
}
|
||||
|
||||
var pseudoElementType = getPseudoElementType(parsedSelector);
|
||||
|
||||
// skip rule if the selector has any pseudos which are ignored
|
||||
for (var i = 0; i < parsedSelector.length; ++i) {
|
||||
var subSel = parsedSelector[i];
|
||||
if (subSel.pseudos) {
|
||||
for (var j = 0; j < subSel.pseudos.length; ++j) {
|
||||
var subSelPseudo = subSel.pseudos[j];
|
||||
if (juiceClient.ignoredPseudos.indexOf(subSelPseudo.name) >= 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pseudoElementType) {
|
||||
var last = parsedSelector[parsedSelector.length - 1];
|
||||
var pseudos = last.pseudos;
|
||||
last.pseudos = filterElementPseudos(last.pseudos);
|
||||
sel = parsedSelector.toString();
|
||||
last.pseudos = pseudos;
|
||||
}
|
||||
|
||||
var els;
|
||||
try {
|
||||
els = $(sel);
|
||||
} catch (err) {
|
||||
// skip invalid selector
|
||||
return;
|
||||
}
|
||||
|
||||
els.each(function() {
|
||||
var el = this;
|
||||
|
||||
if (el.name && juiceClient.nonVisualElements.indexOf(el.name.toUpperCase()) >= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pseudoElementType) {
|
||||
var pseudoElPropName = 'pseudo' + pseudoElementType;
|
||||
var pseudoEl = el[pseudoElPropName];
|
||||
if (!pseudoEl) {
|
||||
pseudoEl = el[pseudoElPropName] = $('<span />').get(0);
|
||||
pseudoEl.pseudoElementType = pseudoElementType;
|
||||
pseudoEl.pseudoElementParent = el;
|
||||
pseudoEl.counterProps = el.counterProps;
|
||||
el[pseudoElPropName] = pseudoEl;
|
||||
}
|
||||
el = pseudoEl;
|
||||
}
|
||||
|
||||
if (!el.styleProps) {
|
||||
el.styleProps = {};
|
||||
|
||||
// if the element has inline styles, fake selector with topmost specificity
|
||||
if ($(el).attr(styleAttributeName)) {
|
||||
var cssText = '* { ' + $(el).attr(styleAttributeName) + ' } ';
|
||||
addProps(utils.parseCSS(cssText)[0][1], new utils.Selector('<style>', true));
|
||||
}
|
||||
|
||||
// store reference to an element we need to compile style="" attr for
|
||||
editedElements.push(el);
|
||||
}
|
||||
|
||||
if (!el.counterProps) {
|
||||
el.counterProps = el.parent && el.parent.counterProps
|
||||
? Object.create(el.parent.counterProps)
|
||||
: {};
|
||||
}
|
||||
|
||||
function resetCounter(el, value) {
|
||||
var tokens = value.split(/\s+/);
|
||||
|
||||
for (var j = 0; j < tokens.length; j++) {
|
||||
var counter = tokens[j];
|
||||
var resetval = parseInt(tokens[j+1], 10);
|
||||
|
||||
isNaN(resetval)
|
||||
? el.counterProps[counter] = counters[counter] = 0
|
||||
: el.counterProps[counter] = counters[tokens[j++]] = resetval;
|
||||
}
|
||||
}
|
||||
|
||||
function incrementCounter(el, value) {
|
||||
var tokens = value.split(/\s+/);
|
||||
|
||||
for (var j = 0; j < tokens.length; j++) {
|
||||
var counter = tokens[j];
|
||||
|
||||
if (el.counterProps[counter] === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var incrval = parseInt(tokens[j+1], 10);
|
||||
|
||||
isNaN(incrval)
|
||||
? el.counterProps[counter] = counters[counter] += 1
|
||||
: el.counterProps[counter] = counters[tokens[j++]] += incrval;
|
||||
}
|
||||
}
|
||||
|
||||
// go through the properties
|
||||
function addProps(style, selector) {
|
||||
for (var i = 0, l = style.length; i < l; i++) {
|
||||
if (style[i].type == 'property') {
|
||||
var name = style[i].name;
|
||||
var value = style[i].value;
|
||||
|
||||
if (name === 'counter-reset') {
|
||||
resetCounter(el, value);
|
||||
}
|
||||
|
||||
if (name === 'counter-increment') {
|
||||
incrementCounter(el, value);
|
||||
}
|
||||
|
||||
var important = value.match(/!important$/) !== null;
|
||||
if (important && !options.preserveImportant) value = removeImportant(value);
|
||||
// adds line number and column number for the properties as "additionalPriority" to the
|
||||
// properties because in CSS the position directly affect the priority.
|
||||
var additionalPriority = [style[i].position.start.line, style[i].position.start.col];
|
||||
var prop = new utils.Property(name, value, selector, important ? 2 : 0, additionalPriority);
|
||||
var existing = el.styleProps[name];
|
||||
|
||||
// if property name is not in the excluded properties array
|
||||
if (juiceClient.excludedProperties.indexOf(name) < 0) {
|
||||
if (existing && existing.compare(prop) === prop || !existing) {
|
||||
// deleting a property let us change the order (move it to the end in the setStyleAttrs loop)
|
||||
if (existing && existing.selector !== selector) {
|
||||
delete el.styleProps[name];
|
||||
} else if (existing) {
|
||||
// make "prop" a special composed property.
|
||||
prop.nextProp = existing;
|
||||
}
|
||||
|
||||
el.styleProps[name] = prop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addProps(style, selector);
|
||||
});
|
||||
}
|
||||
|
||||
function setStyleAttrs(el) {
|
||||
var l = Object.keys(el.styleProps).length;
|
||||
var props = [];
|
||||
// Here we loop each property and make sure to "expand"
|
||||
// linked "nextProp" properties happening when the same property
|
||||
// is declared multiple times in the same selector.
|
||||
Object.keys(el.styleProps).forEach(function(key) {
|
||||
var np = el.styleProps[key];
|
||||
while (typeof np !== 'undefined') {
|
||||
props.push(np);
|
||||
np = np.nextProp;
|
||||
}
|
||||
});
|
||||
// sort properties by their originating selector's specificity so that
|
||||
// props like "padding" and "padding-bottom" are resolved as expected.
|
||||
props.sort(function(a, b) {
|
||||
return a.compareFunc(b);
|
||||
});
|
||||
var string = props
|
||||
.filter(function(prop) {
|
||||
// Content becomes the innerHTML of pseudo elements, not used as a
|
||||
// style property
|
||||
return prop.prop !== 'content';
|
||||
})
|
||||
.map(function(prop) {
|
||||
return prop.prop + ': ' + prop.value.replace(/["]/g, '\'') + ';';
|
||||
})
|
||||
.join(' ');
|
||||
if (string) {
|
||||
$(el).attr(styleAttributeName, string);
|
||||
}
|
||||
}
|
||||
|
||||
function inlinePseudoElements(el) {
|
||||
if (el.pseudoElementType && el.styleProps.content) {
|
||||
var parsed = parseContent(el);
|
||||
if (parsed.img) {
|
||||
el.name = 'img';
|
||||
$(el).attr('src', parsed.img);
|
||||
} else {
|
||||
$(el).text(parsed);
|
||||
}
|
||||
var parent = el.pseudoElementParent;
|
||||
if (el.pseudoElementType === 'before') {
|
||||
$(parent).prepend(el);
|
||||
} else {
|
||||
$(parent).append(el);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setDimensionAttrs(el, dimension) {
|
||||
if (!el.name) { return; }
|
||||
var elName = el.name.toUpperCase();
|
||||
if (juiceClient[dimension + 'Elements'].indexOf(elName) > -1) {
|
||||
for (var i in el.styleProps) {
|
||||
if (el.styleProps[i].prop === dimension) {
|
||||
var value = el.styleProps[i].value;
|
||||
if (options.preserveImportant) {
|
||||
value = removeImportant(value);
|
||||
}
|
||||
if (value.match(/px/)) {
|
||||
var pxSize = value.replace('px', '');
|
||||
$(el).attr(dimension, pxSize);
|
||||
return;
|
||||
}
|
||||
if (juiceClient.tableElements.indexOf(elName) > -1 && value.match(/\%/)) {
|
||||
$(el).attr(dimension, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function extractBackgroundUrl(value) {
|
||||
return value.indexOf('url(') !== 0
|
||||
? value
|
||||
: value.replace(/^url\((["'])?([^"']+)\1\)$/, '$2');
|
||||
}
|
||||
|
||||
function setAttributesOnTableElements(el) {
|
||||
if (!el.name) { return; }
|
||||
var elName = el.name.toUpperCase();
|
||||
var styleProps = Object.keys(juiceClient.styleToAttribute);
|
||||
|
||||
if (juiceClient.tableElements.indexOf(elName) > -1) {
|
||||
for (var i in el.styleProps) {
|
||||
if (styleProps.indexOf(el.styleProps[i].prop) > -1) {
|
||||
var prop = juiceClient.styleToAttribute[el.styleProps[i].prop];
|
||||
var value = el.styleProps[i].value;
|
||||
if (options.preserveImportant) {
|
||||
value = removeImportant(value);
|
||||
}
|
||||
if (prop === 'background') {
|
||||
value = extractBackgroundUrl(value);
|
||||
}
|
||||
if (/(linear|radial)-gradient\(/i.test(value)) {
|
||||
continue;
|
||||
}
|
||||
$(el).attr(prop, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeImportant(value) {
|
||||
return value.replace(/\s*!important$/, '')
|
||||
}
|
||||
|
||||
function findVariableValue(el, variable) {
|
||||
while (el) {
|
||||
if (variable in el.styleProps) {
|
||||
return el.styleProps[variable].value;
|
||||
}
|
||||
|
||||
var el = el.pseudoElementParent || el.parent;
|
||||
}
|
||||
}
|
||||
|
||||
function applyCounterStyle(counter, style) {
|
||||
switch (style) {
|
||||
case 'lower-roman':
|
||||
return numbers.romanize(counter).toLowerCase();
|
||||
case 'upper-roman':
|
||||
return numbers.romanize(counter);
|
||||
case 'lower-latin':
|
||||
case 'lower-alpha':
|
||||
return numbers.alphanumeric(counter).toLowerCase();
|
||||
case 'upper-latin':
|
||||
case 'upper-alpha':
|
||||
return numbers.alphanumeric(counter);
|
||||
// TODO support more counter styles
|
||||
default:
|
||||
return counter.toString();
|
||||
}
|
||||
}
|
||||
|
||||
function parseContent(el) {
|
||||
var content = el.styleProps.content.value;
|
||||
|
||||
if (content === 'none' || content === 'normal') {
|
||||
return '';
|
||||
}
|
||||
|
||||
var imageUrlMatch = content.match(/^\s*url\s*\(\s*(.*?)\s*\)\s*$/i);
|
||||
if (imageUrlMatch) {
|
||||
var url = imageUrlMatch[1].replace(/^['"]|['"]$/g, '');
|
||||
return { img: url };
|
||||
}
|
||||
|
||||
var parsed = [];
|
||||
|
||||
var tokens = content.split(/['"]/);
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
if (tokens[i] === '') continue;
|
||||
|
||||
var varMatch = tokens[i].match(/var\s*\(\s*(.*?)\s*(,\s*(.*?)\s*)?\s*\)/i);
|
||||
if (varMatch) {
|
||||
var variable = findVariableValue(el, varMatch[1]) || varMatch[2];
|
||||
parsed.push(variable.replace(/^['"]|['"]$/g, ''));
|
||||
continue;
|
||||
}
|
||||
|
||||
var counterMatch = tokens[i].match(/counter\s*\(\s*(.*?)\s*(,\s*(.*?)\s*)?\s*\)/i);
|
||||
if (counterMatch && counterMatch[1] in el.counterProps) {
|
||||
var counter = el.counterProps[counterMatch[1]];
|
||||
parsed.push(applyCounterStyle(counter, counterMatch[3]));
|
||||
continue;
|
||||
}
|
||||
|
||||
var attrMatch = tokens[i].match(/attr\s*\(\s*(.*?)\s*\)/i);
|
||||
if (attrMatch) {
|
||||
var attr = attrMatch[1];
|
||||
parsed.push(el.pseudoElementParent
|
||||
? el.pseudoElementParent.attribs[attr]
|
||||
: el.attribs[attr]
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
parsed.push(tokens[i]);
|
||||
}
|
||||
|
||||
content = parsed.join('');
|
||||
// Naive unescape, assume no unicode char codes
|
||||
content = content.replace(/\\/g, '');
|
||||
return content;
|
||||
}
|
||||
|
||||
// Return "before" or "after" if the given selector is a pseudo element (e.g.,
|
||||
// a::after).
|
||||
function getPseudoElementType(selector) {
|
||||
if (selector.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var pseudos = selector[selector.length - 1].pseudos;
|
||||
if (!pseudos) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < pseudos.length; i++) {
|
||||
if (isPseudoElementName(pseudos[i])) {
|
||||
return pseudos[i].name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isPseudoElementName(pseudo) {
|
||||
return pseudo.name === 'before' || pseudo.name === 'after';
|
||||
}
|
||||
|
||||
function filterElementPseudos(pseudos) {
|
||||
return pseudos.filter(function(pseudo) {
|
||||
return !isPseudoElementName(pseudo);
|
||||
});
|
||||
}
|
||||
|
||||
function juiceDocument($, options) {
|
||||
options = utils.getDefaultOptions(options);
|
||||
var css = extractCssFromDocument($, options);
|
||||
css += '\n' + options.extraCss;
|
||||
inlineDocument($, css, options);
|
||||
return $;
|
||||
}
|
||||
|
||||
function getStylesData($, options) {
|
||||
var results = [];
|
||||
var stylesList = $('style');
|
||||
var styleDataList, styleData, styleElement;
|
||||
stylesList.each(function() {
|
||||
styleElement = this;
|
||||
// the API for Cheerio using parse5 (default) and htmlparser2 are slightly different
|
||||
// detect this by checking if .childNodes exist (as opposed to .children)
|
||||
var usingParse5 = !!styleElement.childNodes;
|
||||
styleDataList = usingParse5 ? styleElement.childNodes : styleElement.children;
|
||||
if (styleDataList.length !== 1) {
|
||||
if (options.removeStyleTags) {
|
||||
$(styleElement).remove();
|
||||
}
|
||||
return;
|
||||
}
|
||||
styleData = styleDataList[0].data;
|
||||
if (options.applyStyleTags && $(styleElement).attr('data-embed') === undefined) {
|
||||
results.push(styleData);
|
||||
}
|
||||
if (options.removeStyleTags && $(styleElement).attr('data-embed') === undefined) {
|
||||
var text = usingParse5 ? styleElement.childNodes[0].nodeValue : styleElement.children[0].data;
|
||||
var preservedText = utils.getPreservedText(text, {
|
||||
mediaQueries: options.preserveMediaQueries,
|
||||
fontFaces: options.preserveFontFaces,
|
||||
keyFrames: options.preserveKeyFrames,
|
||||
pseudos: options.preservePseudos
|
||||
}, juiceClient.ignoredPseudos);
|
||||
if (preservedText) {
|
||||
if (usingParse5) {
|
||||
styleElement.childNodes[0].nodeValue = preservedText;
|
||||
} else {
|
||||
styleElement.children[0].data = preservedText;
|
||||
}
|
||||
} else {
|
||||
$(styleElement).remove();
|
||||
}
|
||||
}
|
||||
$(styleElement).removeAttr('data-embed');
|
||||
});
|
||||
return results;
|
||||
}
|
||||
|
||||
function extractCssFromDocument($, options) {
|
||||
var results = getStylesData($, options);
|
||||
var css = results.join('\n');
|
||||
return css;
|
||||
}
|
||||
|
||||
return juiceClient;
|
||||
|
||||
};
|
||||
40
book/node_modules/juice/lib/numbers.js
generated
vendored
Normal file
40
book/node_modules/juice/lib/numbers.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Converts a decimal number to roman numeral.
|
||||
* https://stackoverflow.com/questions/9083037/convert-a-number-into-a-roman-numeral-in-javascript
|
||||
*
|
||||
* @param {Number} number
|
||||
* @api private.
|
||||
*/
|
||||
exports.romanize = function(num) {
|
||||
if (isNaN(num))
|
||||
return NaN;
|
||||
var digits = String(+num).split(""),
|
||||
key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
|
||||
"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
|
||||
"","I","II","III","IV","V","VI","VII","VIII","IX"],
|
||||
roman = "",
|
||||
i = 3;
|
||||
while (i--)
|
||||
roman = (key[+digits.pop() + (i * 10)] || "") + roman;
|
||||
return Array(+digits.join("") + 1).join("M") + roman;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a decimal number to alphanumeric numeral.
|
||||
* https://stackoverflow.com/questions/45787459/convert-number-to-alphabet-string-javascript
|
||||
*
|
||||
* @param {Number} number
|
||||
* @api private.
|
||||
*/
|
||||
exports.alphanumeric = function(num) {
|
||||
var s = '', t;
|
||||
|
||||
while (num > 0) {
|
||||
t = (num - 1) % 26;
|
||||
s = String.fromCharCode(65 + t) + s;
|
||||
num = (num - t)/26 | 0;
|
||||
}
|
||||
return s || undefined;
|
||||
}
|
||||
65
book/node_modules/juice/lib/property.js
generated
vendored
Normal file
65
book/node_modules/juice/lib/property.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = Property;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var utils = require('./utils');
|
||||
|
||||
/**
|
||||
* CSS property constructor.
|
||||
*
|
||||
* @param {String} property
|
||||
* @param {String} value
|
||||
* @param {Selector} selector the property originates from
|
||||
* @param {Integer} priority 0 for normal properties, 2 for !important properties.
|
||||
* @param {Array} additional array of integers representing more detailed priorities (sorting)
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Property(prop, value, selector, priority, additionalPriority) {
|
||||
this.prop = prop;
|
||||
this.value = value;
|
||||
this.selector = selector;
|
||||
this.priority = priority || 0;
|
||||
this.additionalPriority = additionalPriority || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares with another Property based on Selector#specificity.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Property.prototype.compareFunc = function(property) {
|
||||
var a = [];
|
||||
a.push.apply(a, this.selector.specificity());
|
||||
a.push.apply(a, this.additionalPriority);
|
||||
a[0] += this.priority;
|
||||
var b = [];
|
||||
b.push.apply(b, property.selector.specificity());
|
||||
b.push.apply(b, property.additionalPriority);
|
||||
b[0] += property.priority;
|
||||
return utils.compareFunc(a, b);
|
||||
};
|
||||
|
||||
Property.prototype.compare = function(property) {
|
||||
var winner = this.compareFunc(property);
|
||||
if (winner === 1) {
|
||||
return this;
|
||||
}
|
||||
return property;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns CSS property
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Property.prototype.toString = function() {
|
||||
return this.prop + ': ' + this.value.replace(/['"]+/g, '') + ';';
|
||||
};
|
||||
97
book/node_modules/juice/lib/selector.js
generated
vendored
Normal file
97
book/node_modules/juice/lib/selector.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
|
||||
var parser = require('slick/parser');
|
||||
|
||||
module.exports = exports = Selector;
|
||||
|
||||
/**
|
||||
* CSS selector constructor.
|
||||
*
|
||||
* @param {String} selector text
|
||||
* @param {Array} optionally, precalculated specificity
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Selector(text, styleAttribute) {
|
||||
this.text = text;
|
||||
this.spec = undefined;
|
||||
this.styleAttribute = styleAttribute || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parsed selector.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Selector.prototype.parsed = function() {
|
||||
if (!this.tokens) { this.tokens = parse(this.text); }
|
||||
return this.tokens;
|
||||
};
|
||||
|
||||
/**
|
||||
* Lazy specificity getter
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Selector.prototype.specificity = function() {
|
||||
var styleAttribute = this.styleAttribute;
|
||||
if (!this.spec) { this.spec = specificity(this.text, this.parsed()); }
|
||||
return this.spec;
|
||||
|
||||
function specificity(text, parsed) {
|
||||
var expressions = parsed || parse(text);
|
||||
var spec = [styleAttribute ? 1 : 0, 0, 0, 0];
|
||||
var nots = [];
|
||||
|
||||
for (var i = 0; i < expressions.length; i++) {
|
||||
var expression = expressions[i];
|
||||
var pseudos = expression.pseudos;
|
||||
|
||||
// id awards a point in the second column
|
||||
if (expression.id) { spec[1]++; }
|
||||
|
||||
// classes and attributes award a point each in the third column
|
||||
if (expression.attributes) { spec[2] += expression.attributes.length; }
|
||||
if (expression.classList) { spec[2] += expression.classList.length; }
|
||||
|
||||
// tag awards a point in the fourth column
|
||||
if (expression.tag && expression.tag !== '*') { spec[3]++; }
|
||||
|
||||
// pseudos award a point each in the fourth column
|
||||
if (pseudos) {
|
||||
spec[3] += pseudos.length;
|
||||
|
||||
for (var p = 0; p < pseudos.length; p++) {
|
||||
if (pseudos[p].name === 'not') {
|
||||
nots.push(pseudos[p].value);
|
||||
spec[3]--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var ii = nots.length; ii--;) {
|
||||
var not = specificity(nots[ii]);
|
||||
for (var jj = 4; jj--;) { spec[jj] += not[jj]; }
|
||||
}
|
||||
|
||||
return spec;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses a selector and returns the tokens.
|
||||
*
|
||||
* @param {String} selector
|
||||
* @api private.
|
||||
*/
|
||||
|
||||
function parse(text) {
|
||||
try {
|
||||
return parser(text)[0];
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
167
book/node_modules/juice/lib/utils.js
generated
vendored
Normal file
167
book/node_modules/juice/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var mensch = require('mensch');
|
||||
var Selector = require('./selector');
|
||||
var Property = require('./property');
|
||||
|
||||
exports.Selector = Selector;
|
||||
exports.Property = Property;
|
||||
|
||||
/**
|
||||
* Returns an array of the selectors.
|
||||
*
|
||||
* @license Sizzle CSS Selector Engine - MIT
|
||||
* @param {String} selectorText from mensch
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.extract = function extract(selectorText) {
|
||||
var attr = 0;
|
||||
var sels = [];
|
||||
var sel = '';
|
||||
|
||||
for (var i = 0, l = selectorText.length; i < l; i++) {
|
||||
var c = selectorText.charAt(i);
|
||||
|
||||
if (attr) {
|
||||
if (']' === c || ')' === c) { attr--; }
|
||||
sel += c;
|
||||
} else {
|
||||
if (',' === c) {
|
||||
sels.push(sel);
|
||||
sel = '';
|
||||
} else {
|
||||
if ('[' === c || '(' === c) { attr++; }
|
||||
if (sel.length || (c !== ',' && c !== '\n' && c !== ' ')) { sel += c; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sel.length) {
|
||||
sels.push(sel);
|
||||
}
|
||||
|
||||
return sels;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a parse tree for a CSS source.
|
||||
* If it encounters multiple selectors separated by a comma, it splits the
|
||||
* tree.
|
||||
*
|
||||
* @param {String} css source
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.parseCSS = function(css) {
|
||||
var parsed = mensch.parse(css, {position: true, comments: true});
|
||||
var rules = typeof parsed.stylesheet != 'undefined' && parsed.stylesheet.rules ? parsed.stylesheet.rules : [];
|
||||
var ret = [];
|
||||
|
||||
for (var i = 0, l = rules.length; i < l; i++) {
|
||||
if (rules[i].type == 'rule') {
|
||||
var rule = rules[i];
|
||||
var selectors = rule.selectors;
|
||||
|
||||
for (var ii = 0, ll = selectors.length; ii < ll; ii++) {
|
||||
ret.push([selectors[ii], rule.declarations]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns preserved text for a CSS source.
|
||||
*
|
||||
* @param {String} css source
|
||||
* @param {Object} options
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.getPreservedText = function(css, options, ignoredPseudos) {
|
||||
var parsed = mensch.parse(css, {position: true, comments: true});
|
||||
var rules = typeof parsed.stylesheet != 'undefined' && parsed.stylesheet.rules ? parsed.stylesheet.rules : [];
|
||||
var preserved = [];
|
||||
var lastStart = null;
|
||||
|
||||
for (var i = rules.length - 1; i >= 0; i--) {
|
||||
if ((options.fontFaces && rules[i].type === 'font-face') ||
|
||||
(options.mediaQueries && rules[i].type === 'media') ||
|
||||
(options.keyFrames && rules[i].type === 'keyframes') ||
|
||||
(options.pseudos && rules[i].selectors && this.matchesPseudo(rules[i].selectors[0], ignoredPseudos))) {
|
||||
preserved.unshift(
|
||||
mensch.stringify(
|
||||
{ stylesheet: { rules: [ rules[i] ] }},
|
||||
{ comments: false, indentation: ' ' }
|
||||
)
|
||||
);
|
||||
}
|
||||
lastStart = rules[i].position.start;
|
||||
}
|
||||
|
||||
if (preserved.length === 0) {
|
||||
return false;
|
||||
}
|
||||
return '\n' + preserved.join('\n') + '\n';
|
||||
};
|
||||
|
||||
exports.normalizeLineEndings = function(text) {
|
||||
return text.replace(/\r\n/g, '\n').replace(/\n/g, '\r\n');
|
||||
};
|
||||
|
||||
exports.matchesPseudo = function(needle, haystack) {
|
||||
return haystack.find(function (element) {
|
||||
return needle.indexOf(element) > -1;
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two specificity vectors, returning the winning one.
|
||||
*
|
||||
* @param {Array} vector a
|
||||
* @param {Array} vector b
|
||||
* @return {Array}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.compareFunc = function(a, b) {
|
||||
var min = Math.min(a.length, b.length);
|
||||
for (var i = 0; i < min; i++) {
|
||||
if (a[i] === b[i]) { continue; }
|
||||
if (a[i] > b[i]) { return 1; }
|
||||
return -1;
|
||||
}
|
||||
|
||||
return a.length - b.length;
|
||||
};
|
||||
|
||||
exports.compare = function(a, b) {
|
||||
return exports.compareFunc(a, b) == 1 ? a : b;
|
||||
};
|
||||
|
||||
exports.getDefaultOptions = function(options) {
|
||||
var result = Object.assign({
|
||||
extraCss: '',
|
||||
insertPreservedExtraCss: true,
|
||||
applyStyleTags: true,
|
||||
removeStyleTags: true,
|
||||
preserveMediaQueries: true,
|
||||
preserveFontFaces: true,
|
||||
preserveKeyFrames: true,
|
||||
preservePseudos: true,
|
||||
applyWidthAttributes: true,
|
||||
applyHeightAttributes: true,
|
||||
applyAttributesTableElements: true,
|
||||
url: ''
|
||||
}, options);
|
||||
|
||||
result.webResources = result.webResources || {};
|
||||
|
||||
return result;
|
||||
};
|
||||
11
book/node_modules/juice/node_modules/cheerio-select/LICENSE
generated
vendored
Normal file
11
book/node_modules/juice/node_modules/cheerio-select/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
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.
|
||||
18
book/node_modules/juice/node_modules/cheerio-select/README.md
generated
vendored
Normal file
18
book/node_modules/juice/node_modules/cheerio-select/README.md
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# cheerio-select [](https://npmjs.org/package/cheerio-select) [](http://travis-ci.org/cheeriojs/cheerio-select) [](https://npmjs.org/package/cheerio-select) [](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.
|
||||
5
book/node_modules/juice/node_modules/cheerio-select/lib/helpers.d.ts
generated
vendored
Normal file
5
book/node_modules/juice/node_modules/cheerio-select/lib/helpers.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { Node } from "domhandler";
|
||||
import type { Selector } from "css-what";
|
||||
export declare function getDocumentRoot(node: Node): Node;
|
||||
export declare function groupSelectors(selectors: Selector[][]): [plain: Selector[][], filtered: Selector[][]];
|
||||
//# sourceMappingURL=helpers.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/cheerio-select/lib/helpers.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio-select/lib/helpers.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAGhD;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"}
|
||||
25
book/node_modules/juice/node_modules/cheerio-select/lib/helpers.js
generated
vendored
Normal file
25
book/node_modules/juice/node_modules/cheerio-select/lib/helpers.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
"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;
|
||||
12
book/node_modules/juice/node_modules/cheerio-select/lib/index.d.ts
generated
vendored
Normal file
12
book/node_modules/juice/node_modules/cheerio-select/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Options as CSSSelectOptions } from "css-select";
|
||||
import type { Element, Node, Document } from "domhandler";
|
||||
export { filters, pseudos, aliases } from "css-select";
|
||||
export interface Options extends CSSSelectOptions<Node, Element> {
|
||||
/** Optional reference to the root of the document. If not set, this will be computed when needed. */
|
||||
root?: Document;
|
||||
}
|
||||
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: Node[], options?: Options): Element[];
|
||||
export declare function select(selector: string | ((el: Element) => boolean), root: Node | Node[], options?: Options): Element[];
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/cheerio-select/lib/index.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio-select/lib/index.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAEH,OAAO,IAAI,gBAAgB,EAE9B,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAK1D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAevD,MAAM,WAAW,OAAQ,SAAQ,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC;IAC5D,qGAAqG;IACrG,IAAI,CAAC,EAAE,QAAQ,CAAC;CACnB;AAED,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,CAET;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,IAAI,EAAE,EAChB,OAAO,GAAE,OAAY,GACtB,OAAO,EAAE,CAEX;AA6FD,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,CA2BX"}
|
||||
313
book/node_modules/juice/node_modules/cheerio-select/lib/index.js
generated
vendored
Normal file
313
book/node_modules/juice/node_modules/cheerio-select/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,313 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (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;
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.select = exports.filter = exports.some = exports.is = exports.aliases = exports.pseudos = exports.filters = void 0;
|
||||
var css_what_1 = require("css-what");
|
||||
var css_select_1 = require("css-select");
|
||||
var DomUtils = __importStar(require("domutils"));
|
||||
var helpers_1 = require("./helpers");
|
||||
var positionals_1 = require("./positionals");
|
||||
// Re-export pseudo extension points
|
||||
var css_select_2 = require("css-select");
|
||||
Object.defineProperty(exports, "filters", { enumerable: true, get: function () { return css_select_2.filters; } });
|
||||
Object.defineProperty(exports, "pseudos", { enumerable: true, get: function () { return css_select_2.pseudos; } });
|
||||
Object.defineProperty(exports, "aliases", { enumerable: true, get: function () { return css_select_2.aliases; } });
|
||||
/** Used to indicate a scope should be filtered. Might be ignored when filtering. */
|
||||
var SCOPE_PSEUDO = {
|
||||
type: css_what_1.SelectorType.Pseudo,
|
||||
name: "scope",
|
||||
data: null,
|
||||
};
|
||||
/** Used for actually filtering for scope. */
|
||||
var CUSTOM_SCOPE_PSEUDO = __assign({}, SCOPE_PSEUDO);
|
||||
var UNIVERSAL_SELECTOR = {
|
||||
type: css_what_1.SelectorType.Universal,
|
||||
namespace: null,
|
||||
};
|
||||
function is(element, selector, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return some([element], selector, options);
|
||||
}
|
||||
exports.is = is;
|
||||
function some(elements, selector, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
if (typeof selector === "function")
|
||||
return elements.some(selector);
|
||||
var _a = (0, helpers_1.groupSelectors)((0, css_what_1.parse)(selector)), plain = _a[0], filtered = _a[1];
|
||||
return ((plain.length > 0 && elements.some((0, css_select_1._compileToken)(plain, options))) ||
|
||||
filtered.some(function (sel) { return filterBySelector(sel, elements, options).length > 0; }));
|
||||
}
|
||||
exports.some = some;
|
||||
function filterByPosition(filter, elems, data, options) {
|
||||
var num = typeof data === "string" ? parseInt(data, 10) : NaN;
|
||||
switch (filter) {
|
||||
case "first":
|
||||
case "lt":
|
||||
// Already done in `getLimit`
|
||||
return elems;
|
||||
case "last":
|
||||
return elems.length > 0 ? [elems[elems.length - 1]] : elems;
|
||||
case "nth":
|
||||
case "eq":
|
||||
return isFinite(num) && Math.abs(num) < elems.length
|
||||
? [num < 0 ? elems[elems.length + num] : elems[num]]
|
||||
: [];
|
||||
case "gt":
|
||||
return isFinite(num) ? elems.slice(num + 1) : [];
|
||||
case "even":
|
||||
return elems.filter(function (_, i) { return i % 2 === 0; });
|
||||
case "odd":
|
||||
return elems.filter(function (_, i) { return i % 2 === 1; });
|
||||
case "not": {
|
||||
var filtered_1 = new Set(filterParsed(data, elems, options));
|
||||
return elems.filter(function (e) { return !filtered_1.has(e); });
|
||||
}
|
||||
}
|
||||
}
|
||||
function filter(selector, elements, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return filterParsed((0, css_what_1.parse)(selector), elements, options);
|
||||
}
|
||||
exports.filter = filter;
|
||||
/**
|
||||
* Filter a set of elements by a selector.
|
||||
*
|
||||
* Will return elements in the original order.
|
||||
*
|
||||
* @param selector Selector to filter by.
|
||||
* @param elements Elements to filter.
|
||||
* @param options Options for selector.
|
||||
*/
|
||||
function filterParsed(selector, elements, options) {
|
||||
if (elements.length === 0)
|
||||
return [];
|
||||
var _a = (0, helpers_1.groupSelectors)(selector), plainSelectors = _a[0], filteredSelectors = _a[1];
|
||||
var found;
|
||||
if (plainSelectors.length) {
|
||||
var filtered = filterElements(elements, plainSelectors, options);
|
||||
// If there are no filters, just return
|
||||
if (filteredSelectors.length === 0) {
|
||||
return filtered;
|
||||
}
|
||||
// Otherwise, we have to do some filtering
|
||||
if (filtered.length) {
|
||||
found = new Set(filtered);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < filteredSelectors.length && (found === null || found === void 0 ? void 0 : found.size) !== elements.length; i++) {
|
||||
var filteredSelector = filteredSelectors[i];
|
||||
var missing = found
|
||||
? elements.filter(function (e) { return DomUtils.isTag(e) && !found.has(e); })
|
||||
: elements;
|
||||
if (missing.length === 0)
|
||||
break;
|
||||
var filtered = filterBySelector(filteredSelector, elements, options);
|
||||
if (filtered.length) {
|
||||
if (!found) {
|
||||
/*
|
||||
* If we haven't found anything before the last selector,
|
||||
* just return what we found now.
|
||||
*/
|
||||
if (i === filteredSelectors.length - 1) {
|
||||
return filtered;
|
||||
}
|
||||
found = new Set(filtered);
|
||||
}
|
||||
else {
|
||||
filtered.forEach(function (el) { return found.add(el); });
|
||||
}
|
||||
}
|
||||
}
|
||||
return typeof found !== "undefined"
|
||||
? (found.size === elements.length
|
||||
? elements
|
||||
: // Filter elements to preserve order
|
||||
elements.filter(function (el) {
|
||||
return found.has(el);
|
||||
}))
|
||||
: [];
|
||||
}
|
||||
function filterBySelector(selector, elements, options) {
|
||||
var _a;
|
||||
if (selector.some(css_what_1.isTraversal)) {
|
||||
/*
|
||||
* Get root node, run selector with the scope
|
||||
* set to all of our nodes.
|
||||
*/
|
||||
var root = (_a = options.root) !== null && _a !== void 0 ? _a : (0, helpers_1.getDocumentRoot)(elements[0]);
|
||||
var sel = __spreadArray(__spreadArray([], selector, true), [CUSTOM_SCOPE_PSEUDO], false);
|
||||
return findFilterElements(root, sel, options, true, elements);
|
||||
}
|
||||
// Performance optimization: If we don't have to traverse, just filter set.
|
||||
return findFilterElements(elements, selector, options, false);
|
||||
}
|
||||
function select(selector, root, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
if (typeof selector === "function") {
|
||||
return find(root, selector);
|
||||
}
|
||||
var _a = (0, helpers_1.groupSelectors)((0, css_what_1.parse)(selector)), plain = _a[0], filtered = _a[1];
|
||||
var results = filtered.map(function (sel) {
|
||||
return findFilterElements(root, sel, options, true);
|
||||
});
|
||||
// Plain selectors can be queried in a single go
|
||||
if (plain.length) {
|
||||
results.push(findElements(root, plain, options, Infinity));
|
||||
}
|
||||
if (results.length === 0) {
|
||||
return [];
|
||||
}
|
||||
// If there was only a single selector, just return the result
|
||||
if (results.length === 1) {
|
||||
return results[0];
|
||||
}
|
||||
// Sort results, filtering for duplicates
|
||||
return DomUtils.uniqueSort(results.reduce(function (a, b) { return __spreadArray(__spreadArray([], a, true), b, true); }));
|
||||
}
|
||||
exports.select = select;
|
||||
// Traversals that are treated differently in css-select.
|
||||
var specialTraversal = new Set([
|
||||
css_what_1.SelectorType.Descendant,
|
||||
css_what_1.SelectorType.Adjacent,
|
||||
]);
|
||||
function includesScopePseudo(t) {
|
||||
return (t !== SCOPE_PSEUDO &&
|
||||
t.type === "pseudo" &&
|
||||
(t.name === "scope" ||
|
||||
(Array.isArray(t.data) &&
|
||||
t.data.some(function (data) { return data.some(includesScopePseudo); }))));
|
||||
}
|
||||
function addContextIfScope(selector, options, scopeContext) {
|
||||
return scopeContext && selector.some(includesScopePseudo)
|
||||
? __assign(__assign({}, options), { context: scopeContext }) : options;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param root Element(s) to search from.
|
||||
* @param selector Selector to look for.
|
||||
* @param options Options for querying.
|
||||
* @param queryForSelector Query multiple levels deep for the initial selector, even if it doesn't contain a traversal.
|
||||
* @param scopeContext Optional context for a :scope.
|
||||
*/
|
||||
function findFilterElements(root, selector, options, queryForSelector, scopeContext) {
|
||||
var filterIndex = selector.findIndex(positionals_1.isFilter);
|
||||
var sub = selector.slice(0, filterIndex);
|
||||
var filter = selector[filterIndex];
|
||||
/*
|
||||
* Set the number of elements to retrieve.
|
||||
* Eg. for :first, we only have to get a single element.
|
||||
*/
|
||||
var limit = (0, positionals_1.getLimit)(filter.name, filter.data);
|
||||
if (limit === 0)
|
||||
return [];
|
||||
var subOpts = addContextIfScope(sub, options, scopeContext);
|
||||
/*
|
||||
* Skip `findElements` call if our selector starts with a positional
|
||||
* pseudo.
|
||||
*/
|
||||
var elemsNoLimit = sub.length === 0 && !Array.isArray(root)
|
||||
? DomUtils.getChildren(root).filter(DomUtils.isTag)
|
||||
: sub.length === 0 || (sub.length === 1 && sub[0] === SCOPE_PSEUDO)
|
||||
? (Array.isArray(root) ? root : [root]).filter(DomUtils.isTag)
|
||||
: queryForSelector || sub.some(css_what_1.isTraversal)
|
||||
? findElements(root, [sub], subOpts, limit)
|
||||
: filterElements(root, [sub], subOpts);
|
||||
var elems = elemsNoLimit.slice(0, limit);
|
||||
var result = filterByPosition(filter.name, elems, filter.data, options);
|
||||
if (result.length === 0 || selector.length === filterIndex + 1) {
|
||||
return result;
|
||||
}
|
||||
var remainingSelector = selector.slice(filterIndex + 1);
|
||||
var remainingHasTraversal = remainingSelector.some(css_what_1.isTraversal);
|
||||
var remainingOpts = addContextIfScope(remainingSelector, options, scopeContext);
|
||||
if (remainingHasTraversal) {
|
||||
/*
|
||||
* Some types of traversals have special logic when they start a selector
|
||||
* in css-select. If this is the case, add a universal selector in front of
|
||||
* the selector to avoid this behavior.
|
||||
*/
|
||||
if (specialTraversal.has(remainingSelector[0].type)) {
|
||||
remainingSelector.unshift(UNIVERSAL_SELECTOR);
|
||||
}
|
||||
/*
|
||||
* Add a scope token in front of the remaining selector,
|
||||
* to make sure traversals don't match elements that aren't a
|
||||
* part of the considered tree.
|
||||
*/
|
||||
remainingSelector.unshift(SCOPE_PSEUDO);
|
||||
}
|
||||
/*
|
||||
* If we have another filter, recursively call `findFilterElements`,
|
||||
* with the `recursive` flag disabled. We only have to look for more
|
||||
* elements when we see a traversal.
|
||||
*
|
||||
* Otherwise,
|
||||
*/
|
||||
return remainingSelector.some(positionals_1.isFilter)
|
||||
? findFilterElements(result, remainingSelector, options, false, scopeContext)
|
||||
: remainingHasTraversal
|
||||
? // Query existing elements to resolve traversal.
|
||||
findElements(result, [remainingSelector], remainingOpts, Infinity)
|
||||
: // If we don't have any more traversals, simply filter elements.
|
||||
filterElements(result, [remainingSelector], remainingOpts);
|
||||
}
|
||||
function findElements(root, sel, options, limit) {
|
||||
if (limit === 0)
|
||||
return [];
|
||||
var query = (0, css_select_1._compileToken)(sel, options, root);
|
||||
return find(root, query, limit);
|
||||
}
|
||||
function find(root, query, limit) {
|
||||
if (limit === void 0) { limit = Infinity; }
|
||||
var elems = (0, css_select_1.prepareContext)(root, DomUtils, query.shouldTestNextSiblings);
|
||||
return DomUtils.find(function (node) { return DomUtils.isTag(node) && query(node); }, elems, true, limit);
|
||||
}
|
||||
function filterElements(elements, sel, options) {
|
||||
var els = (Array.isArray(elements) ? elements : [elements]).filter(DomUtils.isTag);
|
||||
if (els.length === 0)
|
||||
return els;
|
||||
var query = (0, css_select_1._compileToken)(sel, options);
|
||||
return els.filter(query);
|
||||
}
|
||||
10
book/node_modules/juice/node_modules/cheerio-select/lib/positionals.d.ts
generated
vendored
Normal file
10
book/node_modules/juice/node_modules/cheerio-select/lib/positionals.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
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
|
||||
1
book/node_modules/juice/node_modules/cheerio-select/lib/positionals.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio-select/lib/positionals.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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"}
|
||||
42
book/node_modules/juice/node_modules/cheerio-select/lib/positionals.js
generated
vendored
Normal file
42
book/node_modules/juice/node_modules/cheerio-select/lib/positionals.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"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;
|
||||
63
book/node_modules/juice/node_modules/cheerio-select/package.json
generated
vendored
Normal file
63
book/node_modules/juice/node_modules/cheerio-select/package.json
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"name": "cheerio-select",
|
||||
"description": "CSS selector engine supporting jQuery selectors",
|
||||
"version": "1.6.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": "npm run test:jest && npm run lint",
|
||||
"test:jest": "jest",
|
||||
"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.3.0",
|
||||
"css-what": "^6.0.1",
|
||||
"domelementtype": "^2.2.0",
|
||||
"domhandler": "^4.3.1",
|
||||
"domutils": "^2.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/node": "^17.0.23",
|
||||
"@typescript-eslint/eslint-plugin": "^5.16.0",
|
||||
"@typescript-eslint/parser": "^5.16.0",
|
||||
"eslint": "^8.12.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"htmlparser2": "^7.2.0",
|
||||
"jest": "^27.5.1",
|
||||
"prettier": "^2.6.1",
|
||||
"ts-jest": "^27.1.3",
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"jest": {
|
||||
"preset": "ts-jest",
|
||||
"testEnvironment": "node"
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 4
|
||||
}
|
||||
}
|
||||
21
book/node_modules/juice/node_modules/cheerio/LICENSE
generated
vendored
Normal file
21
book/node_modules/juice/node_modules/cheerio/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
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.
|
||||
319
book/node_modules/juice/node_modules/cheerio/Readme.md
generated
vendored
Normal file
319
book/node_modules/juice/node_modules/cheerio/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,319 @@
|
||||
<h1 align="center">cheerio</h1>
|
||||
|
||||
<h5 align="center">Fast, flexible & lean implementation of core jQuery designed specifically for the server.</h5>
|
||||
|
||||
<div align="center">
|
||||
<a href="https://github.com/cheeriojs/cheerio/actions?query=workflow%3ACI+branch%3Amain">
|
||||
<img src="https://img.shields.io/github/workflow/status/cheeriojs/cheerio/CI/main" alt="Build Status">
|
||||
</a>
|
||||
<a href="https://coveralls.io/github/cheeriojs/cheerio">
|
||||
<img src="https://img.shields.io/coveralls/github/cheeriojs/cheerio/main" alt="Coverage">
|
||||
</a>
|
||||
<a href="#backers">
|
||||
<img src="https://img.shields.io/opencollective/backers/cheerio" alt="OpenCollective backers">
|
||||
</a>
|
||||
<a href="#sponsors">
|
||||
<img src="https://img.shields.io/opencollective/sponsors/cheerio" alt="OpenCollective sponsors">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
[中文文档 (Chinese Readme)](https://github.com/cheeriojs/cheerio/wiki/Chinese-README)
|
||||
|
||||
```js
|
||||
const cheerio = require('cheerio');
|
||||
const $ = cheerio.load('<h2 class="title">Hello world</h2>');
|
||||
|
||||
$('h2.title').text('Hello there!');
|
||||
$('h2').addClass('welcome');
|
||||
|
||||
$.html();
|
||||
//=> <html><head></head><body><h2 class="title welcome">Hello there!</h2></body></html>
|
||||
```
|
||||
|
||||
## Note
|
||||
|
||||
We are currently working on the 1.0.0 release of cheerio on the `main` branch. The source code for the last published version, `0.22.0`, can be found [here](https://github.com/cheeriojs/cheerio/tree/aa90399c9c02f12432bfff97b8f1c7d8ece7c307).
|
||||
|
||||
## Installation
|
||||
|
||||
`npm install cheerio`
|
||||
|
||||
## Features
|
||||
|
||||
**❤ Familiar syntax:**
|
||||
Cheerio implements a subset of core jQuery. Cheerio removes all the DOM inconsistencies and browser cruft from the jQuery library, revealing its truly gorgeous API.
|
||||
|
||||
**ϟ Blazingly fast:**
|
||||
Cheerio works with a very simple, consistent DOM model. As a result parsing, manipulating, and rendering are incredibly efficient.
|
||||
|
||||
**❁ Incredibly flexible:**
|
||||
Cheerio wraps around [parse5](https://github.com/inikulin/parse5) parser and can optionally use @FB55's forgiving [htmlparser2](https://github.com/fb55/htmlparser2/). Cheerio can parse nearly any HTML or XML document.
|
||||
|
||||
## Cheerio is not a web browser
|
||||
|
||||
Cheerio parses markup and provides an API for traversing/manipulating the resulting data structure. It does not interpret the result as a web browser does. Specifically, it does _not_ produce a visual rendering, apply CSS, load external resources, or execute JavaScript. This makes Cheerio **much, much faster than other solutions**. If your use case requires any of this functionality, you should consider projects like [Puppeteer](https://github.com/puppeteer/puppeteer) or [JSDom](https://github.com/jsdom/jsdom).
|
||||
|
||||
## API
|
||||
|
||||
### Markup example we'll be using:
|
||||
|
||||
```html
|
||||
<ul id="fruits">
|
||||
<li class="apple">Apple</li>
|
||||
<li class="orange">Orange</li>
|
||||
<li class="pear">Pear</li>
|
||||
</ul>
|
||||
```
|
||||
|
||||
This is the HTML markup we will be using in all of the API examples.
|
||||
|
||||
### Loading
|
||||
|
||||
First you need to load in the HTML. This step in jQuery is implicit, since jQuery operates on the one, baked-in DOM. With Cheerio, we need to pass in the HTML document.
|
||||
|
||||
This is the _preferred_ method:
|
||||
|
||||
```js
|
||||
// ES6 or TypeScript:
|
||||
import * as cheerio from 'cheerio';
|
||||
|
||||
// In other environments:
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const $ = cheerio.load('<ul id="fruits">...</ul>');
|
||||
|
||||
$.html();
|
||||
//=> <html><head></head><body><ul id="fruits">...</ul></body></html>
|
||||
```
|
||||
|
||||
Similar to web browser contexts, `load` will introduce `<html>`, `<head>`, and `<body>` elements if they are not already present. You can set `load`'s third argument to `false` to disable this.
|
||||
|
||||
```js
|
||||
const $ = cheerio.load('<ul id="fruits">...</ul>', null, false);
|
||||
|
||||
$.html();
|
||||
//=> '<ul id="fruits">...</ul>'
|
||||
```
|
||||
|
||||
Optionally, you can also load in the HTML by passing the string as the context:
|
||||
|
||||
```js
|
||||
$('ul', '<ul id="fruits">...</ul>');
|
||||
```
|
||||
|
||||
Or as the root:
|
||||
|
||||
```js
|
||||
$('li', 'ul', '<ul id="fruits">...</ul>');
|
||||
```
|
||||
|
||||
If you need to modify parsing options for XML input, you may pass an extra
|
||||
object to `.load()`:
|
||||
|
||||
```js
|
||||
const $ = cheerio.load('<ul id="fruits">...</ul>', {
|
||||
xml: {
|
||||
normalizeWhitespace: true,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
The options in the `xml` object are taken directly from [htmlparser2](https://github.com/fb55/htmlparser2/wiki/Parser-options), therefore any options that can be used in `htmlparser2` are valid in cheerio as well. When `xml` is set, the default options are:
|
||||
|
||||
```js
|
||||
{
|
||||
xmlMode: true,
|
||||
decodeEntities: true, // Decode HTML entities.
|
||||
withStartIndices: false, // Add a `startIndex` property to nodes.
|
||||
withEndIndices: false, // Add an `endIndex` property to nodes.
|
||||
}
|
||||
```
|
||||
|
||||
For a full list of options and their effects, see [domhandler](https://github.com/fb55/DomHandler) and
|
||||
[htmlparser2's options](https://github.com/fb55/htmlparser2/wiki/Parser-options).
|
||||
|
||||
Some users may wish to parse markup with the `htmlparser2` library, and
|
||||
traverse/manipulate the resulting structure with Cheerio. This may be the case
|
||||
for those upgrading from pre-1.0 releases of Cheerio (which relied on
|
||||
`htmlparser2`), for those dealing with invalid markup (because `htmlparser2` is
|
||||
more forgiving), or for those operating in performance-critical situations
|
||||
(because `htmlparser2` may be faster in some cases). Note that "more forgiving"
|
||||
means `htmlparser2` has error-correcting mechanisms that aren't always a match
|
||||
for the standards observed by web browsers. This behavior may be useful when
|
||||
parsing non-HTML content.
|
||||
|
||||
To support these cases, `load` also accepts a `htmlparser2`-compatible data
|
||||
structure as its first argument. Users may install `htmlparser2`, use it to
|
||||
parse input, and pass the result to `load`:
|
||||
|
||||
```js
|
||||
// Usage as of htmlparser2 version 6:
|
||||
const htmlparser2 = require('htmlparser2');
|
||||
const dom = htmlparser2.parseDocument(document, options);
|
||||
|
||||
const $ = cheerio.load(dom);
|
||||
```
|
||||
|
||||
### Selectors
|
||||
|
||||
Cheerio's selector implementation is nearly identical to jQuery's, so the API is very similar.
|
||||
|
||||
#### \$( selector, [context], [root] )
|
||||
|
||||
`selector` searches within the `context` scope which searches within the `root` scope. `selector` and `context` can be a string expression, DOM Element, array of DOM elements, or cheerio object. `root` is typically the HTML document string.
|
||||
|
||||
This selector method is the starting point for traversing and manipulating the document. Like jQuery, it's the primary method for selecting elements in the document.
|
||||
|
||||
```js
|
||||
$('.apple', '#fruits').text();
|
||||
//=> Apple
|
||||
|
||||
$('ul .pear').attr('class');
|
||||
//=> pear
|
||||
|
||||
$('li[class=orange]').html();
|
||||
//=> Orange
|
||||
```
|
||||
|
||||
##### XML Namespaces
|
||||
|
||||
You can select with XML Namespaces but [due to the CSS specification](https://www.w3.org/TR/2011/REC-css3-selectors-20110929/#attribute-selectors), the colon (`:`) needs to be escaped for the selector to be valid.
|
||||
|
||||
```js
|
||||
$('[xml\\:id="main"');
|
||||
```
|
||||
|
||||
### Rendering
|
||||
|
||||
When you're ready to render the document, you can call the `html` method on the "root" selection:
|
||||
|
||||
```js
|
||||
$.root().html();
|
||||
//=> <html>
|
||||
// <head></head>
|
||||
// <body>
|
||||
// <ul id="fruits">
|
||||
// <li class="apple">Apple</li>
|
||||
// <li class="orange">Orange</li>
|
||||
// <li class="pear">Pear</li>
|
||||
// </ul>
|
||||
// </body>
|
||||
// </html>
|
||||
```
|
||||
|
||||
If you want to render the [`outerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/outerHTML) of a selection, you can use the `html` utility functon:
|
||||
|
||||
```js
|
||||
cheerio.html($('.pear'));
|
||||
//=> <li class="pear">Pear</li>
|
||||
```
|
||||
|
||||
By default, `html` will leave some tags open. Sometimes you may instead want to render a valid XML document. For example, you might parse the following XML snippet:
|
||||
|
||||
```js
|
||||
const $ = cheerio.load(
|
||||
'<media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123"/>'
|
||||
);
|
||||
```
|
||||
|
||||
... and later want to render to XML. To do this, you can use the 'xml' utility function:
|
||||
|
||||
```js
|
||||
$.xml();
|
||||
//=> <media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123"/>
|
||||
```
|
||||
|
||||
You may also render the text content of a Cheerio object using the `text` static method:
|
||||
|
||||
```js
|
||||
const $ = cheerio.load('This is <em>content</em>.');
|
||||
cheerio.text($('body'));
|
||||
//=> This is content.
|
||||
```
|
||||
|
||||
### Plugins
|
||||
|
||||
Once you have loaded a document, you may extend the prototype or the equivalent `fn` property with custom plugin methods:
|
||||
|
||||
```js
|
||||
const $ = cheerio.load('<html><body>Hello, <b>world</b>!</body></html>');
|
||||
$.prototype.logHtml = function () {
|
||||
console.log(this.html());
|
||||
};
|
||||
|
||||
$('body').logHtml(); // logs "Hello, <b>world</b>!" to the console
|
||||
```
|
||||
|
||||
If you're using TypeScript, you should also add a type definition for your new method:
|
||||
|
||||
```ts
|
||||
declare module 'cheerio' {
|
||||
interface Cheerio<T> {
|
||||
logHtml(this: Cheerio<T>): void;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### The "DOM Node" object
|
||||
|
||||
Cheerio collections are made up of objects that bear some resemblance to [browser-based DOM nodes](https://developer.mozilla.org/en-US/docs/Web/API/Node). You can expect them to define the following properties:
|
||||
|
||||
- `tagName`
|
||||
- `parentNode`
|
||||
- `previousSibling`
|
||||
- `nextSibling`
|
||||
- `nodeValue`
|
||||
- `firstChild`
|
||||
- `childNodes`
|
||||
- `lastChild`
|
||||
|
||||
## Screencasts
|
||||
|
||||
[https://vimeo.com/31950192](https://vimeo.com/31950192)
|
||||
|
||||
> This video tutorial is a follow-up to Nettut's "How to Scrape Web Pages with Node.js and jQuery", using cheerio instead of JSDOM + jQuery. This video shows how easy it is to use cheerio and how much faster cheerio is than JSDOM + jQuery.
|
||||
|
||||
## Cheerio in the real world
|
||||
|
||||
Are you using cheerio in production? Add it to the [wiki](https://github.com/cheeriojs/cheerio/wiki/Cheerio-in-Production)!
|
||||
|
||||
## Sponsors
|
||||
|
||||
Does your company use Cheerio in production? Please consider [sponsoring this project](https://github.com/cheeriojs/cheerio?sponsor=1)! Your help will allow maintainers to dedicate more time and resources to its development and support.
|
||||
|
||||
<!-- BEGIN SPONSORS: sponsor -->
|
||||
|
||||
<a href="https://substack.com/" target="_blank"></a>
|
||||
<a href="https://www.airbnb.com/" target="_blank"></a>
|
||||
|
||||
<!-- END SPONSORS -->
|
||||
|
||||
## Backers
|
||||
|
||||
[Become a backer](https://github.com/cheeriojs/cheerio?sponsor=1) to show your support for Cheerio and help us maintain and improve this open source project.
|
||||
|
||||
<!-- BEGIN SPONSORS: backer -->
|
||||
|
||||
<a href="https://medium.com/norch" target="_blank"></a>
|
||||
<a href="https://nishant-singh.com" target="_blank"></a>
|
||||
|
||||
<!-- END SPONSORS -->
|
||||
|
||||
## Special Thanks
|
||||
|
||||
This library stands on the shoulders of some incredible developers. A special thanks to:
|
||||
|
||||
**• @FB55 for node-htmlparser2 & CSSSelect:**
|
||||
Felix has a knack for writing speedy parsing engines. He completely re-wrote both @tautologistic's `node-htmlparser` and @harry's `node-soupselect` from the ground up, making both of them much faster and more flexible. Cheerio would not be possible without his foundational work
|
||||
|
||||
**• @jQuery team for jQuery:**
|
||||
The core API is the best of its class and despite dealing with all the browser inconsistencies the code base is extremely clean and easy to follow. Much of cheerio's implementation and documentation is from jQuery. Thanks guys.
|
||||
|
||||
**• @visionmedia:**
|
||||
The style, the structure, the open-source"-ness" of this library comes from studying TJ's style and using many of his libraries. This dude consistently pumps out high-quality libraries and has always been more than willing to help or answer questions. You rock TJ.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
317
book/node_modules/juice/node_modules/cheerio/lib/api/attributes.d.ts
generated
vendored
Normal file
317
book/node_modules/juice/node_modules/cheerio/lib/api/attributes.d.ts
generated
vendored
Normal file
@@ -0,0 +1,317 @@
|
||||
/**
|
||||
* Methods for getting and modifying attributes.
|
||||
*
|
||||
* @module cheerio/attributes
|
||||
*/
|
||||
import type { Node, Element } from 'domhandler';
|
||||
import type { Cheerio } from '../cheerio';
|
||||
/**
|
||||
* Method for getting attributes. Gets the attribute value for only the first
|
||||
* element in the matched set.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('ul').attr('id');
|
||||
* //=> fruits
|
||||
* ```
|
||||
*
|
||||
* @param name - Name of the attribute.
|
||||
* @returns The attribute's value.
|
||||
* @see {@link https://api.jquery.com/attr/}
|
||||
*/
|
||||
export declare function attr<T extends Node>(this: Cheerio<T>, name: string): string | undefined;
|
||||
/**
|
||||
* Method for getting all attributes and their values of the first element in
|
||||
* the matched set.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('ul').attr();
|
||||
* //=> { id: 'fruits' }
|
||||
* ```
|
||||
*
|
||||
* @returns The attribute's values.
|
||||
* @see {@link https://api.jquery.com/attr/}
|
||||
*/
|
||||
export declare function attr<T extends Node>(this: Cheerio<T>): Record<string, string>;
|
||||
/**
|
||||
* Method for setting attributes. Sets the attribute value for only the first
|
||||
* element in the matched set. If you set an attribute's value to `null`, you
|
||||
* remove that attribute. You may also pass a `map` and `function`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').attr('id', 'favorite').html();
|
||||
* //=> <li class="apple" id="favorite">Apple</li>
|
||||
* ```
|
||||
*
|
||||
* @param name - Name of the attribute.
|
||||
* @param value - The new value of the attribute.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/attr/}
|
||||
*/
|
||||
export declare function attr<T extends Node>(this: Cheerio<T>, name: string, value?: string | null | ((this: Element, i: number, attrib: string) => string | null)): Cheerio<T>;
|
||||
/**
|
||||
* Method for setting multiple attributes at once. Sets the attribute value for
|
||||
* only the first element in the matched set. If you set an attribute's value to
|
||||
* `null`, you remove that attribute.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').attr({ id: 'favorite' }).html();
|
||||
* //=> <li class="apple" id="favorite">Apple</li>
|
||||
* ```
|
||||
*
|
||||
* @param values - Map of attribute names and values.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/attr/}
|
||||
*/
|
||||
export declare function attr<T extends Node>(this: Cheerio<T>, values: Record<string, string | null>): Cheerio<T>;
|
||||
interface StyleProp {
|
||||
length: number;
|
||||
[key: string]: string | number;
|
||||
[index: number]: string;
|
||||
}
|
||||
/**
|
||||
* Method for getting and setting properties. Gets the property value for only
|
||||
* the first element in the matched set.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('input[type="checkbox"]').prop('checked');
|
||||
* //=> false
|
||||
*
|
||||
* $('input[type="checkbox"]').prop('checked', true).val();
|
||||
* //=> ok
|
||||
* ```
|
||||
*
|
||||
* @param name - Name of the property.
|
||||
* @param value - If specified set the property to this.
|
||||
* @returns If `value` is specified the instance itself, otherwise the prop's value.
|
||||
* @see {@link https://api.jquery.com/prop/}
|
||||
*/
|
||||
export declare function prop<T extends Node>(this: Cheerio<T>, name: 'tagName' | 'nodeName'): T extends Element ? string : undefined;
|
||||
export declare function prop<T extends Node>(this: Cheerio<T>, name: 'innerHTML' | 'outerHTML'): string | null;
|
||||
export declare function prop<T extends Node>(this: Cheerio<T>, name: 'style'): StyleProp;
|
||||
export declare function prop<T extends Node, K extends keyof Element>(this: Cheerio<T>, name: K): Element[K];
|
||||
export declare function prop<T extends Node, K extends keyof Element>(this: Cheerio<T>, name: K, value: Element[K] | ((this: Element, i: number, prop: K) => Element[keyof Element])): Cheerio<T>;
|
||||
export declare function prop<T extends Node>(this: Cheerio<T>, name: Record<string, string | Element[keyof Element] | boolean>): Cheerio<T>;
|
||||
export declare function prop<T extends Node>(this: Cheerio<T>, name: string, value: string | boolean | null | ((this: Element, i: number, prop: string) => string | boolean)): Cheerio<T>;
|
||||
export declare function prop<T extends Node>(this: Cheerio<T>, name: string): string;
|
||||
/**
|
||||
* Method for getting data attributes, for only the first element in the matched set.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('<div data-apple-color="red"></div>').data('apple-color');
|
||||
* //=> 'red'
|
||||
* ```
|
||||
*
|
||||
* @param name - Name of the data attribute.
|
||||
* @returns The data attribute's value.
|
||||
* @see {@link https://api.jquery.com/data/}
|
||||
*/
|
||||
export declare function data<T extends Node>(this: Cheerio<T>, name: string): unknown | undefined;
|
||||
/**
|
||||
* Method for getting all of an element's data attributes, for only the first
|
||||
* element in the matched set.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('<div data-apple-color="red"></div>').data();
|
||||
* //=> { appleColor: 'red' }
|
||||
* ```
|
||||
*
|
||||
* @returns The data attribute's values.
|
||||
* @see {@link https://api.jquery.com/data/}
|
||||
*/
|
||||
export declare function data<T extends Node>(this: Cheerio<T>): Record<string, unknown>;
|
||||
/**
|
||||
* Method for setting data attributes, for only the first element in the matched set.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const apple = $('.apple').data('kind', 'mac');
|
||||
*
|
||||
* apple.data('kind');
|
||||
* //=> 'mac'
|
||||
* ```
|
||||
*
|
||||
* @param name - Name of the data attribute.
|
||||
* @param value - The new value.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/data/}
|
||||
*/
|
||||
export declare function data<T extends Node>(this: Cheerio<T>, name: string, value: unknown): Cheerio<T>;
|
||||
/**
|
||||
* Method for setting multiple data attributes at once, for only the first
|
||||
* element in the matched set.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const apple = $('.apple').data({ kind: 'mac' });
|
||||
*
|
||||
* apple.data('kind');
|
||||
* //=> 'mac'
|
||||
* ```
|
||||
*
|
||||
* @param values - Map of names to values.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/data/}
|
||||
*/
|
||||
export declare function data<T extends Node>(this: Cheerio<T>, values: Record<string, unknown>): Cheerio<T>;
|
||||
/**
|
||||
* Method for getting the value of input, select, and textarea. Note: Support
|
||||
* for `map`, and `function` has not been added yet.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('input[type="text"]').val();
|
||||
* //=> input_text
|
||||
* ```
|
||||
*
|
||||
* @returns The value.
|
||||
* @see {@link https://api.jquery.com/val/}
|
||||
*/
|
||||
export declare function val<T extends Node>(this: Cheerio<T>): string | undefined | string[];
|
||||
/**
|
||||
* Method for setting the value of input, select, and textarea. Note: Support
|
||||
* for `map`, and `function` has not been added yet.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('input[type="text"]').val('test').html();
|
||||
* //=> <input type="text" value="test"/>
|
||||
* ```
|
||||
*
|
||||
* @param value - The new value.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/val/}
|
||||
*/
|
||||
export declare function val<T extends Node>(this: Cheerio<T>, value: string | string[]): Cheerio<T>;
|
||||
/**
|
||||
* Method for removing attributes by `name`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').removeAttr('class').html();
|
||||
* //=> <li>Pear</li>
|
||||
*
|
||||
* $('.apple').attr('id', 'favorite');
|
||||
* $('.apple').removeAttr('id class').html();
|
||||
* //=> <li>Apple</li>
|
||||
* ```
|
||||
*
|
||||
* @param name - Name of the attribute.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/removeAttr/}
|
||||
*/
|
||||
export declare function removeAttr<T extends Node>(this: Cheerio<T>, name: string): Cheerio<T>;
|
||||
/**
|
||||
* Check to see if *any* of the matched elements have the given `className`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').hasClass('pear');
|
||||
* //=> true
|
||||
*
|
||||
* $('apple').hasClass('fruit');
|
||||
* //=> false
|
||||
*
|
||||
* $('li').hasClass('pear');
|
||||
* //=> true
|
||||
* ```
|
||||
*
|
||||
* @param className - Name of the class.
|
||||
* @returns Indicates if an element has the given `className`.
|
||||
* @see {@link https://api.jquery.com/hasClass/}
|
||||
*/
|
||||
export declare function hasClass<T extends Node>(this: Cheerio<T>, className: string): boolean;
|
||||
/**
|
||||
* Adds class(es) to all of the matched elements. Also accepts a `function`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').addClass('fruit').html();
|
||||
* //=> <li class="pear fruit">Pear</li>
|
||||
*
|
||||
* $('.apple').addClass('fruit red').html();
|
||||
* //=> <li class="apple fruit red">Apple</li>
|
||||
* ```
|
||||
*
|
||||
* @param value - Name of new class.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/addClass/}
|
||||
*/
|
||||
export declare function addClass<T extends Node, R extends ArrayLike<T>>(this: R, value?: string | ((this: Element, i: number, className: string) => string | undefined)): R;
|
||||
/**
|
||||
* Removes one or more space-separated classes from the selected elements. If no
|
||||
* `className` is defined, all classes will be removed. Also accepts a `function`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').removeClass('pear').html();
|
||||
* //=> <li class="">Pear</li>
|
||||
*
|
||||
* $('.apple').addClass('red').removeClass().html();
|
||||
* //=> <li class="">Apple</li>
|
||||
* ```
|
||||
*
|
||||
* @param name - Name of the class. If not specified, removes all elements.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/removeClass/}
|
||||
*/
|
||||
export declare function removeClass<T extends Node, R extends ArrayLike<T>>(this: R, name?: string | ((this: Element, i: number, className: string) => string | undefined)): R;
|
||||
/**
|
||||
* Add or remove class(es) from the matched elements, depending on either the
|
||||
* class's presence or the value of the switch argument. Also accepts a `function`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple.green').toggleClass('fruit green red').html();
|
||||
* //=> <li class="apple fruit red">Apple</li>
|
||||
*
|
||||
* $('.apple.green').toggleClass('fruit green red', true).html();
|
||||
* //=> <li class="apple green fruit red">Apple</li>
|
||||
* ```
|
||||
*
|
||||
* @param value - Name of the class. Can also be a function.
|
||||
* @param stateVal - If specified the state of the class.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/toggleClass/}
|
||||
*/
|
||||
export declare function toggleClass<T extends Node, R extends ArrayLike<T>>(this: R, value?: string | ((this: Element, i: number, className: string, stateVal?: boolean) => string), stateVal?: boolean): R;
|
||||
export {};
|
||||
//# sourceMappingURL=attributes.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/api/attributes.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/api/attributes.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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,YAAY,CAAC;AA6F1C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAAC;AACtB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EACF,MAAM,GACN,IAAI,GACJ,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC,GAChE,OAAO,CAAC,CAAC,CAAC,CAAC;AACd;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GACpC,OAAO,CAAC,CAAC,CAAC,CAAC;AAqFd,UAAU,SAAS;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,SAAS,GAAG,UAAU,GAC3B,CAAC,SAAS,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAC1C,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,WAAW,GAAG,WAAW,GAC9B,MAAM,GAAG,IAAI,CAAC;AACjB,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,OAAO,GACZ,SAAS,CAAC;AACb,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,MAAM,OAAO,EAC1D,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,CAAC,GACN,OAAO,CAAC,CAAC,CAAC,CAAC;AACd,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,MAAM,OAAO,EAC1D,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,CAAC,EACP,KAAK,EACD,OAAO,CAAC,CAAC,CAAC,GACV,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,GAClE,OAAO,CAAC,CAAC,CAAC,CAAC;AACd,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,OAAO,CAAC,GAC9D,OAAO,CAAC,CAAC,CAAC,CAAC;AACd,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EACD,MAAM,GACN,OAAO,GACP,IAAI,GACJ,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,GACjE,OAAO,CAAC,CAAC,CAAC,CAAC;AACd,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;AA8J7E;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,GAAG,SAAS,CAAC;AACvB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAChF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,CAAC,CAAC,CAAC;AACd;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,CAAC,CAAC,CAAC;AAkCd;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GACf,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAAC;AACjC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GACvB,OAAO,CAAC,CAAC,CAAC,CAAC;AAoEd;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,IAAI,EACvC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,CAAC,CAUZ;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EACrC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAoBT;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAC7D,IAAI,EAAE,CAAC,EACP,KAAK,CAAC,EACF,MAAM,GACN,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GACxE,CAAC,CAyCH;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAChE,IAAI,EAAE,CAAC,EACP,IAAI,CAAC,EACD,MAAM,GACN,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GACxE,CAAC,CA0CH;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAChE,IAAI,EAAE,CAAC,EACP,KAAK,CAAC,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"}
|
||||
591
book/node_modules/juice/node_modules/cheerio/lib/api/attributes.js
generated
vendored
Normal file
591
book/node_modules/juice/node_modules/cheerio/lib/api/attributes.js
generated
vendored
Normal file
@@ -0,0 +1,591 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Methods for getting and modifying attributes.
|
||||
*
|
||||
* @module cheerio/attributes
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.toggleClass = exports.removeClass = exports.addClass = exports.hasClass = exports.removeAttr = exports.val = exports.data = exports.prop = exports.attr = void 0;
|
||||
var static_1 = require("../static");
|
||||
var utils_1 = require("../utils");
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
var rspace = /\s+/;
|
||||
var dataAttrPrefix = 'data-';
|
||||
/*
|
||||
* Lookup table for coercing string data-* attributes to their corresponding
|
||||
* JavaScript primitives
|
||||
*/
|
||||
var primitives = {
|
||||
null: null,
|
||||
true: true,
|
||||
false: false,
|
||||
};
|
||||
// Attributes that are booleans
|
||||
var rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i;
|
||||
// Matches strings that look like JSON objects or arrays
|
||||
var rbrace = /^{[^]*}$|^\[[^]*]$/;
|
||||
function getAttr(elem, name, xmlMode) {
|
||||
var _a;
|
||||
if (!elem || !utils_1.isTag(elem))
|
||||
return undefined;
|
||||
(_a = elem.attribs) !== null && _a !== void 0 ? _a : (elem.attribs = {});
|
||||
// Return the entire attribs object if no attribute specified
|
||||
if (!name) {
|
||||
return elem.attribs;
|
||||
}
|
||||
if (hasOwn.call(elem.attribs, name)) {
|
||||
// Get the (decoded) attribute
|
||||
return !xmlMode && rboolean.test(name) ? name : elem.attribs[name];
|
||||
}
|
||||
// Mimic the DOM and return text content as value for `option's`
|
||||
if (elem.name === 'option' && name === 'value') {
|
||||
return static_1.text(elem.children);
|
||||
}
|
||||
// Mimic DOM with default value for radios/checkboxes
|
||||
if (elem.name === 'input' &&
|
||||
(elem.attribs.type === 'radio' || elem.attribs.type === 'checkbox') &&
|
||||
name === 'value') {
|
||||
return 'on';
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Sets the value of an attribute. The attribute will be deleted if the value is `null`.
|
||||
*
|
||||
* @private
|
||||
* @param el - The element to set the attribute on.
|
||||
* @param name - The attribute's name.
|
||||
* @param value - The attribute's value.
|
||||
*/
|
||||
function setAttr(el, name, value) {
|
||||
if (value === null) {
|
||||
removeAttribute(el, name);
|
||||
}
|
||||
else {
|
||||
el.attribs[name] = "" + value;
|
||||
}
|
||||
}
|
||||
function attr(name, value) {
|
||||
// Set the value (with attr map support)
|
||||
if (typeof name === 'object' || value !== undefined) {
|
||||
if (typeof value === 'function') {
|
||||
if (typeof name !== 'string') {
|
||||
{
|
||||
throw new Error('Bad combination of arguments.');
|
||||
}
|
||||
}
|
||||
return utils_1.domEach(this, function (el, i) {
|
||||
if (utils_1.isTag(el))
|
||||
setAttr(el, name, value.call(el, i, el.attribs[name]));
|
||||
});
|
||||
}
|
||||
return utils_1.domEach(this, function (el) {
|
||||
if (!utils_1.isTag(el))
|
||||
return;
|
||||
if (typeof name === 'object') {
|
||||
Object.keys(name).forEach(function (objName) {
|
||||
var objValue = name[objName];
|
||||
setAttr(el, objName, objValue);
|
||||
});
|
||||
}
|
||||
else {
|
||||
setAttr(el, name, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
return arguments.length > 1
|
||||
? this
|
||||
: getAttr(this[0], name, this.options.xmlMode);
|
||||
}
|
||||
exports.attr = attr;
|
||||
/**
|
||||
* Gets a node's prop.
|
||||
*
|
||||
* @private
|
||||
* @category Attributes
|
||||
* @param el - Elenent to get the prop of.
|
||||
* @param name - Name of the prop.
|
||||
* @returns The prop's value.
|
||||
*/
|
||||
function getProp(el, name, xmlMode) {
|
||||
if (!el || !utils_1.isTag(el))
|
||||
return;
|
||||
return name in el
|
||||
? // @ts-expect-error TS doesn't like us accessing the value directly here.
|
||||
el[name]
|
||||
: !xmlMode && rboolean.test(name)
|
||||
? getAttr(el, name, false) !== undefined
|
||||
: getAttr(el, name, xmlMode);
|
||||
}
|
||||
/**
|
||||
* Sets the value of a prop.
|
||||
*
|
||||
* @private
|
||||
* @param el - The element to set the prop on.
|
||||
* @param name - The prop's name.
|
||||
* @param value - The prop's value.
|
||||
*/
|
||||
function setProp(el, name, value, xmlMode) {
|
||||
if (name in el) {
|
||||
// @ts-expect-error Overriding value
|
||||
el[name] = value;
|
||||
}
|
||||
else {
|
||||
setAttr(el, name, !xmlMode && rboolean.test(name) ? (value ? '' : null) : "" + value);
|
||||
}
|
||||
}
|
||||
function prop(name, value) {
|
||||
var _this = this;
|
||||
if (typeof name === 'string' && value === undefined) {
|
||||
switch (name) {
|
||||
case 'style': {
|
||||
var property_1 = this.css();
|
||||
var keys = Object.keys(property_1);
|
||||
keys.forEach(function (p, i) {
|
||||
property_1[i] = p;
|
||||
});
|
||||
property_1.length = keys.length;
|
||||
return property_1;
|
||||
}
|
||||
case 'tagName':
|
||||
case 'nodeName': {
|
||||
var el = this[0];
|
||||
return utils_1.isTag(el) ? el.name.toUpperCase() : undefined;
|
||||
}
|
||||
case 'outerHTML':
|
||||
return this.clone().wrap('<container />').parent().html();
|
||||
case 'innerHTML':
|
||||
return this.html();
|
||||
default:
|
||||
return getProp(this[0], name, this.options.xmlMode);
|
||||
}
|
||||
}
|
||||
if (typeof name === 'object' || value !== undefined) {
|
||||
if (typeof value === 'function') {
|
||||
if (typeof name === 'object') {
|
||||
throw new Error('Bad combination of arguments.');
|
||||
}
|
||||
return utils_1.domEach(this, function (el, i) {
|
||||
if (utils_1.isTag(el))
|
||||
setProp(el, name, value.call(el, i, getProp(el, name, _this.options.xmlMode)), _this.options.xmlMode);
|
||||
});
|
||||
}
|
||||
return utils_1.domEach(this, function (el) {
|
||||
if (!utils_1.isTag(el))
|
||||
return;
|
||||
if (typeof name === 'object') {
|
||||
Object.keys(name).forEach(function (key) {
|
||||
var val = name[key];
|
||||
setProp(el, key, val, _this.options.xmlMode);
|
||||
});
|
||||
}
|
||||
else {
|
||||
setProp(el, name, value, _this.options.xmlMode);
|
||||
}
|
||||
});
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
exports.prop = prop;
|
||||
/**
|
||||
* Sets the value of a data attribute.
|
||||
*
|
||||
* @private
|
||||
* @param el - The element to set the data attribute on.
|
||||
* @param name - The data attribute's name.
|
||||
* @param value - The data attribute's value.
|
||||
*/
|
||||
function setData(el, name, value) {
|
||||
var _a;
|
||||
var elem = el;
|
||||
(_a = elem.data) !== null && _a !== void 0 ? _a : (elem.data = {});
|
||||
if (typeof name === 'object')
|
||||
Object.assign(elem.data, name);
|
||||
else if (typeof name === 'string' && value !== undefined) {
|
||||
elem.data[name] = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Read the specified attribute from the equivalent HTML5 `data-*` attribute,
|
||||
* and (if present) cache the value in the node's internal data store. If no
|
||||
* attribute name is specified, read *all* HTML5 `data-*` attributes in this manner.
|
||||
*
|
||||
* @private
|
||||
* @category Attributes
|
||||
* @param el - Elenent to get the data attribute of.
|
||||
* @param name - Name of the data attribute.
|
||||
* @returns The data attribute's value, or a map with all of the data attribute.
|
||||
*/
|
||||
function readData(el, name) {
|
||||
var domNames;
|
||||
var jsNames;
|
||||
var value;
|
||||
if (name == null) {
|
||||
domNames = Object.keys(el.attribs).filter(function (attrName) {
|
||||
return attrName.startsWith(dataAttrPrefix);
|
||||
});
|
||||
jsNames = domNames.map(function (domName) {
|
||||
return utils_1.camelCase(domName.slice(dataAttrPrefix.length));
|
||||
});
|
||||
}
|
||||
else {
|
||||
domNames = [dataAttrPrefix + utils_1.cssCase(name)];
|
||||
jsNames = [name];
|
||||
}
|
||||
for (var idx = 0; idx < domNames.length; ++idx) {
|
||||
var domName = domNames[idx];
|
||||
var jsName = jsNames[idx];
|
||||
if (hasOwn.call(el.attribs, domName) &&
|
||||
!hasOwn.call(el.data, jsName)) {
|
||||
value = el.attribs[domName];
|
||||
if (hasOwn.call(primitives, value)) {
|
||||
value = primitives[value];
|
||||
}
|
||||
else if (value === String(Number(value))) {
|
||||
value = Number(value);
|
||||
}
|
||||
else if (rbrace.test(value)) {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
}
|
||||
catch (e) {
|
||||
/* Ignore */
|
||||
}
|
||||
}
|
||||
el.data[jsName] = value;
|
||||
}
|
||||
}
|
||||
return name == null ? el.data : value;
|
||||
}
|
||||
function data(name, value) {
|
||||
var _a;
|
||||
var elem = this[0];
|
||||
if (!elem || !utils_1.isTag(elem))
|
||||
return;
|
||||
var dataEl = elem;
|
||||
(_a = dataEl.data) !== null && _a !== void 0 ? _a : (dataEl.data = {});
|
||||
// Return the entire data object if no data specified
|
||||
if (!name) {
|
||||
return readData(dataEl);
|
||||
}
|
||||
// Set the value (with attr map support)
|
||||
if (typeof name === 'object' || value !== undefined) {
|
||||
utils_1.domEach(this, function (el) {
|
||||
if (utils_1.isTag(el))
|
||||
if (typeof name === 'object')
|
||||
setData(el, name);
|
||||
else
|
||||
setData(el, name, value);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
if (hasOwn.call(dataEl.data, name)) {
|
||||
return dataEl.data[name];
|
||||
}
|
||||
return readData(dataEl, name);
|
||||
}
|
||||
exports.data = data;
|
||||
function val(value) {
|
||||
var querying = arguments.length === 0;
|
||||
var element = this[0];
|
||||
if (!element || !utils_1.isTag(element))
|
||||
return querying ? undefined : this;
|
||||
switch (element.name) {
|
||||
case 'textarea':
|
||||
return this.text(value);
|
||||
case 'select': {
|
||||
var option = this.find('option:selected');
|
||||
if (!querying) {
|
||||
if (this.attr('multiple') == null && typeof value === 'object') {
|
||||
return this;
|
||||
}
|
||||
this.find('option').removeAttr('selected');
|
||||
var values = typeof value !== 'object' ? [value] : value;
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
this.find("option[value=\"" + values[i] + "\"]").attr('selected', '');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
return this.attr('multiple')
|
||||
? option.toArray().map(function (el) { return static_1.text(el.children); })
|
||||
: option.attr('value');
|
||||
}
|
||||
case 'input':
|
||||
case 'option':
|
||||
return querying
|
||||
? this.attr('value')
|
||||
: this.attr('value', value);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
exports.val = val;
|
||||
/**
|
||||
* Remove an attribute.
|
||||
*
|
||||
* @private
|
||||
* @param elem - Node to remove attribute from.
|
||||
* @param name - Name of the attribute to remove.
|
||||
*/
|
||||
function removeAttribute(elem, name) {
|
||||
if (!elem.attribs || !hasOwn.call(elem.attribs, name))
|
||||
return;
|
||||
delete elem.attribs[name];
|
||||
}
|
||||
/**
|
||||
* Splits a space-separated list of names to individual names.
|
||||
*
|
||||
* @category Attributes
|
||||
* @param names - Names to split.
|
||||
* @returns - Split names.
|
||||
*/
|
||||
function splitNames(names) {
|
||||
return names ? names.trim().split(rspace) : [];
|
||||
}
|
||||
/**
|
||||
* Method for removing attributes by `name`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').removeAttr('class').html();
|
||||
* //=> <li>Pear</li>
|
||||
*
|
||||
* $('.apple').attr('id', 'favorite');
|
||||
* $('.apple').removeAttr('id class').html();
|
||||
* //=> <li>Apple</li>
|
||||
* ```
|
||||
*
|
||||
* @param name - Name of the attribute.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/removeAttr/}
|
||||
*/
|
||||
function removeAttr(name) {
|
||||
var attrNames = splitNames(name);
|
||||
var _loop_1 = function (i) {
|
||||
utils_1.domEach(this_1, function (elem) {
|
||||
if (utils_1.isTag(elem))
|
||||
removeAttribute(elem, attrNames[i]);
|
||||
});
|
||||
};
|
||||
var this_1 = this;
|
||||
for (var i = 0; i < attrNames.length; i++) {
|
||||
_loop_1(i);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
exports.removeAttr = removeAttr;
|
||||
/**
|
||||
* Check to see if *any* of the matched elements have the given `className`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').hasClass('pear');
|
||||
* //=> true
|
||||
*
|
||||
* $('apple').hasClass('fruit');
|
||||
* //=> false
|
||||
*
|
||||
* $('li').hasClass('pear');
|
||||
* //=> true
|
||||
* ```
|
||||
*
|
||||
* @param className - Name of the class.
|
||||
* @returns Indicates if an element has the given `className`.
|
||||
* @see {@link https://api.jquery.com/hasClass/}
|
||||
*/
|
||||
function hasClass(className) {
|
||||
return this.toArray().some(function (elem) {
|
||||
var clazz = utils_1.isTag(elem) && elem.attribs.class;
|
||||
var idx = -1;
|
||||
if (clazz && className.length) {
|
||||
while ((idx = clazz.indexOf(className, idx + 1)) > -1) {
|
||||
var end = idx + className.length;
|
||||
if ((idx === 0 || rspace.test(clazz[idx - 1])) &&
|
||||
(end === clazz.length || rspace.test(clazz[end]))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
exports.hasClass = hasClass;
|
||||
/**
|
||||
* Adds class(es) to all of the matched elements. Also accepts a `function`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').addClass('fruit').html();
|
||||
* //=> <li class="pear fruit">Pear</li>
|
||||
*
|
||||
* $('.apple').addClass('fruit red').html();
|
||||
* //=> <li class="apple fruit red">Apple</li>
|
||||
* ```
|
||||
*
|
||||
* @param value - Name of new class.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/addClass/}
|
||||
*/
|
||||
function addClass(value) {
|
||||
// Support functions
|
||||
if (typeof value === 'function') {
|
||||
return utils_1.domEach(this, function (el, i) {
|
||||
if (utils_1.isTag(el)) {
|
||||
var className = el.attribs.class || '';
|
||||
addClass.call([el], value.call(el, i, className));
|
||||
}
|
||||
});
|
||||
}
|
||||
// Return if no value or not a string or function
|
||||
if (!value || typeof value !== 'string')
|
||||
return this;
|
||||
var classNames = value.split(rspace);
|
||||
var numElements = this.length;
|
||||
for (var i = 0; i < numElements; i++) {
|
||||
var el = this[i];
|
||||
// If selected element isn't a tag, move on
|
||||
if (!utils_1.isTag(el))
|
||||
continue;
|
||||
// If we don't already have classes — always set xmlMode to false here, as it doesn't matter for classes
|
||||
var className = getAttr(el, 'class', false);
|
||||
if (!className) {
|
||||
setAttr(el, 'class', classNames.join(' ').trim());
|
||||
}
|
||||
else {
|
||||
var setClass = " " + className + " ";
|
||||
// Check if class already exists
|
||||
for (var j = 0; j < classNames.length; j++) {
|
||||
var appendClass = classNames[j] + " ";
|
||||
if (!setClass.includes(" " + appendClass))
|
||||
setClass += appendClass;
|
||||
}
|
||||
setAttr(el, 'class', setClass.trim());
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
exports.addClass = addClass;
|
||||
/**
|
||||
* Removes one or more space-separated classes from the selected elements. If no
|
||||
* `className` is defined, all classes will be removed. Also accepts a `function`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').removeClass('pear').html();
|
||||
* //=> <li class="">Pear</li>
|
||||
*
|
||||
* $('.apple').addClass('red').removeClass().html();
|
||||
* //=> <li class="">Apple</li>
|
||||
* ```
|
||||
*
|
||||
* @param name - Name of the class. If not specified, removes all elements.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/removeClass/}
|
||||
*/
|
||||
function removeClass(name) {
|
||||
// Handle if value is a function
|
||||
if (typeof name === 'function') {
|
||||
return utils_1.domEach(this, function (el, i) {
|
||||
if (utils_1.isTag(el))
|
||||
removeClass.call([el], name.call(el, i, el.attribs.class || ''));
|
||||
});
|
||||
}
|
||||
var classes = splitNames(name);
|
||||
var numClasses = classes.length;
|
||||
var removeAll = arguments.length === 0;
|
||||
return utils_1.domEach(this, function (el) {
|
||||
if (!utils_1.isTag(el))
|
||||
return;
|
||||
if (removeAll) {
|
||||
// Short circuit the remove all case as this is the nice one
|
||||
el.attribs.class = '';
|
||||
}
|
||||
else {
|
||||
var elClasses = splitNames(el.attribs.class);
|
||||
var changed = false;
|
||||
for (var j = 0; j < numClasses; j++) {
|
||||
var index = elClasses.indexOf(classes[j]);
|
||||
if (index >= 0) {
|
||||
elClasses.splice(index, 1);
|
||||
changed = true;
|
||||
/*
|
||||
* We have to do another pass to ensure that there are not duplicate
|
||||
* classes listed
|
||||
*/
|
||||
j--;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
el.attribs.class = elClasses.join(' ');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.removeClass = removeClass;
|
||||
/**
|
||||
* Add or remove class(es) from the matched elements, depending on either the
|
||||
* class's presence or the value of the switch argument. Also accepts a `function`.
|
||||
*
|
||||
* @category Attributes
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple.green').toggleClass('fruit green red').html();
|
||||
* //=> <li class="apple fruit red">Apple</li>
|
||||
*
|
||||
* $('.apple.green').toggleClass('fruit green red', true).html();
|
||||
* //=> <li class="apple green fruit red">Apple</li>
|
||||
* ```
|
||||
*
|
||||
* @param value - Name of the class. Can also be a function.
|
||||
* @param stateVal - If specified the state of the class.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/toggleClass/}
|
||||
*/
|
||||
function toggleClass(value, stateVal) {
|
||||
// Support functions
|
||||
if (typeof value === 'function') {
|
||||
return utils_1.domEach(this, function (el, i) {
|
||||
if (utils_1.isTag(el)) {
|
||||
toggleClass.call([el], value.call(el, i, el.attribs.class || '', stateVal), stateVal);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Return if no value or not a string or function
|
||||
if (!value || typeof value !== 'string')
|
||||
return this;
|
||||
var classNames = value.split(rspace);
|
||||
var numClasses = classNames.length;
|
||||
var state = typeof stateVal === 'boolean' ? (stateVal ? 1 : -1) : 0;
|
||||
var numElements = this.length;
|
||||
for (var i = 0; i < numElements; i++) {
|
||||
var el = this[i];
|
||||
// If selected element isn't a tag, move on
|
||||
if (!utils_1.isTag(el))
|
||||
continue;
|
||||
var elementClasses = splitNames(el.attribs.class);
|
||||
// Check if class already exists
|
||||
for (var j = 0; j < numClasses; j++) {
|
||||
// Check if the class name is currently defined
|
||||
var index = elementClasses.indexOf(classNames[j]);
|
||||
// Add if stateValue === true or we are toggling and there is no value
|
||||
if (state >= 0 && index < 0) {
|
||||
elementClasses.push(classNames[j]);
|
||||
}
|
||||
else if (state <= 0 && index >= 0) {
|
||||
// Otherwise remove but only if the item exists
|
||||
elementClasses.splice(index, 1);
|
||||
}
|
||||
}
|
||||
el.attribs.class = elementClasses.join(' ');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
exports.toggleClass = toggleClass;
|
||||
41
book/node_modules/juice/node_modules/cheerio/lib/api/css.d.ts
generated
vendored
Normal file
41
book/node_modules/juice/node_modules/cheerio/lib/api/css.d.ts
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/api/css.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/api/css.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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"}
|
||||
95
book/node_modules/juice/node_modules/cheerio/lib/api/css.js
generated
vendored
Normal file
95
book/node_modules/juice/node_modules/cheerio/lib/api/css.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
"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 (el, i) {
|
||||
if (utils_1.isTag(el)) {
|
||||
// `prop` can't be an array here anymore.
|
||||
setCss(el, prop, val, i);
|
||||
}
|
||||
});
|
||||
}
|
||||
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;
|
||||
}, {});
|
||||
}
|
||||
31
book/node_modules/juice/node_modules/cheerio/lib/api/forms.d.ts
generated
vendored
Normal file
31
book/node_modules/juice/node_modules/cheerio/lib/api/forms.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
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
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/api/forms.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/api/forms.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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,EAAE,MAAM,YAAY,CAAC;AAW1C;;;;;;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,CAsCnB"}
|
||||
84
book/node_modules/juice/node_modules/cheerio/lib/api/forms.js
generated
vendored
Normal file
84
book/node_modules/juice/node_modules/cheerio/lib/api/forms.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
"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() {
|
||||
var _this = this;
|
||||
// Resolve all form elements from either forms or collections of form elements
|
||||
return this.map(function (_, elem) {
|
||||
var $elem = _this._make(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 = _this._make(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;
|
||||
496
book/node_modules/juice/node_modules/cheerio/lib/api/manipulation.d.ts
generated
vendored
Normal file
496
book/node_modules/juice/node_modules/cheerio/lib/api/manipulation.d.ts
generated
vendored
Normal file
@@ -0,0 +1,496 @@
|
||||
/**
|
||||
* Methods for modifying the DOM structure.
|
||||
*
|
||||
* @module cheerio/manipulation
|
||||
*/
|
||||
import { Node } from 'domhandler';
|
||||
import type { Cheerio } from '../cheerio';
|
||||
import type { BasicAcceptedElems, AcceptedElems } from '../types';
|
||||
/**
|
||||
* Create an array of nodes, recursing into arrays and parsing strings if necessary.
|
||||
*
|
||||
* @private
|
||||
* @category Manipulation
|
||||
* @param elem - Elements to make an array of.
|
||||
* @param clone - Optionally clone nodes.
|
||||
* @returns The array of nodes.
|
||||
*/
|
||||
export declare function _makeDomArray<T extends Node>(this: Cheerio<T>, elem?: BasicAcceptedElems<Node>, clone?: boolean): Node[];
|
||||
/**
|
||||
* Insert every element in the set of matched elements to the end of the target.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('<li class="plum">Plum</li>').appendTo('#fruits');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param target - Element to append elements to.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/appendTo/}
|
||||
*/
|
||||
export declare function appendTo<T extends Node>(this: Cheerio<T>, target: BasicAcceptedElems<Node>): Cheerio<T>;
|
||||
/**
|
||||
* Insert every element in the set of matched elements to the beginning of the target.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('<li class="plum">Plum</li>').prependTo('#fruits');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param target - Element to prepend elements to.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/prependTo/}
|
||||
*/
|
||||
export declare function prependTo<T extends Node>(this: Cheerio<T>, target: BasicAcceptedElems<Node>): Cheerio<T>;
|
||||
/**
|
||||
* Inserts content as the *last* child of each of the selected elements.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('ul').append('<li class="plum">Plum</li>');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @see {@link https://api.jquery.com/append/}
|
||||
*/
|
||||
export declare const append: <T extends Node>(this: Cheerio<T>, ...elems: [(this: Node, i: number, html: string) => BasicAcceptedElems<Node>] | BasicAcceptedElems<Node>[]) => Cheerio<T>;
|
||||
/**
|
||||
* Inserts content as the *first* child of each of the selected elements.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('ul').prepend('<li class="plum">Plum</li>');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @see {@link https://api.jquery.com/prepend/}
|
||||
*/
|
||||
export declare const prepend: <T extends Node>(this: Cheerio<T>, ...elems: [(this: Node, i: number, html: string) => BasicAcceptedElems<Node>] | BasicAcceptedElems<Node>[]) => Cheerio<T>;
|
||||
/**
|
||||
* The .wrap() function can take any string or object that could be passed to
|
||||
* the $() factory function to specify a DOM structure. This structure may be
|
||||
* nested several levels deep, but should contain only one inmost element. A
|
||||
* copy of this structure will be wrapped around each of the elements in the set
|
||||
* of matched elements. This method returns the original set of elements for
|
||||
* chaining purposes.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const redFruit = $('<div class="red-fruit"></div>');
|
||||
* $('.apple').wrap(redFruit);
|
||||
*
|
||||
* //=> <ul id="fruits">
|
||||
* // <div class="red-fruit">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // </div>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // </ul>
|
||||
*
|
||||
* const healthy = $('<div class="healthy"></div>');
|
||||
* $('li').wrap(healthy);
|
||||
*
|
||||
* //=> <ul id="fruits">
|
||||
* // <div class="healthy">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // </div>
|
||||
* // <div class="healthy">
|
||||
* // <li class="orange">Orange</li>
|
||||
* // </div>
|
||||
* // <div class="healthy">
|
||||
* // <li class="plum">Plum</li>
|
||||
* // </div>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param wrapper - The DOM structure to wrap around each element in the selection.
|
||||
* @see {@link https://api.jquery.com/wrap/}
|
||||
*/
|
||||
export declare const wrap: <T extends Node>(this: Cheerio<T>, wrapper: AcceptedElems<Node>) => Cheerio<T>;
|
||||
/**
|
||||
* The .wrapInner() function can take any string or object that could be passed
|
||||
* to the $() factory function to specify a DOM structure. This structure may be
|
||||
* nested several levels deep, but should contain only one inmost element. The
|
||||
* structure will be wrapped around the content of each of the elements in the
|
||||
* set of matched elements.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const redFruit = $('<div class="red-fruit"></div>');
|
||||
* $('.apple').wrapInner(redFruit);
|
||||
*
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">
|
||||
* // <div class="red-fruit">Apple</div>
|
||||
* // </li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
*
|
||||
* const healthy = $('<div class="healthy"></div>');
|
||||
* $('li').wrapInner(healthy);
|
||||
*
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">
|
||||
* // <div class="healthy">Apple</div>
|
||||
* // </li>
|
||||
* // <li class="orange">
|
||||
* // <div class="healthy">Orange</div>
|
||||
* // </li>
|
||||
* // <li class="pear">
|
||||
* // <div class="healthy">Pear</div>
|
||||
* // </li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param wrapper - The DOM structure to wrap around the content of each element
|
||||
* in the selection.
|
||||
* @returns The instance itself, for chaining.
|
||||
* @see {@link https://api.jquery.com/wrapInner/}
|
||||
*/
|
||||
export declare const wrapInner: <T extends Node>(this: Cheerio<T>, wrapper: AcceptedElems<Node>) => Cheerio<T>;
|
||||
/**
|
||||
* The .unwrap() function, removes the parents of the set of matched elements
|
||||
* from the DOM, leaving the matched elements in their place.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example <caption>without selector</caption>
|
||||
*
|
||||
* ```js
|
||||
* const $ = cheerio.load(
|
||||
* '<div id=test>\n <div><p>Hello</p></div>\n <div><p>World</p></div>\n</div>'
|
||||
* );
|
||||
* $('#test p').unwrap();
|
||||
*
|
||||
* //=> <div id=test>
|
||||
* // <p>Hello</p>
|
||||
* // <p>World</p>
|
||||
* // </div>
|
||||
* ```
|
||||
*
|
||||
* @example <caption>with selector</caption>
|
||||
*
|
||||
* ```js
|
||||
* const $ = cheerio.load(
|
||||
* '<div id=test>\n <p>Hello</p>\n <b><p>World</p></b>\n</div>'
|
||||
* );
|
||||
* $('#test p').unwrap('b');
|
||||
*
|
||||
* //=> <div id=test>
|
||||
* // <p>Hello</p>
|
||||
* // <p>World</p>
|
||||
* // </div>
|
||||
* ```
|
||||
*
|
||||
* @param selector - A selector to check the parent element against. If an
|
||||
* element's parent does not match the selector, the element won't be unwrapped.
|
||||
* @returns The instance itself, for chaining.
|
||||
* @see {@link https://api.jquery.com/unwrap/}
|
||||
*/
|
||||
export declare function unwrap<T extends Node>(this: Cheerio<T>, selector?: string): Cheerio<T>;
|
||||
/**
|
||||
* The .wrapAll() function can take any string or object that could be passed to
|
||||
* the $() function to specify a DOM structure. This structure may be nested
|
||||
* several levels deep, but should contain only one inmost element. The
|
||||
* structure will be wrapped around all of the elements in the set of matched
|
||||
* elements, as a single group.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example <caption>With markup passed to `wrapAll`</caption>
|
||||
*
|
||||
* ```js
|
||||
* const $ = cheerio.load(
|
||||
* '<div class="container"><div class="inner">First</div><div class="inner">Second</div></div>'
|
||||
* );
|
||||
* $('.inner').wrapAll("<div class='new'></div>");
|
||||
*
|
||||
* //=> <div class="container">
|
||||
* // <div class='new'>
|
||||
* // <div class="inner">First</div>
|
||||
* // <div class="inner">Second</div>
|
||||
* // </div>
|
||||
* // </div>
|
||||
* ```
|
||||
*
|
||||
* @example <caption>With an existing cheerio instance</caption>
|
||||
*
|
||||
* ```js
|
||||
* const $ = cheerio.load(
|
||||
* '<span>Span 1</span><strong>Strong</strong><span>Span 2</span>'
|
||||
* );
|
||||
* const wrap = $('<div><p><em><b></b></em></p></div>');
|
||||
* $('span').wrapAll(wrap);
|
||||
*
|
||||
* //=> <div>
|
||||
* // <p>
|
||||
* // <em>
|
||||
* // <b>
|
||||
* // <span>Span 1</span>
|
||||
* // <span>Span 2</span>
|
||||
* // </b>
|
||||
* // </em>
|
||||
* // </p>
|
||||
* // </div>
|
||||
* // <strong>Strong</strong>
|
||||
* ```
|
||||
*
|
||||
* @param wrapper - The DOM structure to wrap around all matched elements in the
|
||||
* selection.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/wrapAll/}
|
||||
*/
|
||||
export declare function wrapAll<T extends Node>(this: Cheerio<T>, wrapper: AcceptedElems<T>): Cheerio<T>;
|
||||
/**
|
||||
* Insert content next to each element in the set of matched elements.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').after('<li class="plum">Plum</li>');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param content - HTML string, DOM element, array of DOM elements or Cheerio
|
||||
* to insert after each element in the set of matched elements.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/after/}
|
||||
*/
|
||||
export declare function after<T extends Node>(this: Cheerio<T>, ...elems: [(this: Node, i: number, html: string) => BasicAcceptedElems<Node>] | BasicAcceptedElems<Node>[]): Cheerio<T>;
|
||||
/**
|
||||
* Insert every element in the set of matched elements after the target.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('<li class="plum">Plum</li>').insertAfter('.apple');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param target - Element to insert elements after.
|
||||
* @returns The set of newly inserted elements.
|
||||
* @see {@link https://api.jquery.com/insertAfter/}
|
||||
*/
|
||||
export declare function insertAfter<T extends Node>(this: Cheerio<T>, target: BasicAcceptedElems<Node>): Cheerio<T>;
|
||||
/**
|
||||
* Insert content previous to each element in the set of matched elements.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').before('<li class="plum">Plum</li>');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param content - HTML string, DOM element, array of DOM elements or Cheerio
|
||||
* to insert before each element in the set of matched elements.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/before/}
|
||||
*/
|
||||
export declare function before<T extends Node>(this: Cheerio<T>, ...elems: [(this: Node, i: number, html: string) => BasicAcceptedElems<Node>] | BasicAcceptedElems<Node>[]): Cheerio<T>;
|
||||
/**
|
||||
* Insert every element in the set of matched elements before the target.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('<li class="plum">Plum</li>').insertBefore('.apple');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param target - Element to insert elements before.
|
||||
* @returns The set of newly inserted elements.
|
||||
* @see {@link https://api.jquery.com/insertBefore/}
|
||||
*/
|
||||
export declare function insertBefore<T extends Node>(this: Cheerio<T>, target: BasicAcceptedElems<Node>): Cheerio<T>;
|
||||
/**
|
||||
* Removes the set of matched elements from the DOM and all their children.
|
||||
* `selector` filters the set of matched elements to be removed.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').remove();
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param selector - Optional selector for elements to remove.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/remove/}
|
||||
*/
|
||||
export declare function remove<T extends Node>(this: Cheerio<T>, selector?: string): Cheerio<T>;
|
||||
/**
|
||||
* Replaces matched elements with `content`.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const plum = $('<li class="plum">Plum</li>');
|
||||
* $('.pear').replaceWith(plum);
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param content - Replacement for matched elements.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/replaceWith/}
|
||||
*/
|
||||
export declare function replaceWith<T extends Node>(this: Cheerio<T>, content: AcceptedElems<Node>): Cheerio<T>;
|
||||
/**
|
||||
* Empties an element, removing all its children.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('ul').empty();
|
||||
* $.html();
|
||||
* //=> <ul id="fruits"></ul>
|
||||
* ```
|
||||
*
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/empty/}
|
||||
*/
|
||||
export declare function empty<T extends Node>(this: Cheerio<T>): Cheerio<T>;
|
||||
/**
|
||||
* Gets an HTML content string from the first selected element. If `htmlString`
|
||||
* is specified, each selected element's content is replaced by the new content.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.orange').html();
|
||||
* //=> Orange
|
||||
*
|
||||
* $('#fruits').html('<li class="mango">Mango</li>').html();
|
||||
* //=> <li class="mango">Mango</li>
|
||||
* ```
|
||||
*
|
||||
* @param str - If specified used to replace selection's contents.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/html/}
|
||||
*/
|
||||
export declare function html<T extends Node>(this: Cheerio<T>): string | null;
|
||||
export declare function html<T extends Node>(this: Cheerio<T>, str: string | Cheerio<T>): Cheerio<T>;
|
||||
/**
|
||||
* Turns the collection to a string. Alias for `.html()`.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @returns The rendered document.
|
||||
*/
|
||||
export declare function toString<T extends Node>(this: Cheerio<T>): string;
|
||||
/**
|
||||
* Get the combined text contents of each element in the set of matched
|
||||
* elements, including their descendants. If `textString` is specified, each
|
||||
* selected element's content is replaced by the new text content.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.orange').text();
|
||||
* //=> Orange
|
||||
*
|
||||
* $('ul').text();
|
||||
* //=> Apple
|
||||
* // Orange
|
||||
* // Pear
|
||||
* ```
|
||||
*
|
||||
* @param str - If specified replacement for the selected element's contents.
|
||||
* @returns The instance itself when setting text, otherwise the rendered document.
|
||||
* @see {@link https://api.jquery.com/text/}
|
||||
*/
|
||||
export declare function text<T extends Node>(this: Cheerio<T>): string;
|
||||
export declare function text<T extends Node>(this: Cheerio<T>, str: string | ((this: Node, i: number, text: string) => string)): Cheerio<T>;
|
||||
/**
|
||||
* Clone the cheerio object.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const moreFruit = $('#fruits').clone();
|
||||
* ```
|
||||
*
|
||||
* @returns The cloned object.
|
||||
* @see {@link https://api.jquery.com/clone/}
|
||||
*/
|
||||
export declare function clone<T extends Node>(this: Cheerio<T>): Cheerio<T>;
|
||||
//# sourceMappingURL=manipulation.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/api/manipulation.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/api/manipulation.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAElE;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,IAAI,EAC1C,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,EAC/B,KAAK,CAAC,EAAE,OAAO,GACd,IAAI,EAAE,CAiBR;AAoGD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EACrC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAC/B,OAAO,CAAC,CAAC,CAAC,CAMZ;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EACtC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAC/B,OAAO,CAAC,CAAC,CAAC,CAMZ;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,MAAM,uDA3KH,IAAI,KAAK,MAAM,QAAQ,MAAM,KAAK,mBAAmB,IAAI,CAAC,6CA6KxE,CAAC;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,OAAO,uDAlMJ,IAAI,KAAK,MAAM,QAAQ,MAAM,KAAK,mBAAmB,IAAI,CAAC,6CAoMxE,CAAC;AAuDH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,IAAI,8CAtFJ,cAAc,IAAI,CAAC,eAqG9B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,SAAS,8CAlJT,cAAc,IAAI,CAAC,eAsJ9B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,IAAI,EACnC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,CAAC,CAAC,CAOZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,IAAI,EACpC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC,CAAC,CAAC,CAiCZ;AAID;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,IAAI,EAClC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,GAAG,KAAK,EACJ,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,kBAAkB,CAAC,IAAI,CAAC,CAAC,GACnE,kBAAkB,CAAC,IAAI,CAAC,EAAE,GAC7B,OAAO,CAAC,CAAC,CAAC,CA0BZ;AAID;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EACxC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAC/B,OAAO,CAAC,CAAC,CAAC,CA6BZ;AAID;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,IAAI,EACnC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,GAAG,KAAK,EACJ,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,kBAAkB,CAAC,IAAI,CAAC,CAAC,GACnE,kBAAkB,CAAC,IAAI,CAAC,EAAE,GAC7B,OAAO,CAAC,CAAC,CAAC,CA0BZ;AAID;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,IAAI,EACzC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAC/B,OAAO,CAAC,CAAC,CAAC,CA2BZ;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,IAAI,EACnC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,CAAC,CAAC,CAUZ;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EACxC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,GAC3B,OAAO,CAAC,CAAC,CAAC,CA2BZ;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CASlE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;AACtE,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CAAC;AA8Bd;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,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"}
|
||||
852
book/node_modules/juice/node_modules/cheerio/lib/api/manipulation.js
generated
vendored
Normal file
852
book/node_modules/juice/node_modules/cheerio/lib/api/manipulation.js
generated
vendored
Normal file
@@ -0,0 +1,852 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.clone = exports.text = exports.toString = exports.html = exports.empty = exports.replaceWith = exports.remove = exports.insertBefore = exports.before = exports.insertAfter = exports.after = exports.wrapAll = exports.unwrap = exports.wrapInner = exports.wrap = exports.prepend = exports.append = exports.prependTo = exports.appendTo = exports._makeDomArray = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var domhandler_1 = require("domhandler");
|
||||
/**
|
||||
* Methods for modifying the DOM structure.
|
||||
*
|
||||
* @module cheerio/manipulation
|
||||
*/
|
||||
var domhandler_2 = require("domhandler");
|
||||
var parse_1 = tslib_1.__importStar(require("../parse"));
|
||||
var static_1 = require("../static");
|
||||
var utils_1 = require("../utils");
|
||||
var htmlparser2_1 = require("htmlparser2");
|
||||
/**
|
||||
* Create an array of nodes, recursing into arrays and parsing strings if necessary.
|
||||
*
|
||||
* @private
|
||||
* @category Manipulation
|
||||
* @param elem - Elements to make an array of.
|
||||
* @param clone - Optionally clone nodes.
|
||||
* @returns The array of nodes.
|
||||
*/
|
||||
function _makeDomArray(elem, clone) {
|
||||
var _this = this;
|
||||
if (elem == null) {
|
||||
return [];
|
||||
}
|
||||
if (utils_1.isCheerio(elem)) {
|
||||
return clone ? utils_1.cloneDom(elem.get()) : elem.get();
|
||||
}
|
||||
if (Array.isArray(elem)) {
|
||||
return elem.reduce(function (newElems, el) { return newElems.concat(_this._makeDomArray(el, clone)); }, []);
|
||||
}
|
||||
if (typeof elem === 'string') {
|
||||
return parse_1.default(elem, this.options, false).children;
|
||||
}
|
||||
return clone ? utils_1.cloneDom([elem]) : [elem];
|
||||
}
|
||||
exports._makeDomArray = _makeDomArray;
|
||||
function _insert(concatenator) {
|
||||
return function () {
|
||||
var _this = this;
|
||||
var elems = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
elems[_i] = arguments[_i];
|
||||
}
|
||||
var lastIdx = this.length - 1;
|
||||
return utils_1.domEach(this, function (el, i) {
|
||||
if (!domhandler_1.hasChildren(el))
|
||||
return;
|
||||
var domSrc = typeof elems[0] === 'function'
|
||||
? elems[0].call(el, i, static_1.html(el.children))
|
||||
: elems;
|
||||
var dom = _this._makeDomArray(domSrc, i < lastIdx);
|
||||
concatenator(dom, el.children, el);
|
||||
});
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Modify an array in-place, removing some number of elements and adding new
|
||||
* elements directly following them.
|
||||
*
|
||||
* @private
|
||||
* @category Manipulation
|
||||
* @param array - Target array to splice.
|
||||
* @param spliceIdx - Index at which to begin changing the array.
|
||||
* @param spliceCount - Number of elements to remove from the array.
|
||||
* @param newElems - Elements to insert into the array.
|
||||
* @param parent - The parent of the node.
|
||||
* @returns The spliced array.
|
||||
*/
|
||||
function uniqueSplice(array, spliceIdx, spliceCount, newElems, parent) {
|
||||
var _a, _b;
|
||||
var spliceArgs = tslib_1.__spreadArray([
|
||||
spliceIdx,
|
||||
spliceCount
|
||||
], newElems);
|
||||
var prev = array[spliceIdx - 1] || null;
|
||||
var next = array[spliceIdx + spliceCount] || null;
|
||||
/*
|
||||
* Before splicing in new elements, ensure they do not already appear in the
|
||||
* current array.
|
||||
*/
|
||||
for (var idx = 0; idx < newElems.length; ++idx) {
|
||||
var node = newElems[idx];
|
||||
var oldParent = node.parent;
|
||||
if (oldParent) {
|
||||
var prevIdx = oldParent.children.indexOf(newElems[idx]);
|
||||
if (prevIdx > -1) {
|
||||
oldParent.children.splice(prevIdx, 1);
|
||||
if (parent === oldParent && spliceIdx > prevIdx) {
|
||||
spliceArgs[0]--;
|
||||
}
|
||||
}
|
||||
}
|
||||
node.parent = parent;
|
||||
if (node.prev) {
|
||||
node.prev.next = (_a = node.next) !== null && _a !== void 0 ? _a : null;
|
||||
}
|
||||
if (node.next) {
|
||||
node.next.prev = (_b = node.prev) !== null && _b !== void 0 ? _b : null;
|
||||
}
|
||||
node.prev = newElems[idx - 1] || prev;
|
||||
node.next = newElems[idx + 1] || next;
|
||||
}
|
||||
if (prev) {
|
||||
prev.next = newElems[0];
|
||||
}
|
||||
if (next) {
|
||||
next.prev = newElems[newElems.length - 1];
|
||||
}
|
||||
return array.splice.apply(array, spliceArgs);
|
||||
}
|
||||
/**
|
||||
* Insert every element in the set of matched elements to the end of the target.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('<li class="plum">Plum</li>').appendTo('#fruits');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param target - Element to append elements to.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/appendTo/}
|
||||
*/
|
||||
function appendTo(target) {
|
||||
var appendTarget = utils_1.isCheerio(target) ? target : this._make(target);
|
||||
appendTarget.append(this);
|
||||
return this;
|
||||
}
|
||||
exports.appendTo = appendTo;
|
||||
/**
|
||||
* Insert every element in the set of matched elements to the beginning of the target.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('<li class="plum">Plum</li>').prependTo('#fruits');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param target - Element to prepend elements to.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/prependTo/}
|
||||
*/
|
||||
function prependTo(target) {
|
||||
var prependTarget = utils_1.isCheerio(target) ? target : this._make(target);
|
||||
prependTarget.prepend(this);
|
||||
return this;
|
||||
}
|
||||
exports.prependTo = prependTo;
|
||||
/**
|
||||
* Inserts content as the *last* child of each of the selected elements.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('ul').append('<li class="plum">Plum</li>');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @see {@link https://api.jquery.com/append/}
|
||||
*/
|
||||
exports.append = _insert(function (dom, children, parent) {
|
||||
uniqueSplice(children, children.length, 0, dom, parent);
|
||||
});
|
||||
/**
|
||||
* Inserts content as the *first* child of each of the selected elements.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('ul').prepend('<li class="plum">Plum</li>');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @see {@link https://api.jquery.com/prepend/}
|
||||
*/
|
||||
exports.prepend = _insert(function (dom, children, parent) {
|
||||
uniqueSplice(children, 0, 0, dom, parent);
|
||||
});
|
||||
function _wrap(insert) {
|
||||
return function (wrapper) {
|
||||
var lastIdx = this.length - 1;
|
||||
var lastParent = this.parents().last();
|
||||
for (var i = 0; i < this.length; i++) {
|
||||
var el = this[i];
|
||||
var wrap_1 = typeof wrapper === 'function'
|
||||
? wrapper.call(el, i, el)
|
||||
: typeof wrapper === 'string' && !utils_1.isHtml(wrapper)
|
||||
? lastParent.find(wrapper).clone()
|
||||
: wrapper;
|
||||
var wrapperDom = this._makeDomArray(wrap_1, i < lastIdx)[0];
|
||||
if (!wrapperDom || !htmlparser2_1.DomUtils.hasChildren(wrapperDom))
|
||||
continue;
|
||||
var elInsertLocation = wrapperDom;
|
||||
/*
|
||||
* Find the deepest child. Only consider the first tag child of each node
|
||||
* (ignore text); stop if no children are found.
|
||||
*/
|
||||
var j = 0;
|
||||
while (j < elInsertLocation.children.length) {
|
||||
var child = elInsertLocation.children[j];
|
||||
if (utils_1.isTag(child)) {
|
||||
elInsertLocation = child;
|
||||
j = 0;
|
||||
}
|
||||
else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
insert(el, elInsertLocation, [wrapperDom]);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* The .wrap() function can take any string or object that could be passed to
|
||||
* the $() factory function to specify a DOM structure. This structure may be
|
||||
* nested several levels deep, but should contain only one inmost element. A
|
||||
* copy of this structure will be wrapped around each of the elements in the set
|
||||
* of matched elements. This method returns the original set of elements for
|
||||
* chaining purposes.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const redFruit = $('<div class="red-fruit"></div>');
|
||||
* $('.apple').wrap(redFruit);
|
||||
*
|
||||
* //=> <ul id="fruits">
|
||||
* // <div class="red-fruit">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // </div>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // </ul>
|
||||
*
|
||||
* const healthy = $('<div class="healthy"></div>');
|
||||
* $('li').wrap(healthy);
|
||||
*
|
||||
* //=> <ul id="fruits">
|
||||
* // <div class="healthy">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // </div>
|
||||
* // <div class="healthy">
|
||||
* // <li class="orange">Orange</li>
|
||||
* // </div>
|
||||
* // <div class="healthy">
|
||||
* // <li class="plum">Plum</li>
|
||||
* // </div>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param wrapper - The DOM structure to wrap around each element in the selection.
|
||||
* @see {@link https://api.jquery.com/wrap/}
|
||||
*/
|
||||
exports.wrap = _wrap(function (el, elInsertLocation, wrapperDom) {
|
||||
var parent = el.parent;
|
||||
if (!parent)
|
||||
return;
|
||||
var siblings = parent.children;
|
||||
var index = siblings.indexOf(el);
|
||||
parse_1.update([el], elInsertLocation);
|
||||
/*
|
||||
* The previous operation removed the current element from the `siblings`
|
||||
* array, so the `dom` array can be inserted without removing any
|
||||
* additional elements.
|
||||
*/
|
||||
uniqueSplice(siblings, index, 0, wrapperDom, parent);
|
||||
});
|
||||
/**
|
||||
* The .wrapInner() function can take any string or object that could be passed
|
||||
* to the $() factory function to specify a DOM structure. This structure may be
|
||||
* nested several levels deep, but should contain only one inmost element. The
|
||||
* structure will be wrapped around the content of each of the elements in the
|
||||
* set of matched elements.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const redFruit = $('<div class="red-fruit"></div>');
|
||||
* $('.apple').wrapInner(redFruit);
|
||||
*
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">
|
||||
* // <div class="red-fruit">Apple</div>
|
||||
* // </li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
*
|
||||
* const healthy = $('<div class="healthy"></div>');
|
||||
* $('li').wrapInner(healthy);
|
||||
*
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">
|
||||
* // <div class="healthy">Apple</div>
|
||||
* // </li>
|
||||
* // <li class="orange">
|
||||
* // <div class="healthy">Orange</div>
|
||||
* // </li>
|
||||
* // <li class="pear">
|
||||
* // <div class="healthy">Pear</div>
|
||||
* // </li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param wrapper - The DOM structure to wrap around the content of each element
|
||||
* in the selection.
|
||||
* @returns The instance itself, for chaining.
|
||||
* @see {@link https://api.jquery.com/wrapInner/}
|
||||
*/
|
||||
exports.wrapInner = _wrap(function (el, elInsertLocation, wrapperDom) {
|
||||
if (!domhandler_1.hasChildren(el))
|
||||
return;
|
||||
parse_1.update(el.children, elInsertLocation);
|
||||
parse_1.update(wrapperDom, el);
|
||||
});
|
||||
/**
|
||||
* The .unwrap() function, removes the parents of the set of matched elements
|
||||
* from the DOM, leaving the matched elements in their place.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example <caption>without selector</caption>
|
||||
*
|
||||
* ```js
|
||||
* const $ = cheerio.load(
|
||||
* '<div id=test>\n <div><p>Hello</p></div>\n <div><p>World</p></div>\n</div>'
|
||||
* );
|
||||
* $('#test p').unwrap();
|
||||
*
|
||||
* //=> <div id=test>
|
||||
* // <p>Hello</p>
|
||||
* // <p>World</p>
|
||||
* // </div>
|
||||
* ```
|
||||
*
|
||||
* @example <caption>with selector</caption>
|
||||
*
|
||||
* ```js
|
||||
* const $ = cheerio.load(
|
||||
* '<div id=test>\n <p>Hello</p>\n <b><p>World</p></b>\n</div>'
|
||||
* );
|
||||
* $('#test p').unwrap('b');
|
||||
*
|
||||
* //=> <div id=test>
|
||||
* // <p>Hello</p>
|
||||
* // <p>World</p>
|
||||
* // </div>
|
||||
* ```
|
||||
*
|
||||
* @param selector - A selector to check the parent element against. If an
|
||||
* element's parent does not match the selector, the element won't be unwrapped.
|
||||
* @returns The instance itself, for chaining.
|
||||
* @see {@link https://api.jquery.com/unwrap/}
|
||||
*/
|
||||
function unwrap(selector) {
|
||||
var _this = this;
|
||||
this.parent(selector)
|
||||
.not('body')
|
||||
.each(function (_, el) {
|
||||
_this._make(el).replaceWith(el.children);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
exports.unwrap = unwrap;
|
||||
/**
|
||||
* The .wrapAll() function can take any string or object that could be passed to
|
||||
* the $() function to specify a DOM structure. This structure may be nested
|
||||
* several levels deep, but should contain only one inmost element. The
|
||||
* structure will be wrapped around all of the elements in the set of matched
|
||||
* elements, as a single group.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example <caption>With markup passed to `wrapAll`</caption>
|
||||
*
|
||||
* ```js
|
||||
* const $ = cheerio.load(
|
||||
* '<div class="container"><div class="inner">First</div><div class="inner">Second</div></div>'
|
||||
* );
|
||||
* $('.inner').wrapAll("<div class='new'></div>");
|
||||
*
|
||||
* //=> <div class="container">
|
||||
* // <div class='new'>
|
||||
* // <div class="inner">First</div>
|
||||
* // <div class="inner">Second</div>
|
||||
* // </div>
|
||||
* // </div>
|
||||
* ```
|
||||
*
|
||||
* @example <caption>With an existing cheerio instance</caption>
|
||||
*
|
||||
* ```js
|
||||
* const $ = cheerio.load(
|
||||
* '<span>Span 1</span><strong>Strong</strong><span>Span 2</span>'
|
||||
* );
|
||||
* const wrap = $('<div><p><em><b></b></em></p></div>');
|
||||
* $('span').wrapAll(wrap);
|
||||
*
|
||||
* //=> <div>
|
||||
* // <p>
|
||||
* // <em>
|
||||
* // <b>
|
||||
* // <span>Span 1</span>
|
||||
* // <span>Span 2</span>
|
||||
* // </b>
|
||||
* // </em>
|
||||
* // </p>
|
||||
* // </div>
|
||||
* // <strong>Strong</strong>
|
||||
* ```
|
||||
*
|
||||
* @param wrapper - The DOM structure to wrap around all matched elements in the
|
||||
* selection.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/wrapAll/}
|
||||
*/
|
||||
function wrapAll(wrapper) {
|
||||
var el = this[0];
|
||||
if (el) {
|
||||
var wrap_2 = this._make(typeof wrapper === 'function' ? wrapper.call(el, 0, el) : wrapper).insertBefore(el);
|
||||
// If html is given as wrapper, wrap may contain text elements
|
||||
var elInsertLocation = void 0;
|
||||
for (var i = 0; i < wrap_2.length; i++) {
|
||||
if (wrap_2[i].type === 'tag')
|
||||
elInsertLocation = wrap_2[i];
|
||||
}
|
||||
var j = 0;
|
||||
/*
|
||||
* Find the deepest child. Only consider the first tag child of each node
|
||||
* (ignore text); stop if no children are found.
|
||||
*/
|
||||
while (elInsertLocation && j < elInsertLocation.children.length) {
|
||||
var child = elInsertLocation.children[j];
|
||||
if (child.type === 'tag') {
|
||||
elInsertLocation = child;
|
||||
j = 0;
|
||||
}
|
||||
else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
if (elInsertLocation)
|
||||
this._make(elInsertLocation).append(this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
exports.wrapAll = wrapAll;
|
||||
/* eslint-disable jsdoc/check-param-names*/
|
||||
/**
|
||||
* Insert content next to each element in the set of matched elements.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').after('<li class="plum">Plum</li>');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param content - HTML string, DOM element, array of DOM elements or Cheerio
|
||||
* to insert after each element in the set of matched elements.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/after/}
|
||||
*/
|
||||
function after() {
|
||||
var _this = this;
|
||||
var elems = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
elems[_i] = arguments[_i];
|
||||
}
|
||||
var lastIdx = this.length - 1;
|
||||
return utils_1.domEach(this, function (el, i) {
|
||||
var parent = el.parent;
|
||||
if (!htmlparser2_1.DomUtils.hasChildren(el) || !parent) {
|
||||
return;
|
||||
}
|
||||
var siblings = parent.children;
|
||||
var index = siblings.indexOf(el);
|
||||
// If not found, move on
|
||||
/* istanbul ignore next */
|
||||
if (index < 0)
|
||||
return;
|
||||
var domSrc = typeof elems[0] === 'function'
|
||||
? elems[0].call(el, i, static_1.html(el.children))
|
||||
: elems;
|
||||
var dom = _this._makeDomArray(domSrc, i < lastIdx);
|
||||
// Add element after `this` element
|
||||
uniqueSplice(siblings, index + 1, 0, dom, parent);
|
||||
});
|
||||
}
|
||||
exports.after = after;
|
||||
/* eslint-enable jsdoc/check-param-names*/
|
||||
/**
|
||||
* Insert every element in the set of matched elements after the target.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('<li class="plum">Plum</li>').insertAfter('.apple');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param target - Element to insert elements after.
|
||||
* @returns The set of newly inserted elements.
|
||||
* @see {@link https://api.jquery.com/insertAfter/}
|
||||
*/
|
||||
function insertAfter(target) {
|
||||
var _this = this;
|
||||
if (typeof target === 'string') {
|
||||
target = this._make(target);
|
||||
}
|
||||
this.remove();
|
||||
var clones = [];
|
||||
this._makeDomArray(target).forEach(function (el) {
|
||||
var clonedSelf = _this.clone().toArray();
|
||||
var parent = el.parent;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
var siblings = parent.children;
|
||||
var index = siblings.indexOf(el);
|
||||
// If not found, move on
|
||||
/* istanbul ignore next */
|
||||
if (index < 0)
|
||||
return;
|
||||
// Add cloned `this` element(s) after target element
|
||||
uniqueSplice(siblings, index + 1, 0, clonedSelf, parent);
|
||||
clones.push.apply(clones, clonedSelf);
|
||||
});
|
||||
return this._make(clones);
|
||||
}
|
||||
exports.insertAfter = insertAfter;
|
||||
/* eslint-disable jsdoc/check-param-names*/
|
||||
/**
|
||||
* Insert content previous to each element in the set of matched elements.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').before('<li class="plum">Plum</li>');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param content - HTML string, DOM element, array of DOM elements or Cheerio
|
||||
* to insert before each element in the set of matched elements.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/before/}
|
||||
*/
|
||||
function before() {
|
||||
var _this = this;
|
||||
var elems = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
elems[_i] = arguments[_i];
|
||||
}
|
||||
var lastIdx = this.length - 1;
|
||||
return utils_1.domEach(this, function (el, i) {
|
||||
var parent = el.parent;
|
||||
if (!htmlparser2_1.DomUtils.hasChildren(el) || !parent) {
|
||||
return;
|
||||
}
|
||||
var siblings = parent.children;
|
||||
var index = siblings.indexOf(el);
|
||||
// If not found, move on
|
||||
/* istanbul ignore next */
|
||||
if (index < 0)
|
||||
return;
|
||||
var domSrc = typeof elems[0] === 'function'
|
||||
? elems[0].call(el, i, static_1.html(el.children))
|
||||
: elems;
|
||||
var dom = _this._makeDomArray(domSrc, i < lastIdx);
|
||||
// Add element before `el` element
|
||||
uniqueSplice(siblings, index, 0, dom, parent);
|
||||
});
|
||||
}
|
||||
exports.before = before;
|
||||
/* eslint-enable jsdoc/check-param-names*/
|
||||
/**
|
||||
* Insert every element in the set of matched elements before the target.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('<li class="plum">Plum</li>').insertBefore('.apple');
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="plum">Plum</li>
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="pear">Pear</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param target - Element to insert elements before.
|
||||
* @returns The set of newly inserted elements.
|
||||
* @see {@link https://api.jquery.com/insertBefore/}
|
||||
*/
|
||||
function insertBefore(target) {
|
||||
var _this = this;
|
||||
var targetArr = this._make(target);
|
||||
this.remove();
|
||||
var clones = [];
|
||||
utils_1.domEach(targetArr, function (el) {
|
||||
var clonedSelf = _this.clone().toArray();
|
||||
var parent = el.parent;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
var siblings = parent.children;
|
||||
var index = siblings.indexOf(el);
|
||||
// If not found, move on
|
||||
/* istanbul ignore next */
|
||||
if (index < 0)
|
||||
return;
|
||||
// Add cloned `this` element(s) after target element
|
||||
uniqueSplice(siblings, index, 0, clonedSelf, parent);
|
||||
clones.push.apply(clones, clonedSelf);
|
||||
});
|
||||
return this._make(clones);
|
||||
}
|
||||
exports.insertBefore = insertBefore;
|
||||
/**
|
||||
* Removes the set of matched elements from the DOM and all their children.
|
||||
* `selector` filters the set of matched elements to be removed.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').remove();
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param selector - Optional selector for elements to remove.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/remove/}
|
||||
*/
|
||||
function remove(selector) {
|
||||
// Filter if we have selector
|
||||
var elems = selector ? this.filter(selector) : this;
|
||||
utils_1.domEach(elems, function (el) {
|
||||
htmlparser2_1.DomUtils.removeElement(el);
|
||||
el.prev = el.next = el.parent = null;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
exports.remove = remove;
|
||||
/**
|
||||
* Replaces matched elements with `content`.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const plum = $('<li class="plum">Plum</li>');
|
||||
* $('.pear').replaceWith(plum);
|
||||
* $.html();
|
||||
* //=> <ul id="fruits">
|
||||
* // <li class="apple">Apple</li>
|
||||
* // <li class="orange">Orange</li>
|
||||
* // <li class="plum">Plum</li>
|
||||
* // </ul>
|
||||
* ```
|
||||
*
|
||||
* @param content - Replacement for matched elements.
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/replaceWith/}
|
||||
*/
|
||||
function replaceWith(content) {
|
||||
var _this = this;
|
||||
return utils_1.domEach(this, function (el, i) {
|
||||
var parent = el.parent;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
var siblings = parent.children;
|
||||
var cont = typeof content === 'function' ? content.call(el, i, el) : content;
|
||||
var dom = _this._makeDomArray(cont);
|
||||
/*
|
||||
* In the case that `dom` contains nodes that already exist in other
|
||||
* structures, ensure those nodes are properly removed.
|
||||
*/
|
||||
parse_1.update(dom, null);
|
||||
var index = siblings.indexOf(el);
|
||||
// Completely remove old element
|
||||
uniqueSplice(siblings, index, 1, dom, parent);
|
||||
if (!dom.includes(el)) {
|
||||
el.parent = el.prev = el.next = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.replaceWith = replaceWith;
|
||||
/**
|
||||
* Empties an element, removing all its children.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('ul').empty();
|
||||
* $.html();
|
||||
* //=> <ul id="fruits"></ul>
|
||||
* ```
|
||||
*
|
||||
* @returns The instance itself.
|
||||
* @see {@link https://api.jquery.com/empty/}
|
||||
*/
|
||||
function empty() {
|
||||
return utils_1.domEach(this, function (el) {
|
||||
if (!htmlparser2_1.DomUtils.hasChildren(el))
|
||||
return;
|
||||
el.children.forEach(function (child) {
|
||||
child.next = child.prev = child.parent = null;
|
||||
});
|
||||
el.children.length = 0;
|
||||
});
|
||||
}
|
||||
exports.empty = empty;
|
||||
function html(str) {
|
||||
if (str === undefined) {
|
||||
var el = this[0];
|
||||
if (!el || !htmlparser2_1.DomUtils.hasChildren(el))
|
||||
return null;
|
||||
return static_1.html(el.children, this.options);
|
||||
}
|
||||
// Keep main options unchanged
|
||||
var opts = tslib_1.__assign(tslib_1.__assign({}, this.options), { context: null });
|
||||
return utils_1.domEach(this, function (el) {
|
||||
if (!htmlparser2_1.DomUtils.hasChildren(el))
|
||||
return;
|
||||
el.children.forEach(function (child) {
|
||||
child.next = child.prev = child.parent = null;
|
||||
});
|
||||
opts.context = el;
|
||||
var content = utils_1.isCheerio(str)
|
||||
? str.toArray()
|
||||
: parse_1.default("" + str, opts, false).children;
|
||||
parse_1.update(content, el);
|
||||
});
|
||||
}
|
||||
exports.html = html;
|
||||
/**
|
||||
* Turns the collection to a string. Alias for `.html()`.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @returns The rendered document.
|
||||
*/
|
||||
function toString() {
|
||||
return static_1.html(this, this.options);
|
||||
}
|
||||
exports.toString = toString;
|
||||
function text(str) {
|
||||
var _this = this;
|
||||
// If `str` is undefined, act as a "getter"
|
||||
if (str === undefined) {
|
||||
return static_1.text(this);
|
||||
}
|
||||
if (typeof str === 'function') {
|
||||
// Function support
|
||||
return utils_1.domEach(this, function (el, i) {
|
||||
text.call(_this._make(el), str.call(el, i, static_1.text([el])));
|
||||
});
|
||||
}
|
||||
// Append text node to each selected elements
|
||||
return utils_1.domEach(this, function (el) {
|
||||
if (!htmlparser2_1.DomUtils.hasChildren(el))
|
||||
return;
|
||||
el.children.forEach(function (child) {
|
||||
child.next = child.prev = child.parent = null;
|
||||
});
|
||||
var textNode = new domhandler_2.Text(str);
|
||||
parse_1.update(textNode, el);
|
||||
});
|
||||
}
|
||||
exports.text = text;
|
||||
/**
|
||||
* Clone the cheerio object.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const moreFruit = $('#fruits').clone();
|
||||
* ```
|
||||
*
|
||||
* @returns The cloned object.
|
||||
* @see {@link https://api.jquery.com/clone/}
|
||||
*/
|
||||
function clone() {
|
||||
return this._make(utils_1.cloneDom(this.get()));
|
||||
}
|
||||
exports.clone = clone;
|
||||
644
book/node_modules/juice/node_modules/cheerio/lib/api/traversing.d.ts
generated
vendored
Normal file
644
book/node_modules/juice/node_modules/cheerio/lib/api/traversing.d.ts
generated
vendored
Normal file
@@ -0,0 +1,644 @@
|
||||
/**
|
||||
* Methods for traversing the DOM structure.
|
||||
*
|
||||
* @module cheerio/traversing
|
||||
*/
|
||||
import { Node, Element, Document } from 'domhandler';
|
||||
import type { Cheerio } from '../cheerio';
|
||||
import type { AcceptedFilters } from '../types';
|
||||
/**
|
||||
* Get the descendants of each element in the current set of matched elements,
|
||||
* filtered by a selector, jQuery object, or element.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('#fruits').find('li').length;
|
||||
* //=> 3
|
||||
* $('#fruits').find($('.apple')).length;
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param selectorOrHaystack - Element to look for.
|
||||
* @returns The found elements.
|
||||
* @see {@link https://api.jquery.com/find/}
|
||||
*/
|
||||
export declare function find<T extends Node>(this: Cheerio<T>, selectorOrHaystack?: string | Cheerio<Element> | Element): Cheerio<Element>;
|
||||
/**
|
||||
* Get the parent of each element in the current set of matched elements,
|
||||
* optionally filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').parent().attr('id');
|
||||
* //=> fruits
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for parent.
|
||||
* @returns The parents.
|
||||
* @see {@link https://api.jquery.com/parent/}
|
||||
*/
|
||||
export declare const parent: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* Get a set of parents filtered by `selector` of each element in the current
|
||||
* set of match elements.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.orange').parents().length;
|
||||
* //=> 2
|
||||
* $('.orange').parents('#fruits').length;
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for parents.
|
||||
* @returns The parents.
|
||||
* @see {@link https://api.jquery.com/parents/}
|
||||
*/
|
||||
export declare const parents: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* Get the ancestors of each element in the current set of matched elements, up
|
||||
* to but not including the element matched by the selector, DOM node, or cheerio object.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.orange').parentsUntil('#food').length;
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param selector - Selector for element to stop at.
|
||||
* @param filterSelector - Optional filter for parents.
|
||||
* @returns The parents.
|
||||
* @see {@link https://api.jquery.com/parentsUntil/}
|
||||
*/
|
||||
export declare const parentsUntil: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | null | undefined, filterSelector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* For each element in the set, get the first element that matches the selector
|
||||
* by testing the element itself and traversing up through its ancestors in the DOM tree.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.orange').closest();
|
||||
* //=> []
|
||||
*
|
||||
* $('.orange').closest('.apple');
|
||||
* // => []
|
||||
*
|
||||
* $('.orange').closest('li');
|
||||
* //=> [<li class="orange">Orange</li>]
|
||||
*
|
||||
* $('.orange').closest('#fruits');
|
||||
* //=> [<ul id="fruits"> ... </ul>]
|
||||
* ```
|
||||
*
|
||||
* @param selector - Selector for the element to find.
|
||||
* @returns The closest nodes.
|
||||
* @see {@link https://api.jquery.com/closest/}
|
||||
*/
|
||||
export declare function closest<T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Node>): Cheerio<Node>;
|
||||
/**
|
||||
* Gets the next sibling of the first selected element, optionally filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').next().hasClass('orange');
|
||||
* //=> true
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for sibling.
|
||||
* @returns The next nodes.
|
||||
* @see {@link https://api.jquery.com/next/}
|
||||
*/
|
||||
export declare const next: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* Gets all the following siblings of the first selected element, optionally
|
||||
* filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').nextAll();
|
||||
* //=> [<li class="orange">Orange</li>, <li class="pear">Pear</li>]
|
||||
* $('.apple').nextAll('.orange');
|
||||
* //=> [<li class="orange">Orange</li>]
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for siblings.
|
||||
* @returns The next nodes.
|
||||
* @see {@link https://api.jquery.com/nextAll/}
|
||||
*/
|
||||
export declare const nextAll: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* Gets all the following siblings up to but not including the element matched
|
||||
* by the selector, optionally filtered by another selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').nextUntil('.pear');
|
||||
* //=> [<li class="orange">Orange</li>]
|
||||
* ```
|
||||
*
|
||||
* @param selector - Selector for element to stop at.
|
||||
* @param filterSelector - If specified filter for siblings.
|
||||
* @returns The next nodes.
|
||||
* @see {@link https://api.jquery.com/nextUntil/}
|
||||
*/
|
||||
export declare const nextUntil: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | null | undefined, filterSelector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* Gets the previous sibling of the first selected element optionally filtered
|
||||
* by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.orange').prev().hasClass('apple');
|
||||
* //=> true
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for siblings.
|
||||
* @returns The previous nodes.
|
||||
* @see {@link https://api.jquery.com/prev/}
|
||||
*/
|
||||
export declare const prev: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* Gets all the preceding siblings of the first selected element, optionally
|
||||
* filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').prevAll();
|
||||
* //=> [<li class="orange">Orange</li>, <li class="apple">Apple</li>]
|
||||
*
|
||||
* $('.pear').prevAll('.orange');
|
||||
* //=> [<li class="orange">Orange</li>]
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for siblings.
|
||||
* @returns The previous nodes.
|
||||
* @see {@link https://api.jquery.com/prevAll/}
|
||||
*/
|
||||
export declare const prevAll: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* Gets all the preceding siblings up to but not including the element matched
|
||||
* by the selector, optionally filtered by another selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').prevUntil('.apple');
|
||||
* //=> [<li class="orange">Orange</li>]
|
||||
* ```
|
||||
*
|
||||
* @param selector - Selector for element to stop at.
|
||||
* @param filterSelector - If specified filter for siblings.
|
||||
* @returns The previous nodes.
|
||||
* @see {@link https://api.jquery.com/prevUntil/}
|
||||
*/
|
||||
export declare const prevUntil: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | null | undefined, filterSelector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* Get the siblings of each element (excluding the element) in the set of
|
||||
* matched elements, optionally filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').siblings().length;
|
||||
* //=> 2
|
||||
*
|
||||
* $('.pear').siblings('.orange').length;
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for siblings.
|
||||
* @returns The siblings.
|
||||
* @see {@link https://api.jquery.com/siblings/}
|
||||
*/
|
||||
export declare const siblings: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* Gets the children of the first selected element.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('#fruits').children().length;
|
||||
* //=> 3
|
||||
*
|
||||
* $('#fruits').children('.pear').text();
|
||||
* //=> Pear
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for children.
|
||||
* @returns The children.
|
||||
* @see {@link https://api.jquery.com/children/}
|
||||
*/
|
||||
export declare const children: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>;
|
||||
/**
|
||||
* Gets the children of each element in the set of matched elements, including
|
||||
* text and comment nodes.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('#fruits').contents().length;
|
||||
* //=> 3
|
||||
* ```
|
||||
*
|
||||
* @returns The children.
|
||||
* @see {@link https://api.jquery.com/contents/}
|
||||
*/
|
||||
export declare function contents<T extends Node>(this: Cheerio<T>): Cheerio<Node>;
|
||||
/**
|
||||
* Iterates over a cheerio object, executing a function for each matched
|
||||
* element. When the callback is fired, the function is fired in the context of
|
||||
* the DOM element, so `this` refers to the current element, which is equivalent
|
||||
* to the function parameter `element`. To break out of the `each` loop early,
|
||||
* return with `false`.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const fruits = [];
|
||||
*
|
||||
* $('li').each(function (i, elem) {
|
||||
* fruits[i] = $(this).text();
|
||||
* });
|
||||
*
|
||||
* fruits.join(', ');
|
||||
* //=> Apple, Orange, Pear
|
||||
* ```
|
||||
*
|
||||
* @param fn - Function to execute.
|
||||
* @returns The instance itself, useful for chaining.
|
||||
* @see {@link https://api.jquery.com/each/}
|
||||
*/
|
||||
export declare function each<T>(this: Cheerio<T>, fn: (this: T, i: number, el: T) => void | boolean): Cheerio<T>;
|
||||
/**
|
||||
* Pass each element in the current matched set through a function, producing a
|
||||
* new Cheerio object containing the return values. The function can return an
|
||||
* individual data item or an array of data items to be inserted into the
|
||||
* resulting set. If an array is returned, the elements inside the array are
|
||||
* inserted into the set. If the function returns null or undefined, no element
|
||||
* will be inserted.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li')
|
||||
* .map(function (i, el) {
|
||||
* // this === el
|
||||
* return $(this).text();
|
||||
* })
|
||||
* .toArray()
|
||||
* .join(' ');
|
||||
* //=> "apple orange pear"
|
||||
* ```
|
||||
*
|
||||
* @param fn - Function to execute.
|
||||
* @returns The mapped elements, wrapped in a Cheerio collection.
|
||||
* @see {@link https://api.jquery.com/map/}
|
||||
*/
|
||||
export declare function map<T, M>(this: Cheerio<T>, fn: (this: T, i: number, el: T) => M[] | M | null | undefined): Cheerio<M>;
|
||||
/**
|
||||
* Iterates over a cheerio object, reducing the set of selector elements to
|
||||
* those that match the selector or pass the function's test.
|
||||
*
|
||||
* This is the definition for using type guards; have a look below for other
|
||||
* ways to invoke this method. The function is executed in the context of the
|
||||
* selected element, so `this` refers to the current element.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example <caption>Function</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('li')
|
||||
* .filter(function (i, el) {
|
||||
* // this === el
|
||||
* return $(this).attr('class') === 'orange';
|
||||
* })
|
||||
* .attr('class'); //=> orange
|
||||
* ```
|
||||
*
|
||||
* @param match - Value to look for, following the rules above.
|
||||
* @returns The filtered collection.
|
||||
* @see {@link https://api.jquery.com/filter/}
|
||||
*/
|
||||
export declare function filter<T, S extends T>(this: Cheerio<T>, match: (this: T, index: number, value: T) => value is S): Cheerio<S>;
|
||||
/**
|
||||
* Iterates over a cheerio object, reducing the set of selector elements to
|
||||
* those that match the selector or pass the function's test.
|
||||
*
|
||||
* - When a Cheerio selection is specified, return only the elements contained in
|
||||
* that selection.
|
||||
* - When an element is specified, return only that element (if it is contained in
|
||||
* the original selection).
|
||||
* - If using the function method, the function is executed in the context of the
|
||||
* selected element, so `this` refers to the current element.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example <caption>Selector</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('li').filter('.orange').attr('class');
|
||||
* //=> orange
|
||||
* ```
|
||||
*
|
||||
* @example <caption>Function</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('li')
|
||||
* .filter(function (i, el) {
|
||||
* // this === el
|
||||
* return $(this).attr('class') === 'orange';
|
||||
* })
|
||||
* .attr('class'); //=> orange
|
||||
* ```
|
||||
*
|
||||
* @param match - Value to look for, following the rules above. See
|
||||
* {@link AcceptedFilters}.
|
||||
* @returns The filtered collection.
|
||||
* @see {@link https://api.jquery.com/filter/}
|
||||
*/
|
||||
export declare function filter<T, S extends AcceptedFilters<T>>(this: Cheerio<T>, match: S): Cheerio<S extends string ? Element : T>;
|
||||
export declare function filterArray<T>(nodes: T[], match: AcceptedFilters<T>, xmlMode?: boolean, root?: Document): Element[] | T[];
|
||||
/**
|
||||
* Checks the current list of elements and returns `true` if *any* of the
|
||||
* elements match the selector. If using an element or Cheerio selection,
|
||||
* returns `true` if *any* of the elements match. If using a predicate function,
|
||||
* the function is executed in the context of the selected element, so `this`
|
||||
* refers to the current element.
|
||||
*
|
||||
* @category Attributes
|
||||
* @param selector - Selector for the selection.
|
||||
* @returns Whether or not the selector matches an element of the instance.
|
||||
* @see {@link https://api.jquery.com/is/}
|
||||
*/
|
||||
export declare function is<T>(this: Cheerio<T>, selector?: AcceptedFilters<T>): boolean;
|
||||
/**
|
||||
* Remove elements from the set of matched elements. Given a Cheerio object that
|
||||
* represents a set of DOM elements, the `.not()` method constructs a new
|
||||
* Cheerio object from a subset of the matching elements. The supplied selector
|
||||
* is tested against each element; the elements that don't match the selector
|
||||
* will be included in the result.
|
||||
*
|
||||
* The `.not()` method can take a function as its argument in the same way that
|
||||
* `.filter()` does. Elements for which the function returns `true` are excluded
|
||||
* from the filtered set; all other elements are included.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example <caption>Selector</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('li').not('.apple').length;
|
||||
* //=> 2
|
||||
* ```
|
||||
*
|
||||
* @example <caption>Function</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('li').not(function (i, el) {
|
||||
* // this === el
|
||||
* return $(this).attr('class') === 'orange';
|
||||
* }).length; //=> 2
|
||||
* ```
|
||||
*
|
||||
* @param match - Value to look for, following the rules above.
|
||||
* @param container - Optional node to filter instead.
|
||||
* @returns The filtered collection.
|
||||
* @see {@link https://api.jquery.com/not/}
|
||||
*/
|
||||
export declare function not<T extends Node>(this: Cheerio<T>, match: AcceptedFilters<T>): Cheerio<T>;
|
||||
/**
|
||||
* Filters the set of matched elements to only those which have the given DOM
|
||||
* element as a descendant or which have a descendant that matches the given
|
||||
* selector. Equivalent to `.filter(':has(selector)')`.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example <caption>Selector</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('ul').has('.pear').attr('id');
|
||||
* //=> fruits
|
||||
* ```
|
||||
*
|
||||
* @example <caption>Element</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('ul').has($('.pear')[0]).attr('id');
|
||||
* //=> fruits
|
||||
* ```
|
||||
*
|
||||
* @param selectorOrHaystack - Element to look for.
|
||||
* @returns The filtered collection.
|
||||
* @see {@link https://api.jquery.com/has/}
|
||||
*/
|
||||
export declare function has(this: Cheerio<Node | Element>, selectorOrHaystack: string | Cheerio<Element> | Element): Cheerio<Node | Element>;
|
||||
/**
|
||||
* Will select the first element of a cheerio object.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('#fruits').children().first().text();
|
||||
* //=> Apple
|
||||
* ```
|
||||
*
|
||||
* @returns The first element.
|
||||
* @see {@link https://api.jquery.com/first/}
|
||||
*/
|
||||
export declare function first<T extends Node>(this: Cheerio<T>): Cheerio<T>;
|
||||
/**
|
||||
* Will select the last element of a cheerio object.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('#fruits').children().last().text();
|
||||
* //=> Pear
|
||||
* ```
|
||||
*
|
||||
* @returns The last element.
|
||||
* @see {@link https://api.jquery.com/last/}
|
||||
*/
|
||||
export declare function last<T>(this: Cheerio<T>): Cheerio<T>;
|
||||
/**
|
||||
* Reduce the set of matched elements to the one at the specified index. Use
|
||||
* `.eq(-i)` to count backwards from the last selected element.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').eq(0).text();
|
||||
* //=> Apple
|
||||
*
|
||||
* $('li').eq(-1).text();
|
||||
* //=> Pear
|
||||
* ```
|
||||
*
|
||||
* @param i - Index of the element to select.
|
||||
* @returns The element at the `i`th position.
|
||||
* @see {@link https://api.jquery.com/eq/}
|
||||
*/
|
||||
export declare function eq<T>(this: Cheerio<T>, i: number): Cheerio<T>;
|
||||
/**
|
||||
* Retrieve one of the elements matched by the Cheerio object, at the `i`th position.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').get(0).tagName;
|
||||
* //=> li
|
||||
* ```
|
||||
*
|
||||
* @param i - Element to retrieve.
|
||||
* @returns The element at the `i`th position.
|
||||
* @see {@link https://api.jquery.com/get/}
|
||||
*/
|
||||
export declare function get<T>(this: Cheerio<T>, i: number): T;
|
||||
/**
|
||||
* Retrieve all elements matched by the Cheerio object, as an array.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').get().length;
|
||||
* //=> 3
|
||||
* ```
|
||||
*
|
||||
* @returns All elements matched by the Cheerio object.
|
||||
* @see {@link https://api.jquery.com/get/}
|
||||
*/
|
||||
export declare function get<T>(this: Cheerio<T>): T[];
|
||||
/**
|
||||
* Retrieve all the DOM elements contained in the jQuery set as an array.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').toArray();
|
||||
* //=> [ {...}, {...}, {...} ]
|
||||
* ```
|
||||
*
|
||||
* @returns The contained items.
|
||||
*/
|
||||
export declare function toArray<T>(this: Cheerio<T>): T[];
|
||||
/**
|
||||
* Search for a given element from among the matched elements.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').index();
|
||||
* //=> 2 $('.orange').index('li');
|
||||
* //=> 1
|
||||
* $('.apple').index($('#fruit, li'));
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param selectorOrNeedle - Element to look for.
|
||||
* @returns The index of the element.
|
||||
* @see {@link https://api.jquery.com/index/}
|
||||
*/
|
||||
export declare function index<T extends Node>(this: Cheerio<T>, selectorOrNeedle?: string | Cheerio<Node> | Node): number;
|
||||
/**
|
||||
* Gets the elements matching the specified range (0-based position).
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').slice(1).eq(0).text();
|
||||
* //=> 'Orange'
|
||||
*
|
||||
* $('li').slice(1, 2).length;
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param start - An position at which the elements begin to be selected. If
|
||||
* negative, it indicates an offset from the end of the set.
|
||||
* @param end - An position at which the elements stop being selected. If
|
||||
* negative, it indicates an offset from the end of the set. If omitted, the
|
||||
* range continues until the end of the set.
|
||||
* @returns The elements matching the specified range.
|
||||
* @see {@link https://api.jquery.com/slice/}
|
||||
*/
|
||||
export declare function slice<T>(this: Cheerio<T>, start?: number, end?: number): Cheerio<T>;
|
||||
/**
|
||||
* End the most recent filtering operation in the current chain and return the
|
||||
* set of matched elements to its previous state.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').eq(0).end().length;
|
||||
* //=> 3
|
||||
* ```
|
||||
*
|
||||
* @returns The previous state of the set of matched elements.
|
||||
* @see {@link https://api.jquery.com/end/}
|
||||
*/
|
||||
export declare function end<T>(this: Cheerio<T>): Cheerio<Node>;
|
||||
/**
|
||||
* Add elements to the set of matched elements.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').add('.orange').length;
|
||||
* //=> 2
|
||||
* ```
|
||||
*
|
||||
* @param other - Elements to add.
|
||||
* @param context - Optionally the context of the new selection.
|
||||
* @returns The combined set.
|
||||
* @see {@link https://api.jquery.com/add/}
|
||||
*/
|
||||
export declare function add<S extends Node, T extends Node>(this: Cheerio<T>, other: string | Cheerio<S> | S | S[], context?: Cheerio<S> | string): Cheerio<S | T>;
|
||||
/**
|
||||
* Add the previous set of elements on the stack to the current set, optionally
|
||||
* filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').eq(0).addBack('.orange').length;
|
||||
* //=> 2
|
||||
* ```
|
||||
*
|
||||
* @param selector - Selector for the elements to add.
|
||||
* @returns The combined set.
|
||||
* @see {@link https://api.jquery.com/addBack/}
|
||||
*/
|
||||
export declare function addBack<T extends Node>(this: Cheerio<T>, selector?: string): Cheerio<Node>;
|
||||
//# sourceMappingURL=traversing.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/api/traversing.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/api/traversing.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"traversing.d.ts","sourceRoot":"","sources":["../../src/api/traversing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAA2B,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAK1C,OAAO,KAAK,EAAkB,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,CA4BlB;AA2HD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,MAAM,yFAvHZ,QAAQ,OAAO,CA0HrB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,OAAO,yFA9Ib,QAAQ,OAAO,CAyJrB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY,uJA3FpB,QAAQ,OAAO,CA+FnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,IAAI,EACpC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,QAAQ,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CAyBf;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,IAAI,yFAxPV,QAAQ,OAAO,CAwPyD,CAAC;AAEhF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,OAAO,yFA5Qb,QAAQ,OAAO,CAmRD,CAAC;AAEtB;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,SAAS,uJArNjB,QAAQ,OAAO,CAwNnB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,IAAI,yFA3TV,QAAQ,OAAO,CA2TyD,CAAC;AAEhF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,OAAO,yFAhVb,QAAQ,OAAO,CAuVD,CAAC;AAEtB;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,SAAS,uJAzRjB,QAAQ,OAAO,CA4RnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,QAAQ,yFAlYd,QAAQ,OAAO,CAwYrB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,QAAQ,yFA5Zd,QAAQ,OAAO,CA+ZrB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxE;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACpB,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,GAChD,OAAO,CAAC,CAAC,CAAC,CAKZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EACtB,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,GAC5D,OAAO,CAAC,CAAC,CAAC,CAUZ;AAsBD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,EACnC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,GACtD,OAAO,CAAC,CAAC,CAAC,CAAC;AACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EACpD,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,KAAK,EAAE,CAAC,GACP,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC;AAU3C,wBAAgB,WAAW,CAAC,CAAC,EAC3B,KAAK,EAAE,CAAC,EAAE,EACV,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EACzB,OAAO,CAAC,EAAE,OAAO,EACjB,IAAI,CAAC,EAAE,QAAQ,GACd,OAAO,EAAE,GAAG,CAAC,EAAE,CAIjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAClB,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,QAAQ,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAC5B,OAAO,CAWT;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC,CAAC,CAAC,CAYZ;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,GAAG,CACjB,IAAI,EAAE,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,EAC7B,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GACtD,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,CAOzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAElE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEpD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAQ7D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;AACvD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;AAQ9C;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAEhD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,IAAI,EAClC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAC/C,MAAM,CAkBR;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACrB,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;;;;;;;;;;;;;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"}
|
||||
866
book/node_modules/juice/node_modules/cheerio/lib/api/traversing.js
generated
vendored
Normal file
866
book/node_modules/juice/node_modules/cheerio/lib/api/traversing.js
generated
vendored
Normal file
@@ -0,0 +1,866 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Methods for traversing the DOM structure.
|
||||
*
|
||||
* @module cheerio/traversing
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.addBack = exports.add = exports.end = exports.slice = exports.index = exports.toArray = exports.get = exports.eq = exports.last = exports.first = exports.has = exports.not = exports.is = exports.filterArray = exports.filter = exports.map = exports.each = exports.contents = exports.children = exports.siblings = exports.prevUntil = exports.prevAll = exports.prev = exports.nextUntil = exports.nextAll = exports.next = exports.closest = exports.parentsUntil = exports.parents = exports.parent = exports.find = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var domhandler_1 = require("domhandler");
|
||||
var select = tslib_1.__importStar(require("cheerio-select"));
|
||||
var utils_1 = require("../utils");
|
||||
var static_1 = require("../static");
|
||||
var htmlparser2_1 = require("htmlparser2");
|
||||
var uniqueSort = htmlparser2_1.DomUtils.uniqueSort;
|
||||
var reSiblingSelector = /^\s*[~+]/;
|
||||
/**
|
||||
* Get the descendants of each element in the current set of matched elements,
|
||||
* filtered by a selector, jQuery object, or element.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('#fruits').find('li').length;
|
||||
* //=> 3
|
||||
* $('#fruits').find($('.apple')).length;
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param selectorOrHaystack - Element to look for.
|
||||
* @returns The found elements.
|
||||
* @see {@link https://api.jquery.com/find/}
|
||||
*/
|
||||
function find(selectorOrHaystack) {
|
||||
var _a;
|
||||
if (!selectorOrHaystack) {
|
||||
return this._make([]);
|
||||
}
|
||||
var context = this.toArray();
|
||||
if (typeof selectorOrHaystack !== 'string') {
|
||||
var haystack = utils_1.isCheerio(selectorOrHaystack)
|
||||
? selectorOrHaystack.toArray()
|
||||
: [selectorOrHaystack];
|
||||
return this._make(haystack.filter(function (elem) { return context.some(function (node) { return static_1.contains(node, elem); }); }));
|
||||
}
|
||||
var elems = reSiblingSelector.test(selectorOrHaystack)
|
||||
? context
|
||||
: this.children().toArray();
|
||||
var options = {
|
||||
context: context,
|
||||
root: (_a = this._root) === null || _a === void 0 ? void 0 : _a[0],
|
||||
xmlMode: this.options.xmlMode,
|
||||
};
|
||||
return this._make(select.select(selectorOrHaystack, elems, options));
|
||||
}
|
||||
exports.find = find;
|
||||
/**
|
||||
* Creates a matcher, using a particular mapping function. Matchers provide a
|
||||
* function that finds elements using a generating function, supporting filtering.
|
||||
*
|
||||
* @private
|
||||
* @param matchMap - Mapping function.
|
||||
* @returns - Function for wrapping generating functions.
|
||||
*/
|
||||
function _getMatcher(matchMap) {
|
||||
return function (fn) {
|
||||
var postFns = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
postFns[_i - 1] = arguments[_i];
|
||||
}
|
||||
return function (selector) {
|
||||
var _a;
|
||||
var matched = matchMap(fn, this);
|
||||
if (selector) {
|
||||
matched = filterArray(matched, selector, this.options.xmlMode, (_a = this._root) === null || _a === void 0 ? void 0 : _a[0]);
|
||||
}
|
||||
return this._make(
|
||||
// Post processing is only necessary if there is more than one element.
|
||||
this.length > 1 && matched.length > 1
|
||||
? postFns.reduce(function (elems, fn) { return fn(elems); }, matched)
|
||||
: matched);
|
||||
};
|
||||
};
|
||||
}
|
||||
/** Matcher that adds multiple elements for each entry in the input. */
|
||||
var _matcher = _getMatcher(function (fn, elems) {
|
||||
var _a;
|
||||
var ret = [];
|
||||
for (var i = 0; i < elems.length; i++) {
|
||||
var value = fn(elems[i]);
|
||||
ret.push(value);
|
||||
}
|
||||
return (_a = new Array()).concat.apply(_a, ret);
|
||||
});
|
||||
/** Matcher that adds at most one element for each entry in the input. */
|
||||
var _singleMatcher = _getMatcher(function (fn, elems) {
|
||||
var ret = [];
|
||||
for (var i = 0; i < elems.length; i++) {
|
||||
var value = fn(elems[i]);
|
||||
if (value !== null) {
|
||||
ret.push(value);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
/**
|
||||
* Matcher that supports traversing until a condition is met.
|
||||
*
|
||||
* @returns A function usable for `*Until` methods.
|
||||
*/
|
||||
function _matchUntil(nextElem) {
|
||||
var postFns = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
postFns[_i - 1] = arguments[_i];
|
||||
}
|
||||
// We use a variable here that is used from within the matcher.
|
||||
var matches = null;
|
||||
var innerMatcher = _getMatcher(function (nextElem, elems) {
|
||||
var matched = [];
|
||||
utils_1.domEach(elems, function (elem) {
|
||||
for (var next_1; (next_1 = nextElem(elem)); elem = next_1) {
|
||||
// FIXME: `matched` might contain duplicates here and the index is too large.
|
||||
if (matches === null || matches === void 0 ? void 0 : matches(next_1, matched.length))
|
||||
break;
|
||||
matched.push(next_1);
|
||||
}
|
||||
});
|
||||
return matched;
|
||||
}).apply(void 0, tslib_1.__spreadArray([nextElem], postFns));
|
||||
return function (selector, filterSelector) {
|
||||
var _this = this;
|
||||
// Override `matches` variable with the new target.
|
||||
matches =
|
||||
typeof selector === 'string'
|
||||
? function (elem) { return select.is(elem, selector, _this.options); }
|
||||
: selector
|
||||
? getFilterFn(selector)
|
||||
: null;
|
||||
var ret = innerMatcher.call(this, filterSelector);
|
||||
// Set `matches` to `null`, so we don't waste memory.
|
||||
matches = null;
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
function _removeDuplicates(elems) {
|
||||
return Array.from(new Set(elems));
|
||||
}
|
||||
/**
|
||||
* Get the parent of each element in the current set of matched elements,
|
||||
* optionally filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').parent().attr('id');
|
||||
* //=> fruits
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for parent.
|
||||
* @returns The parents.
|
||||
* @see {@link https://api.jquery.com/parent/}
|
||||
*/
|
||||
exports.parent = _singleMatcher(function (_a) {
|
||||
var parent = _a.parent;
|
||||
return (parent && !domhandler_1.isDocument(parent) ? parent : null);
|
||||
}, _removeDuplicates);
|
||||
/**
|
||||
* Get a set of parents filtered by `selector` of each element in the current
|
||||
* set of match elements.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.orange').parents().length;
|
||||
* //=> 2
|
||||
* $('.orange').parents('#fruits').length;
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for parents.
|
||||
* @returns The parents.
|
||||
* @see {@link https://api.jquery.com/parents/}
|
||||
*/
|
||||
exports.parents = _matcher(function (elem) {
|
||||
var matched = [];
|
||||
while (elem.parent && !domhandler_1.isDocument(elem.parent)) {
|
||||
matched.push(elem.parent);
|
||||
elem = elem.parent;
|
||||
}
|
||||
return matched;
|
||||
}, uniqueSort, function (elems) { return elems.reverse(); });
|
||||
/**
|
||||
* Get the ancestors of each element in the current set of matched elements, up
|
||||
* to but not including the element matched by the selector, DOM node, or cheerio object.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.orange').parentsUntil('#food').length;
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param selector - Selector for element to stop at.
|
||||
* @param filterSelector - Optional filter for parents.
|
||||
* @returns The parents.
|
||||
* @see {@link https://api.jquery.com/parentsUntil/}
|
||||
*/
|
||||
exports.parentsUntil = _matchUntil(function (_a) {
|
||||
var parent = _a.parent;
|
||||
return (parent && !domhandler_1.isDocument(parent) ? parent : null);
|
||||
}, uniqueSort, function (elems) { return elems.reverse(); });
|
||||
/**
|
||||
* For each element in the set, get the first element that matches the selector
|
||||
* by testing the element itself and traversing up through its ancestors in the DOM tree.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.orange').closest();
|
||||
* //=> []
|
||||
*
|
||||
* $('.orange').closest('.apple');
|
||||
* // => []
|
||||
*
|
||||
* $('.orange').closest('li');
|
||||
* //=> [<li class="orange">Orange</li>]
|
||||
*
|
||||
* $('.orange').closest('#fruits');
|
||||
* //=> [<ul id="fruits"> ... </ul>]
|
||||
* ```
|
||||
*
|
||||
* @param selector - Selector for the element to find.
|
||||
* @returns The closest nodes.
|
||||
* @see {@link https://api.jquery.com/closest/}
|
||||
*/
|
||||
function closest(selector) {
|
||||
var _this = this;
|
||||
var set = [];
|
||||
if (!selector) {
|
||||
return this._make(set);
|
||||
}
|
||||
utils_1.domEach(this, function (elem) {
|
||||
var _a;
|
||||
while (elem && elem.type !== 'root') {
|
||||
if (!selector ||
|
||||
filterArray([elem], selector, _this.options.xmlMode, (_a = _this._root) === null || _a === void 0 ? void 0 : _a[0])
|
||||
.length) {
|
||||
// Do not add duplicate elements to the set
|
||||
if (elem && !set.includes(elem)) {
|
||||
set.push(elem);
|
||||
}
|
||||
break;
|
||||
}
|
||||
elem = elem.parent;
|
||||
}
|
||||
});
|
||||
return this._make(set);
|
||||
}
|
||||
exports.closest = closest;
|
||||
/**
|
||||
* Gets the next sibling of the first selected element, optionally filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').next().hasClass('orange');
|
||||
* //=> true
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for sibling.
|
||||
* @returns The next nodes.
|
||||
* @see {@link https://api.jquery.com/next/}
|
||||
*/
|
||||
exports.next = _singleMatcher(function (elem) { return htmlparser2_1.DomUtils.nextElementSibling(elem); });
|
||||
/**
|
||||
* Gets all the following siblings of the first selected element, optionally
|
||||
* filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').nextAll();
|
||||
* //=> [<li class="orange">Orange</li>, <li class="pear">Pear</li>]
|
||||
* $('.apple').nextAll('.orange');
|
||||
* //=> [<li class="orange">Orange</li>]
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for siblings.
|
||||
* @returns The next nodes.
|
||||
* @see {@link https://api.jquery.com/nextAll/}
|
||||
*/
|
||||
exports.nextAll = _matcher(function (elem) {
|
||||
var matched = [];
|
||||
while (elem.next) {
|
||||
elem = elem.next;
|
||||
if (utils_1.isTag(elem))
|
||||
matched.push(elem);
|
||||
}
|
||||
return matched;
|
||||
}, _removeDuplicates);
|
||||
/**
|
||||
* Gets all the following siblings up to but not including the element matched
|
||||
* by the selector, optionally filtered by another selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').nextUntil('.pear');
|
||||
* //=> [<li class="orange">Orange</li>]
|
||||
* ```
|
||||
*
|
||||
* @param selector - Selector for element to stop at.
|
||||
* @param filterSelector - If specified filter for siblings.
|
||||
* @returns The next nodes.
|
||||
* @see {@link https://api.jquery.com/nextUntil/}
|
||||
*/
|
||||
exports.nextUntil = _matchUntil(function (el) { return htmlparser2_1.DomUtils.nextElementSibling(el); }, _removeDuplicates);
|
||||
/**
|
||||
* Gets the previous sibling of the first selected element optionally filtered
|
||||
* by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.orange').prev().hasClass('apple');
|
||||
* //=> true
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for siblings.
|
||||
* @returns The previous nodes.
|
||||
* @see {@link https://api.jquery.com/prev/}
|
||||
*/
|
||||
exports.prev = _singleMatcher(function (elem) { return htmlparser2_1.DomUtils.prevElementSibling(elem); });
|
||||
/**
|
||||
* Gets all the preceding siblings of the first selected element, optionally
|
||||
* filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').prevAll();
|
||||
* //=> [<li class="orange">Orange</li>, <li class="apple">Apple</li>]
|
||||
*
|
||||
* $('.pear').prevAll('.orange');
|
||||
* //=> [<li class="orange">Orange</li>]
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for siblings.
|
||||
* @returns The previous nodes.
|
||||
* @see {@link https://api.jquery.com/prevAll/}
|
||||
*/
|
||||
exports.prevAll = _matcher(function (elem) {
|
||||
var matched = [];
|
||||
while (elem.prev) {
|
||||
elem = elem.prev;
|
||||
if (utils_1.isTag(elem))
|
||||
matched.push(elem);
|
||||
}
|
||||
return matched;
|
||||
}, _removeDuplicates);
|
||||
/**
|
||||
* Gets all the preceding siblings up to but not including the element matched
|
||||
* by the selector, optionally filtered by another selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').prevUntil('.apple');
|
||||
* //=> [<li class="orange">Orange</li>]
|
||||
* ```
|
||||
*
|
||||
* @param selector - Selector for element to stop at.
|
||||
* @param filterSelector - If specified filter for siblings.
|
||||
* @returns The previous nodes.
|
||||
* @see {@link https://api.jquery.com/prevUntil/}
|
||||
*/
|
||||
exports.prevUntil = _matchUntil(function (el) { return htmlparser2_1.DomUtils.prevElementSibling(el); }, _removeDuplicates);
|
||||
/**
|
||||
* Get the siblings of each element (excluding the element) in the set of
|
||||
* matched elements, optionally filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').siblings().length;
|
||||
* //=> 2
|
||||
*
|
||||
* $('.pear').siblings('.orange').length;
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for siblings.
|
||||
* @returns The siblings.
|
||||
* @see {@link https://api.jquery.com/siblings/}
|
||||
*/
|
||||
exports.siblings = _matcher(function (elem) {
|
||||
return htmlparser2_1.DomUtils.getSiblings(elem).filter(function (el) { return utils_1.isTag(el) && el !== elem; });
|
||||
}, uniqueSort);
|
||||
/**
|
||||
* Gets the children of the first selected element.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('#fruits').children().length;
|
||||
* //=> 3
|
||||
*
|
||||
* $('#fruits').children('.pear').text();
|
||||
* //=> Pear
|
||||
* ```
|
||||
*
|
||||
* @param selector - If specified filter for children.
|
||||
* @returns The children.
|
||||
* @see {@link https://api.jquery.com/children/}
|
||||
*/
|
||||
exports.children = _matcher(function (elem) { return htmlparser2_1.DomUtils.getChildren(elem).filter(utils_1.isTag); }, _removeDuplicates);
|
||||
/**
|
||||
* Gets the children of each element in the set of matched elements, including
|
||||
* text and comment nodes.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('#fruits').contents().length;
|
||||
* //=> 3
|
||||
* ```
|
||||
*
|
||||
* @returns The children.
|
||||
* @see {@link https://api.jquery.com/contents/}
|
||||
*/
|
||||
function contents() {
|
||||
var elems = this.toArray().reduce(function (newElems, elem) {
|
||||
return domhandler_1.hasChildren(elem) ? newElems.concat(elem.children) : newElems;
|
||||
}, []);
|
||||
return this._make(elems);
|
||||
}
|
||||
exports.contents = contents;
|
||||
/**
|
||||
* Iterates over a cheerio object, executing a function for each matched
|
||||
* element. When the callback is fired, the function is fired in the context of
|
||||
* the DOM element, so `this` refers to the current element, which is equivalent
|
||||
* to the function parameter `element`. To break out of the `each` loop early,
|
||||
* return with `false`.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* const fruits = [];
|
||||
*
|
||||
* $('li').each(function (i, elem) {
|
||||
* fruits[i] = $(this).text();
|
||||
* });
|
||||
*
|
||||
* fruits.join(', ');
|
||||
* //=> Apple, Orange, Pear
|
||||
* ```
|
||||
*
|
||||
* @param fn - Function to execute.
|
||||
* @returns The instance itself, useful for chaining.
|
||||
* @see {@link https://api.jquery.com/each/}
|
||||
*/
|
||||
function each(fn) {
|
||||
var i = 0;
|
||||
var len = this.length;
|
||||
while (i < len && fn.call(this[i], i, this[i]) !== false)
|
||||
++i;
|
||||
return this;
|
||||
}
|
||||
exports.each = each;
|
||||
/**
|
||||
* Pass each element in the current matched set through a function, producing a
|
||||
* new Cheerio object containing the return values. The function can return an
|
||||
* individual data item or an array of data items to be inserted into the
|
||||
* resulting set. If an array is returned, the elements inside the array are
|
||||
* inserted into the set. If the function returns null or undefined, no element
|
||||
* will be inserted.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li')
|
||||
* .map(function (i, el) {
|
||||
* // this === el
|
||||
* return $(this).text();
|
||||
* })
|
||||
* .toArray()
|
||||
* .join(' ');
|
||||
* //=> "apple orange pear"
|
||||
* ```
|
||||
*
|
||||
* @param fn - Function to execute.
|
||||
* @returns The mapped elements, wrapped in a Cheerio collection.
|
||||
* @see {@link https://api.jquery.com/map/}
|
||||
*/
|
||||
function map(fn) {
|
||||
var elems = [];
|
||||
for (var i = 0; i < this.length; i++) {
|
||||
var el = this[i];
|
||||
var val = fn.call(el, i, el);
|
||||
if (val != null) {
|
||||
elems = elems.concat(val);
|
||||
}
|
||||
}
|
||||
return this._make(elems);
|
||||
}
|
||||
exports.map = map;
|
||||
/**
|
||||
* Creates a function to test if a filter is matched.
|
||||
*
|
||||
* @param match - A filter.
|
||||
* @returns A function that determines if a filter has been matched.
|
||||
*/
|
||||
function getFilterFn(match) {
|
||||
if (typeof match === 'function') {
|
||||
return function (el, i) { return match.call(el, i, el); };
|
||||
}
|
||||
if (utils_1.isCheerio(match)) {
|
||||
return function (el) { return Array.prototype.includes.call(match, el); };
|
||||
}
|
||||
return function (el) {
|
||||
return match === el;
|
||||
};
|
||||
}
|
||||
function filter(match) {
|
||||
var _a;
|
||||
return this._make(filterArray(this.toArray(), match, this.options.xmlMode, (_a = this._root) === null || _a === void 0 ? void 0 : _a[0]));
|
||||
}
|
||||
exports.filter = filter;
|
||||
function filterArray(nodes, match, xmlMode, root) {
|
||||
return typeof match === 'string'
|
||||
? select.filter(match, nodes, { xmlMode: xmlMode, root: root })
|
||||
: nodes.filter(getFilterFn(match));
|
||||
}
|
||||
exports.filterArray = filterArray;
|
||||
/**
|
||||
* Checks the current list of elements and returns `true` if *any* of the
|
||||
* elements match the selector. If using an element or Cheerio selection,
|
||||
* returns `true` if *any* of the elements match. If using a predicate function,
|
||||
* the function is executed in the context of the selected element, so `this`
|
||||
* refers to the current element.
|
||||
*
|
||||
* @category Attributes
|
||||
* @param selector - Selector for the selection.
|
||||
* @returns Whether or not the selector matches an element of the instance.
|
||||
* @see {@link https://api.jquery.com/is/}
|
||||
*/
|
||||
function is(selector) {
|
||||
var nodes = this.toArray();
|
||||
return typeof selector === 'string'
|
||||
? select.some(nodes.filter(utils_1.isTag), selector, this.options)
|
||||
: selector
|
||||
? nodes.some(getFilterFn(selector))
|
||||
: false;
|
||||
}
|
||||
exports.is = is;
|
||||
/**
|
||||
* Remove elements from the set of matched elements. Given a Cheerio object that
|
||||
* represents a set of DOM elements, the `.not()` method constructs a new
|
||||
* Cheerio object from a subset of the matching elements. The supplied selector
|
||||
* is tested against each element; the elements that don't match the selector
|
||||
* will be included in the result.
|
||||
*
|
||||
* The `.not()` method can take a function as its argument in the same way that
|
||||
* `.filter()` does. Elements for which the function returns `true` are excluded
|
||||
* from the filtered set; all other elements are included.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example <caption>Selector</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('li').not('.apple').length;
|
||||
* //=> 2
|
||||
* ```
|
||||
*
|
||||
* @example <caption>Function</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('li').not(function (i, el) {
|
||||
* // this === el
|
||||
* return $(this).attr('class') === 'orange';
|
||||
* }).length; //=> 2
|
||||
* ```
|
||||
*
|
||||
* @param match - Value to look for, following the rules above.
|
||||
* @param container - Optional node to filter instead.
|
||||
* @returns The filtered collection.
|
||||
* @see {@link https://api.jquery.com/not/}
|
||||
*/
|
||||
function not(match) {
|
||||
var nodes = this.toArray();
|
||||
if (typeof match === 'string') {
|
||||
var matches_1 = new Set(select.filter(match, nodes, this.options));
|
||||
nodes = nodes.filter(function (el) { return !matches_1.has(el); });
|
||||
}
|
||||
else {
|
||||
var filterFn_1 = getFilterFn(match);
|
||||
nodes = nodes.filter(function (el, i) { return !filterFn_1(el, i); });
|
||||
}
|
||||
return this._make(nodes);
|
||||
}
|
||||
exports.not = not;
|
||||
/**
|
||||
* Filters the set of matched elements to only those which have the given DOM
|
||||
* element as a descendant or which have a descendant that matches the given
|
||||
* selector. Equivalent to `.filter(':has(selector)')`.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example <caption>Selector</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('ul').has('.pear').attr('id');
|
||||
* //=> fruits
|
||||
* ```
|
||||
*
|
||||
* @example <caption>Element</caption>
|
||||
*
|
||||
* ```js
|
||||
* $('ul').has($('.pear')[0]).attr('id');
|
||||
* //=> fruits
|
||||
* ```
|
||||
*
|
||||
* @param selectorOrHaystack - Element to look for.
|
||||
* @returns The filtered collection.
|
||||
* @see {@link https://api.jquery.com/has/}
|
||||
*/
|
||||
function has(selectorOrHaystack) {
|
||||
var _this = this;
|
||||
return this.filter(typeof selectorOrHaystack === 'string'
|
||||
? // Using the `:has` selector here short-circuits searches.
|
||||
":has(" + selectorOrHaystack + ")"
|
||||
: function (_, el) { return _this._make(el).find(selectorOrHaystack).length > 0; });
|
||||
}
|
||||
exports.has = has;
|
||||
/**
|
||||
* Will select the first element of a cheerio object.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('#fruits').children().first().text();
|
||||
* //=> Apple
|
||||
* ```
|
||||
*
|
||||
* @returns The first element.
|
||||
* @see {@link https://api.jquery.com/first/}
|
||||
*/
|
||||
function first() {
|
||||
return this.length > 1 ? this._make(this[0]) : this;
|
||||
}
|
||||
exports.first = first;
|
||||
/**
|
||||
* Will select the last element of a cheerio object.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('#fruits').children().last().text();
|
||||
* //=> Pear
|
||||
* ```
|
||||
*
|
||||
* @returns The last element.
|
||||
* @see {@link https://api.jquery.com/last/}
|
||||
*/
|
||||
function last() {
|
||||
return this.length > 0 ? this._make(this[this.length - 1]) : this;
|
||||
}
|
||||
exports.last = last;
|
||||
/**
|
||||
* Reduce the set of matched elements to the one at the specified index. Use
|
||||
* `.eq(-i)` to count backwards from the last selected element.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').eq(0).text();
|
||||
* //=> Apple
|
||||
*
|
||||
* $('li').eq(-1).text();
|
||||
* //=> Pear
|
||||
* ```
|
||||
*
|
||||
* @param i - Index of the element to select.
|
||||
* @returns The element at the `i`th position.
|
||||
* @see {@link https://api.jquery.com/eq/}
|
||||
*/
|
||||
function eq(i) {
|
||||
var _a;
|
||||
i = +i;
|
||||
// Use the first identity optimization if possible
|
||||
if (i === 0 && this.length <= 1)
|
||||
return this;
|
||||
if (i < 0)
|
||||
i = this.length + i;
|
||||
return this._make((_a = this[i]) !== null && _a !== void 0 ? _a : []);
|
||||
}
|
||||
exports.eq = eq;
|
||||
function get(i) {
|
||||
if (i == null) {
|
||||
return this.toArray();
|
||||
}
|
||||
return this[i < 0 ? this.length + i : i];
|
||||
}
|
||||
exports.get = get;
|
||||
/**
|
||||
* Retrieve all the DOM elements contained in the jQuery set as an array.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').toArray();
|
||||
* //=> [ {...}, {...}, {...} ]
|
||||
* ```
|
||||
*
|
||||
* @returns The contained items.
|
||||
*/
|
||||
function toArray() {
|
||||
return Array.prototype.slice.call(this);
|
||||
}
|
||||
exports.toArray = toArray;
|
||||
/**
|
||||
* Search for a given element from among the matched elements.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.pear').index();
|
||||
* //=> 2 $('.orange').index('li');
|
||||
* //=> 1
|
||||
* $('.apple').index($('#fruit, li'));
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param selectorOrNeedle - Element to look for.
|
||||
* @returns The index of the element.
|
||||
* @see {@link https://api.jquery.com/index/}
|
||||
*/
|
||||
function index(selectorOrNeedle) {
|
||||
var $haystack;
|
||||
var needle;
|
||||
if (selectorOrNeedle == null) {
|
||||
$haystack = this.parent().children();
|
||||
needle = this[0];
|
||||
}
|
||||
else if (typeof selectorOrNeedle === 'string') {
|
||||
$haystack = this._make(selectorOrNeedle);
|
||||
needle = this[0];
|
||||
}
|
||||
else {
|
||||
$haystack = this;
|
||||
needle = utils_1.isCheerio(selectorOrNeedle)
|
||||
? selectorOrNeedle[0]
|
||||
: selectorOrNeedle;
|
||||
}
|
||||
return Array.prototype.indexOf.call($haystack, needle);
|
||||
}
|
||||
exports.index = index;
|
||||
/**
|
||||
* Gets the elements matching the specified range (0-based position).
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').slice(1).eq(0).text();
|
||||
* //=> 'Orange'
|
||||
*
|
||||
* $('li').slice(1, 2).length;
|
||||
* //=> 1
|
||||
* ```
|
||||
*
|
||||
* @param start - An position at which the elements begin to be selected. If
|
||||
* negative, it indicates an offset from the end of the set.
|
||||
* @param end - An position at which the elements stop being selected. If
|
||||
* negative, it indicates an offset from the end of the set. If omitted, the
|
||||
* range continues until the end of the set.
|
||||
* @returns The elements matching the specified range.
|
||||
* @see {@link https://api.jquery.com/slice/}
|
||||
*/
|
||||
function slice(start, end) {
|
||||
return this._make(Array.prototype.slice.call(this, start, end));
|
||||
}
|
||||
exports.slice = slice;
|
||||
/**
|
||||
* End the most recent filtering operation in the current chain and return the
|
||||
* set of matched elements to its previous state.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').eq(0).end().length;
|
||||
* //=> 3
|
||||
* ```
|
||||
*
|
||||
* @returns The previous state of the set of matched elements.
|
||||
* @see {@link https://api.jquery.com/end/}
|
||||
*/
|
||||
function end() {
|
||||
var _a;
|
||||
return (_a = this.prevObject) !== null && _a !== void 0 ? _a : this._make([]);
|
||||
}
|
||||
exports.end = end;
|
||||
/**
|
||||
* Add elements to the set of matched elements.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple').add('.orange').length;
|
||||
* //=> 2
|
||||
* ```
|
||||
*
|
||||
* @param other - Elements to add.
|
||||
* @param context - Optionally the context of the new selection.
|
||||
* @returns The combined set.
|
||||
* @see {@link https://api.jquery.com/add/}
|
||||
*/
|
||||
function add(other, context) {
|
||||
var selection = this._make(other, context);
|
||||
var contents = uniqueSort(tslib_1.__spreadArray(tslib_1.__spreadArray([], this.get()), selection.get()));
|
||||
return this._make(contents);
|
||||
}
|
||||
exports.add = add;
|
||||
/**
|
||||
* Add the previous set of elements on the stack to the current set, optionally
|
||||
* filtered by a selector.
|
||||
*
|
||||
* @category Traversing
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('li').eq(0).addBack('.orange').length;
|
||||
* //=> 2
|
||||
* ```
|
||||
*
|
||||
* @param selector - Selector for the elements to add.
|
||||
* @returns The combined set.
|
||||
* @see {@link https://api.jquery.com/addBack/}
|
||||
*/
|
||||
function addBack(selector) {
|
||||
return this.prevObject
|
||||
? this.add(selector ? this.prevObject.filter(selector) : this.prevObject)
|
||||
: this;
|
||||
}
|
||||
exports.addBack = addBack;
|
||||
53
book/node_modules/juice/node_modules/cheerio/lib/cheerio.d.ts
generated
vendored
Normal file
53
book/node_modules/juice/node_modules/cheerio/lib/cheerio.d.ts
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
import { InternalOptions } from './options';
|
||||
import type { Node, Document } from 'domhandler';
|
||||
import { 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 set by using the `root` argument of the constructor.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_root: Cheerio<Document> | undefined;
|
||||
/** @function */
|
||||
find: typeof Traversing.find;
|
||||
/**
|
||||
* 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> | null, options?: InternalOptions);
|
||||
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>): Cheerio<T>;
|
||||
}
|
||||
export interface Cheerio<T> extends AttributesType, TraversingType, ManipulationType, CssType, FormsType, Iterable<T> {
|
||||
cheerio: '[cheerio object]';
|
||||
splice: typeof Array.prototype.slice;
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=cheerio.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/cheerio.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/cheerio.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"cheerio.d.ts","sourceRoot":"","sources":["../src/cheerio.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA6B,MAAM,WAAW,CAAC;AAEvE,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,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;AAE9B,qBAAa,OAAO,CAAC,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC;IAC7C,MAAM,SAAK;IACX,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;IAEnB,OAAO,EAAE,eAAe,CAAC;IACzB;;;;OAIG;IACH,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;IACrC,gBAAgB;IAChB,IAAI,EAAG,OAAO,UAAU,CAAC,IAAI,CAAC;IAE9B;;;;;;;;;OASG;gBAED,QAAQ,CAAC,EAAE,CAAC,SAAS,IAAI,GAAG,kBAAkB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EACpE,OAAO,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAAG,IAAI,EACzC,IAAI,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,IAAI,EAC1C,OAAO,GAAE,eAAgC;IAsE3C,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IACtC;;;;;;;OAOG;IACH,KAAK,CAAC,CAAC,EACL,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,MAAM,EAClC,OAAO,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,GACjC,OAAO,CAAC,CAAC,CAAC;CAWd;AAED,MAAM,WAAW,OAAO,CAAC,CAAC,CACxB,SAAQ,cAAc,EACpB,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,SAAS,EACT,QAAQ,CAAC,CAAC,CAAC;IACb,OAAO,EAAE,kBAAkB,CAAC;IAE5B,MAAM,EAAE,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;CACtC"}
|
||||
115
book/node_modules/juice/node_modules/cheerio/lib/cheerio.js
generated
vendored
Normal file
115
book/node_modules/juice/node_modules/cheerio/lib/cheerio.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
"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.__importDefault(require("./options"));
|
||||
var utils_1 = require("./utils");
|
||||
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"));
|
||||
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 (options === void 0) { options = options_1.default; }
|
||||
this.length = 0;
|
||||
this.options = options;
|
||||
// $(), $(null), $(undefined), $(false)
|
||||
if (!selector)
|
||||
return this;
|
||||
if (root) {
|
||||
if (typeof root === 'string')
|
||||
root = parse_1.default(root, this.options, false);
|
||||
this._root = new this.constructor(root, null, null, this.options);
|
||||
// Add a cyclic reference, so that calling methods on `_root` never fails.
|
||||
this._root._root = 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>')
|
||||
this._make(parse_1.default(context, this.options, false))
|
||||
: // $('li', 'ul')
|
||||
((search = context + " " + search), this._root)
|
||||
: utils_1.isCheerio(context)
|
||||
? // $('li', $)
|
||||
context
|
||||
: // $('li', node), $('li', [nodes])
|
||||
this._make(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) {
|
||||
var cheerio = new this.constructor(dom, context, this._root, this.options);
|
||||
cheerio.prevObject = this;
|
||||
return cheerio;
|
||||
};
|
||||
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
|
||||
Object.assign(Cheerio.prototype, Attributes, Traversing, Manipulation, Css, Forms);
|
||||
function isNode(obj) {
|
||||
return (!!obj.name ||
|
||||
obj.type === 'root' ||
|
||||
obj.type === 'text' ||
|
||||
obj.type === 'comment');
|
||||
}
|
||||
91
book/node_modules/juice/node_modules/cheerio/lib/index.d.ts
generated
vendored
Normal file
91
book/node_modules/juice/node_modules/cheerio/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* The main types of Cheerio objects.
|
||||
*
|
||||
* @category Cheerio
|
||||
*/
|
||||
export type { Cheerio } 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';
|
||||
declare const _default: import("./load").CheerioAPI;
|
||||
/**
|
||||
* The default cheerio instance.
|
||||
*
|
||||
* @deprecated Use the function returned by `load` instead.
|
||||
*/
|
||||
export default _default;
|
||||
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
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/index.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/index.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC;;;;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;;AAGvB;;;;GAIG;AACH,wBAAwB;AAExB,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"}
|
||||
81
book/node_modules/juice/node_modules/cheerio/lib/index.js
generated
vendored
Normal file
81
book/node_modules/juice/node_modules/cheerio/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.root = exports.parseHTML = exports.merge = exports.contains = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
/**
|
||||
* 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");
|
||||
/**
|
||||
* The default cheerio instance.
|
||||
*
|
||||
* @deprecated Use the function returned by `load` instead.
|
||||
*/
|
||||
exports.default = 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;
|
||||
73
book/node_modules/juice/node_modules/cheerio/lib/load.d.ts
generated
vendored
Normal file
73
book/node_modules/juice/node_modules/cheerio/lib/load.d.ts
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/// <reference types="node" />
|
||||
import { CheerioOptions, InternalOptions } from './options';
|
||||
import * as staticMethods from './static';
|
||||
import { Cheerio } from './cheerio';
|
||||
import type { Node, Document, Element } from 'domhandler';
|
||||
import type * as Load from './load';
|
||||
import { SelectorType, BasicAcceptedElems } from './types';
|
||||
declare type StaticType = typeof staticMethods;
|
||||
declare type LoadType = typeof Load;
|
||||
/**
|
||||
* A querying function, bound to a document created from the provided markup.
|
||||
*
|
||||
* Also provides several helper methods for dealing with the document as a whole.
|
||||
*/
|
||||
export interface CheerioAPI extends StaticType, LoadType {
|
||||
/**
|
||||
* This selector method is the starting point for traversing and manipulating
|
||||
* the document. Like jQuery, it's the primary method for selecting elements
|
||||
* in the document.
|
||||
*
|
||||
* `selector` searches within the `context` scope which searches within the
|
||||
* `root` scope.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```js
|
||||
* $('.apple', '#fruits').text();
|
||||
* //=> Apple
|
||||
*
|
||||
* $('ul .pear').attr('class');
|
||||
* //=> pear
|
||||
*
|
||||
* $('li[class=orange]').html();
|
||||
* //=> Orange
|
||||
* ```
|
||||
*
|
||||
* @param selector - Either a selector to look for within the document, or the
|
||||
* contents of a new Cheerio instance.
|
||||
* @param context - Either a selector to look for within the root, or the
|
||||
* contents of the document to query.
|
||||
* @param root - Optional HTML document string.
|
||||
*/
|
||||
<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>;
|
||||
/**
|
||||
* The root the document was originally loaded with.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_root: Document;
|
||||
/**
|
||||
* The options the document was originally loaded with.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_options: InternalOptions;
|
||||
/** Mimic jQuery's prototype alias for plugin authors. */
|
||||
fn: typeof Cheerio.prototype;
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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.
|
||||
* @see {@link https://cheerio.js.org#loading} for additional usage information.
|
||||
*/
|
||||
export declare function load(content: string | Node | Node[] | Buffer, options?: CheerioOptions | null, isDocument?: boolean): CheerioAPI;
|
||||
export {};
|
||||
//# sourceMappingURL=load.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/load.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/load.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,cAAc,EACd,eAAe,EAGhB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,aAAa,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,KAAK,IAAI,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE3D,aAAK,UAAU,GAAG,OAAO,aAAa,CAAC;AACvC,aAAK,QAAQ,GAAG,OAAO,IAAI,CAAC;AAE5B;;;;GAIG;AACH,MAAM,WAAW,UAAW,SAAQ,UAAU,EAAE,QAAQ;IACtD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,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;IAEjD;;;;OAIG;IACH,KAAK,EAAE,QAAQ,CAAC;IAEhB;;;;OAIG;IACH,QAAQ,EAAE,eAAe,CAAC;IAE1B,yDAAyD;IACzD,EAAE,EAAE,OAAO,OAAO,CAAC,SAAS,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,IAAI,CAClB,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAAE,GAAG,MAAM,EACxC,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,EAC/B,UAAU,UAAO,GAChB,UAAU,CAsCZ"}
|
||||
53
book/node_modules/juice/node_modules/cheerio/lib/load.js
generated
vendored
Normal file
53
book/node_modules/juice/node_modules/cheerio/lib/load.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
"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.
|
||||
*
|
||||
* @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.
|
||||
* @see {@link https://cheerio.js.org#loading} for additional usage information.
|
||||
*/
|
||||
function load(content, options, isDocument) {
|
||||
if (isDocument === void 0) { isDocument = true; }
|
||||
if (content == null) {
|
||||
throw new Error('cheerio.load() expects a string');
|
||||
}
|
||||
var internalOpts = tslib_1.__assign(tslib_1.__assign({}, options_1.default), options_1.flatten(options));
|
||||
var root = parse_1.default(content, internalOpts, isDocument);
|
||||
/** Create an extended class here, so that extensions only live on one instance. */
|
||||
var LoadedCheerio = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(LoadedCheerio, _super);
|
||||
function LoadedCheerio() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return LoadedCheerio;
|
||||
}(cheerio_1.Cheerio));
|
||||
function initialize(selector, context, r, opts) {
|
||||
if (r === void 0) { r = root; }
|
||||
return new LoadedCheerio(selector, context, r, tslib_1.__assign(tslib_1.__assign({}, internalOpts), options_1.flatten(opts)));
|
||||
}
|
||||
// Add in static methods & properties
|
||||
Object.assign(initialize, staticMethods, {
|
||||
load: load,
|
||||
// `_root` and `_options` are used in static methods.
|
||||
_root: root,
|
||||
_options: internalOpts,
|
||||
// Add `fn` for plugins
|
||||
fn: LoadedCheerio.prototype,
|
||||
// Add the prototype here to maintain `instanceof` behavior.
|
||||
prototype: LoadedCheerio.prototype,
|
||||
});
|
||||
return initialize;
|
||||
}
|
||||
exports.load = load;
|
||||
31
book/node_modules/juice/node_modules/cheerio/lib/options.d.ts
generated
vendored
Normal file
31
book/node_modules/juice/node_modules/cheerio/lib/options.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
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
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/options.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/options.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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;;;;;GAKG;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"}
|
||||
22
book/node_modules/juice/node_modules/cheerio/lib/options.js
generated
vendored
Normal file
22
book/node_modules/juice/node_modules/cheerio/lib/options.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"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;
|
||||
13
book/node_modules/juice/node_modules/cheerio/lib/parse.d.ts
generated
vendored
Normal file
13
book/node_modules/juice/node_modules/cheerio/lib/parse.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <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
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/parse.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/parse.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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"}
|
||||
67
book/node_modules/juice/node_modules/cheerio/lib/parse.js
generated
vendored
Normal file
67
book/node_modules/juice/node_modules/cheerio/lib/parse.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.update = void 0;
|
||||
var htmlparser2_1 = require("htmlparser2");
|
||||
var htmlparser2_adapter_1 = require("./parsers/htmlparser2-adapter");
|
||||
var parse5_adapter_1 = require("./parsers/parse5-adapter");
|
||||
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_adapter_1.parse(content, options)
|
||||
: parse5_adapter_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;
|
||||
3
book/node_modules/juice/node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts
generated
vendored
Normal file
3
book/node_modules/juice/node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export { parseDocument as parse } from 'htmlparser2';
|
||||
export { default as render } from 'dom-serializer';
|
||||
//# sourceMappingURL=htmlparser2-adapter.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"htmlparser2-adapter.d.ts","sourceRoot":"","sources":["../../src/parsers/htmlparser2-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,gBAAgB,CAAC"}
|
||||
10
book/node_modules/juice/node_modules/cheerio/lib/parsers/htmlparser2-adapter.js
generated
vendored
Normal file
10
book/node_modules/juice/node_modules/cheerio/lib/parsers/htmlparser2-adapter.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
"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; } });
|
||||
9
book/node_modules/juice/node_modules/cheerio/lib/parsers/parse5-adapter.d.ts
generated
vendored
Normal file
9
book/node_modules/juice/node_modules/cheerio/lib/parsers/parse5-adapter.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
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-adapter.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/parsers/parse5-adapter.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/parsers/parse5-adapter.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"parse5-adapter.d.ts","sourceRoot":"","sources":["../../src/parsers/parse5-adapter.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"}
|
||||
41
book/node_modules/juice/node_modules/cheerio/lib/parsers/parse5-adapter.js
generated
vendored
Normal file
41
book/node_modules/juice/node_modules/cheerio/lib/parsers/parse5-adapter.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
"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;
|
||||
88
book/node_modules/juice/node_modules/cheerio/lib/static.d.ts
generated
vendored
Normal file
88
book/node_modules/juice/node_modules/cheerio/lib/static.d.ts
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
import type { CheerioAPI, Cheerio } from '.';
|
||||
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: CheerioAPI | 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: CheerioAPI | 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: CheerioAPI, 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: CheerioAPI | 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: CheerioAPI, data: string, context?: unknown | boolean, keepScripts?: boolean): Node[];
|
||||
export declare function parseHTML(this: CheerioAPI, 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: CheerioAPI): 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
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/static.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/static.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../src/static.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAEL,cAAc,EAGf,MAAM,WAAW,CAAC;AAiDnB;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC;AAChF;;;;;;GAMG;AACH,wBAAgB,IAAI,CAClB,IAAI,EAAE,UAAU,GAAG,IAAI,EACvB,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,EACrC,OAAO,CAAC,EAAE,cAAc,GACvB,MAAM,CAAC;AAkCV;;;;;GAKG;AACH,wBAAgB,GAAG,CACjB,IAAI,EAAE,UAAU,EAChB,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,GACpC,MAAM,CAIR;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAClB,IAAI,EAAE,UAAU,GAAG,IAAI,EACvB,QAAQ,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC,GACzB,MAAM,CAmBR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,EAC3B,WAAW,CAAC,EAAE,OAAO,GACpB,IAAI,EAAE,CAAC;AACV,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AA8BpE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAExD;AAED;;;;;;;;;GASG;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"}
|
||||
207
book/node_modules/juice/node_modules/cheerio/lib/static.js
generated
vendored
Normal file
207
book/node_modules/juice/node_modules/cheerio/lib/static.js
generated
vendored
Normal file
@@ -0,0 +1,207 @@
|
||||
"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_adapter_1 = require("./parsers/parse5-adapter");
|
||||
var htmlparser2_adapter_1 = require("./parsers/htmlparser2-adapter");
|
||||
/**
|
||||
* 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;
|
||||
var toRender = dom
|
||||
? typeof dom === 'string'
|
||||
? cheerio_select_1.select(dom, (_a = that === null || that === void 0 ? void 0 : that._root) !== null && _a !== void 0 ? _a : [], options)
|
||||
: dom
|
||||
: that === null || that === void 0 ? void 0 : that._root.children;
|
||||
if (!toRender)
|
||||
return '';
|
||||
return options.xmlMode || options._useHtmlParser2
|
||||
? htmlparser2_adapter_1.render(toRender, options)
|
||||
: parse5_adapter_1.render(toRender);
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
var opts = 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, opts);
|
||||
}
|
||||
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() {
|
||||
return this(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;
|
||||
}
|
||||
20
book/node_modules/juice/node_modules/cheerio/lib/types.d.ts
generated
vendored
Normal file
20
book/node_modules/juice/node_modules/cheerio/lib/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
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 } 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<T> = string | FilterFunction<T> | T | Cheerio<T>;
|
||||
export {};
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/types.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/types.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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,MAAM,YAAY,CAAC;AAEvC,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,CAAC,CAAC,IAAI,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
||||
2
book/node_modules/juice/node_modules/cheerio/lib/types.js
generated
vendored
Normal file
2
book/node_modules/juice/node_modules/cheerio/lib/types.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
73
book/node_modules/juice/node_modules/cheerio/lib/utils.d.ts
generated
vendored
Normal file
73
book/node_modules/juice/node_modules/cheerio/lib/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
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: (elem: T, index: number) => void): 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
|
||||
1
book/node_modules/juice/node_modules/cheerio/lib/utils.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/cheerio/lib/utils.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GACnC,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"}
|
||||
111
book/node_modules/juice/node_modules/cheerio/lib/utils.js
generated
vendored
Normal file
111
book/node_modules/juice/node_modules/cheerio/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
"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; i++)
|
||||
fn(array[i], 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;
|
||||
114
book/node_modules/juice/node_modules/cheerio/package.json
generated
vendored
Normal file
114
book/node_modules/juice/node_modules/cheerio/package.json
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
{
|
||||
"name": "cheerio",
|
||||
"version": "1.0.0-rc.10",
|
||||
"description": "Tiny, fast, and elegant implementation of core jQuery designed specifically for the server",
|
||||
"author": "Matt Mueller <mattmuelle@gmail.com>",
|
||||
"maintainers": [
|
||||
"Felix Boehm <me@feedic.com>"
|
||||
],
|
||||
"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.5.0",
|
||||
"dom-serializer": "^1.3.2",
|
||||
"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.2",
|
||||
"@types/benchmark": "^2.1.0",
|
||||
"@types/jest": "^26.0.23",
|
||||
"@types/jsdom": "^16.2.10",
|
||||
"@types/node": "^15.12.1",
|
||||
"@types/node-fetch": "^2.5.10",
|
||||
"@types/parse5": "^6.0.0",
|
||||
"@types/parse5-htmlparser2-tree-adapter": "^6.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.26.0",
|
||||
"@typescript-eslint/parser": "^4.26.0",
|
||||
"benchmark": "^2.1.4",
|
||||
"eslint": "^7.28.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-jest": "^24.3.6",
|
||||
"eslint-plugin-jsdoc": "^35.1.3",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"husky": "^4.3.8",
|
||||
"jest": "^27.0.4",
|
||||
"jquery": "^3.6.0",
|
||||
"jsdom": "^16.6.0",
|
||||
"lint-staged": "^11.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"prettier": "^2.3.1",
|
||||
"prettier-plugin-jsdoc": "0.3.22",
|
||||
"ts-jest": "^27.0.3",
|
||||
"ts-node": "^10.0.0",
|
||||
"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__/"
|
||||
]
|
||||
}
|
||||
}
|
||||
361
book/node_modules/juice/node_modules/commander/CHANGELOG.md
generated
vendored
Normal file
361
book/node_modules/juice/node_modules/commander/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,361 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). (Format adopted after v3.0.0.)
|
||||
|
||||
<!-- markdownlint-disable MD024 -->
|
||||
<!-- markdownlint-disable MD004 -->
|
||||
|
||||
## [6.2.1] (2020-12-13)
|
||||
|
||||
### Fixed
|
||||
|
||||
- some tests failed if directory path included a space ([1390])
|
||||
|
||||
## [6.2.0] (2020-10-25)
|
||||
|
||||
### Added
|
||||
|
||||
- added 'tsx' file extension for stand-alone executable subcommands ([#1368])
|
||||
- documented second parameter to `.description()` to describe command arguments ([#1353])
|
||||
- documentation of special cases with options taking varying numbers of option-arguments ([#1332])
|
||||
- documentation for terminology ([#1361])
|
||||
|
||||
### Fixed
|
||||
|
||||
- add missing TypeScript definition for `.addHelpCommand()' ([#1375])
|
||||
- removed blank line after "Arguments:" in help, to match "Options:" and "Commands:" ([#1360])
|
||||
|
||||
### Changed
|
||||
|
||||
- update dependencies
|
||||
|
||||
## [6.1.0] (2020-08-28)
|
||||
|
||||
### Added
|
||||
|
||||
- include URL to relevant section of README for error for potential conflict between Command properties and option values ([#1306])
|
||||
- `.combineFlagAndOptionalValue(false)` to ease upgrade path from older versions of Commander ([#1326])
|
||||
- allow disabling the built-in help option using `.helpOption(false)` ([#1325])
|
||||
- allow just some arguments in `argumentDescription` to `.description()` ([#1323])
|
||||
|
||||
### Changed
|
||||
|
||||
- tidy async test and remove lint override ([#1312])
|
||||
|
||||
### Fixed
|
||||
|
||||
- executable subcommand launching when script path not known ([#1322])
|
||||
|
||||
## [6.0.0] (2020-07-21)
|
||||
|
||||
### Added
|
||||
|
||||
- add support for variadic options ([#1250])
|
||||
- allow options to be added with just a short flag ([#1256])
|
||||
- *Breaking* the option property has same case as flag. e.g. flag `-n` accessed as `opts().n` (previously uppercase)
|
||||
- *Breaking* throw an error if there might be a clash between option name and a Command property, with advice on how to resolve ([#1275])
|
||||
|
||||
### Fixed
|
||||
|
||||
- Options which contain -no- in the middle of the option flag should not be treated as negatable. ([#1301])
|
||||
|
||||
## [6.0.0-0] (2020-06-20)
|
||||
|
||||
(Released in 6.0.0)
|
||||
|
||||
## [5.1.0] (2020-04-25)
|
||||
|
||||
### Added
|
||||
|
||||
- support for multiple command aliases, the first of which is shown in the auto-generated help ([#531], [#1236])
|
||||
- configuration support in `addCommand()` for `hidden` and `isDefault` ([#1232])
|
||||
|
||||
### Fixed
|
||||
|
||||
- omit masked help flags from the displayed help ([#645], [#1247])
|
||||
- remove old short help flag when change help flags using `helpOption` ([#1248])
|
||||
|
||||
### Changed
|
||||
|
||||
- remove use of `arguments` to improve auto-generated help in editors ([#1235])
|
||||
- rename `.command()` configuration `noHelp` to `hidden` (but not remove old support) ([#1232])
|
||||
- improvements to documentation
|
||||
- update dependencies
|
||||
- update tested versions of node
|
||||
- eliminate lint errors in TypeScript ([#1208])
|
||||
|
||||
## [5.0.0] (2020-03-14)
|
||||
|
||||
### Added
|
||||
|
||||
* support for nested commands with action-handlers ([#1] [#764] [#1149])
|
||||
* `.addCommand()` for adding a separately configured command ([#764] [#1149])
|
||||
* allow a non-executable to be set as the default command ([#742] [#1149])
|
||||
* implicit help command when there are subcommands (previously only if executables) ([#1149])
|
||||
* customise implicit help command with `.addHelpCommand()` ([#1149])
|
||||
* display error message for unknown subcommand, by default ([#432] [#1088] [#1149])
|
||||
* display help for missing subcommand, by default ([#1088] [#1149])
|
||||
* combined short options as single argument may include boolean flags and value flag and value (e.g. `-a -b -p 80` can be written as `-abp80`) ([#1145])
|
||||
* `.parseOption()` includes short flag and long flag expansions ([#1145])
|
||||
* `.helpInformation()` returns help text as a string, previously a private routine ([#1169])
|
||||
* `.parse()` implicitly uses `process.argv` if arguments not specified ([#1172])
|
||||
* optionally specify where `.parse()` arguments "from", if not following node conventions ([#512] [#1172])
|
||||
* suggest help option along with unknown command error ([#1179])
|
||||
* TypeScript definition for `commands` property of `Command` ([#1184])
|
||||
* export `program` property ([#1195])
|
||||
* `createCommand` factory method to simplify subclassing ([#1191])
|
||||
|
||||
### Fixed
|
||||
|
||||
* preserve argument order in subcommands ([#508] [#962] [#1138])
|
||||
* do not emit `command:*` for executable subcommands ([#809] [#1149])
|
||||
* action handler called whether or not there are non-option arguments ([#1062] [#1149])
|
||||
* combining option short flag and value in single argument now works for subcommands ([#1145])
|
||||
* only add implicit help command when it will not conflict with other uses of argument ([#1153] [#1149])
|
||||
* implicit help command works with command aliases ([#948] [#1149])
|
||||
* options are validated whether or not there is an action handler ([#1149])
|
||||
|
||||
### Changed
|
||||
|
||||
* *Breaking* `.args` contains command arguments with just recognised options removed ([#1032] [#1138])
|
||||
* *Breaking* display error if required argument for command is missing ([#995] [#1149])
|
||||
* tighten TypeScript definition of custom option processing function passed to `.option()` ([#1119])
|
||||
* *Breaking* `.allowUnknownOption()` ([#802] [#1138])
|
||||
* unknown options included in arguments passed to command action handler
|
||||
* unknown options included in `.args`
|
||||
* only recognised option short flags and long flags are expanded (e.g. `-ab` or `--foo=bar`) ([#1145])
|
||||
* *Breaking* `.parseOptions()` ([#1138])
|
||||
* `args` in returned result renamed `operands` and does not include anything after first unknown option
|
||||
* `unknown` in returned result has arguments after first unknown option including operands, not just options and values
|
||||
* *Breaking* `.on('command:*', callback)` and other command events passed (changed) results from `.parseOptions`, i.e. operands and unknown ([#1138])
|
||||
* refactor Option from prototype to class ([#1133])
|
||||
* refactor Command from prototype to class ([#1159])
|
||||
* changes to error handling ([#1165])
|
||||
* throw for author error, not just display message
|
||||
* preflight for variadic error
|
||||
* add tips to missing subcommand executable
|
||||
* TypeScript fluent return types changed to be more subclass friendly, return `this` rather than `Command` ([#1180])
|
||||
* `.parseAsync` returns `Promise<this>` to be consistent with `.parse()` ([#1180])
|
||||
* update dependencies
|
||||
|
||||
### Removed
|
||||
|
||||
* removed EventEmitter from TypeScript definition for Command, eliminating implicit peer dependency on `@types/node` ([#1146])
|
||||
* removed private function `normalize` (the functionality has been integrated into `parseOptions`) ([#1145])
|
||||
* `parseExpectedArgs` is now private ([#1149])
|
||||
|
||||
### Migration Tips
|
||||
|
||||
If you use `.on('command:*')` or more complicated tests to detect an unrecognised subcommand, you may be able to delete the code and rely on the default behaviour.
|
||||
|
||||
If you use `program.args` or more complicated tests to detect a missing subcommand, you may be able to delete the code and rely on the default behaviour.
|
||||
|
||||
If you use `.command('*')` to add a default command, you may be be able to switch to `isDefault:true` with a named command.
|
||||
|
||||
If you want to continue combining short options with optional values as though they were boolean flags, set `combineFlagAndOptionalValue(false)`
|
||||
to expand `-fb` to `-f -b` rather than `-f b`.
|
||||
|
||||
## [5.0.0-4] (2020-03-03)
|
||||
|
||||
(Released in 5.0.0)
|
||||
|
||||
## [5.0.0-3] (2020-02-20)
|
||||
|
||||
(Released in 5.0.0)
|
||||
|
||||
## [5.0.0-2] (2020-02-10)
|
||||
|
||||
(Released in 5.0.0)
|
||||
|
||||
## [5.0.0-1] (2020-02-08)
|
||||
|
||||
(Released in 5.0.0)
|
||||
|
||||
## [5.0.0-0] (2020-02-02)
|
||||
|
||||
(Released in 5.0.0)
|
||||
|
||||
## [4.1.1] (2020-02-02)
|
||||
|
||||
### Fixed
|
||||
|
||||
* TypeScript definition for `.action()` should include Promise for async ([#1157])
|
||||
|
||||
## [4.1.0] (2020-01-06)
|
||||
|
||||
### Added
|
||||
|
||||
* two routines to change how option values are handled, and eliminate name clashes with command properties ([#933] [#1102])
|
||||
* see storeOptionsAsProperties and passCommandToAction in README
|
||||
* `.parseAsync` to use instead of `.parse` if supply async action handlers ([#806] [#1118])
|
||||
|
||||
### Fixed
|
||||
|
||||
* Remove trailing blanks from wrapped help text ([#1096])
|
||||
|
||||
### Changed
|
||||
|
||||
* update dependencies
|
||||
* extend security coverage for Commander 2.x to 2020-02-03
|
||||
* improvements to README
|
||||
* improvements to TypeScript definition documentation
|
||||
* move old versions out of main CHANGELOG
|
||||
* removed explicit use of `ts-node` in tests
|
||||
|
||||
## [4.0.1] (2019-11-12)
|
||||
|
||||
### Fixed
|
||||
|
||||
* display help when requested, even if there are missing required options ([#1091])
|
||||
|
||||
## [4.0.0] (2019-11-02)
|
||||
|
||||
### Added
|
||||
|
||||
* automatically wrap and indent help descriptions for options and commands ([#1051])
|
||||
* `.exitOverride()` allows override of calls to `process.exit` for additional error handling and to keep program running ([#1040])
|
||||
* support for declaring required options with `.requiredOptions()` ([#1071])
|
||||
* GitHub Actions support ([#1027])
|
||||
* translation links in README
|
||||
|
||||
### Changed
|
||||
|
||||
* dev: switch tests from Sinon+Should to Jest with major rewrite of tests ([#1035])
|
||||
* call default subcommand even when there are unknown options ([#1047])
|
||||
* *Breaking* Commander is only officially supported on Node 8 and above, and requires Node 6 ([#1053])
|
||||
|
||||
### Fixed
|
||||
|
||||
* *Breaking* keep command object out of program.args when action handler called ([#1048])
|
||||
* also, action handler now passed array of unknown arguments
|
||||
* complain about unknown options when program argument supplied and action handler ([#1049])
|
||||
* this changes parameters to `command:*` event to include unknown arguments
|
||||
* removed deprecated `customFds` option from call to `child_process.spawn` ([#1052])
|
||||
* rework TypeScript declarations to bring all types into imported namespace ([#1081])
|
||||
|
||||
### Migration Tips
|
||||
|
||||
#### Testing for no arguments
|
||||
|
||||
If you were previously using code like:
|
||||
|
||||
```js
|
||||
if (!program.args.length) ...
|
||||
```
|
||||
|
||||
a partial replacement is:
|
||||
|
||||
```js
|
||||
if (program.rawArgs.length < 3) ...
|
||||
```
|
||||
|
||||
## [4.0.0-1] Prerelease (2019-10-08)
|
||||
|
||||
(Released in 4.0.0)
|
||||
|
||||
## [4.0.0-0] Prerelease (2019-10-01)
|
||||
|
||||
(Released in 4.0.0)
|
||||
|
||||
## Older versions
|
||||
|
||||
* [3.x](./changelogs/CHANGELOG-3.md)
|
||||
* [2.x](./changelogs/CHANGELOG-2.md)
|
||||
* [1.x](./changelogs/CHANGELOG-1.md)
|
||||
* [0.x](./changelogs/CHANGELOG-0.md)
|
||||
|
||||
[#1]: https://github.com/tj/commander.js/issues/1
|
||||
[#432]: https://github.com/tj/commander.js/issues/432
|
||||
[#508]: https://github.com/tj/commander.js/issues/508
|
||||
[#512]: https://github.com/tj/commander.js/issues/512
|
||||
[#531]: https://github.com/tj/commander.js/issues/531
|
||||
[#645]: https://github.com/tj/commander.js/issues/645
|
||||
[#742]: https://github.com/tj/commander.js/issues/742
|
||||
[#764]: https://github.com/tj/commander.js/issues/764
|
||||
[#802]: https://github.com/tj/commander.js/issues/802
|
||||
[#806]: https://github.com/tj/commander.js/issues/806
|
||||
[#809]: https://github.com/tj/commander.js/issues/809
|
||||
[#948]: https://github.com/tj/commander.js/issues/948
|
||||
[#962]: https://github.com/tj/commander.js/issues/962
|
||||
[#995]: https://github.com/tj/commander.js/issues/995
|
||||
[#1027]: https://github.com/tj/commander.js/pull/1027
|
||||
[#1032]: https://github.com/tj/commander.js/issues/1032
|
||||
[#1035]: https://github.com/tj/commander.js/pull/1035
|
||||
[#1040]: https://github.com/tj/commander.js/pull/1040
|
||||
[#1047]: https://github.com/tj/commander.js/pull/1047
|
||||
[#1048]: https://github.com/tj/commander.js/pull/1048
|
||||
[#1049]: https://github.com/tj/commander.js/pull/1049
|
||||
[#1051]: https://github.com/tj/commander.js/pull/1051
|
||||
[#1052]: https://github.com/tj/commander.js/pull/1052
|
||||
[#1053]: https://github.com/tj/commander.js/pull/1053
|
||||
[#1062]: https://github.com/tj/commander.js/pull/1062
|
||||
[#1071]: https://github.com/tj/commander.js/pull/1071
|
||||
[#1081]: https://github.com/tj/commander.js/pull/1081
|
||||
[#1088]: https://github.com/tj/commander.js/issues/1088
|
||||
[#1091]: https://github.com/tj/commander.js/pull/1091
|
||||
[#1096]: https://github.com/tj/commander.js/pull/1096
|
||||
[#1102]: https://github.com/tj/commander.js/pull/1102
|
||||
[#1118]: https://github.com/tj/commander.js/pull/1118
|
||||
[#1119]: https://github.com/tj/commander.js/pull/1119
|
||||
[#1133]: https://github.com/tj/commander.js/pull/1133
|
||||
[#1138]: https://github.com/tj/commander.js/pull/1138
|
||||
[#1145]: https://github.com/tj/commander.js/pull/1145
|
||||
[#1146]: https://github.com/tj/commander.js/pull/1146
|
||||
[#1149]: https://github.com/tj/commander.js/pull/1149
|
||||
[#1153]: https://github.com/tj/commander.js/issues/1153
|
||||
[#1157]: https://github.com/tj/commander.js/pull/1157
|
||||
[#1159]: https://github.com/tj/commander.js/pull/1159
|
||||
[#1165]: https://github.com/tj/commander.js/pull/1165
|
||||
[#1169]: https://github.com/tj/commander.js/pull/1169
|
||||
[#1172]: https://github.com/tj/commander.js/pull/1172
|
||||
[#1179]: https://github.com/tj/commander.js/pull/1179
|
||||
[#1180]: https://github.com/tj/commander.js/pull/1180
|
||||
[#1184]: https://github.com/tj/commander.js/pull/1184
|
||||
[#1191]: https://github.com/tj/commander.js/pull/1191
|
||||
[#1195]: https://github.com/tj/commander.js/pull/1195
|
||||
[#1208]: https://github.com/tj/commander.js/pull/1208
|
||||
[#1232]: https://github.com/tj/commander.js/pull/1232
|
||||
[#1235]: https://github.com/tj/commander.js/pull/1235
|
||||
[#1236]: https://github.com/tj/commander.js/pull/1236
|
||||
[#1247]: https://github.com/tj/commander.js/pull/1247
|
||||
[#1248]: https://github.com/tj/commander.js/pull/1248
|
||||
[#1250]: https://github.com/tj/commander.js/pull/1250
|
||||
[#1256]: https://github.com/tj/commander.js/pull/1256
|
||||
[#1275]: https://github.com/tj/commander.js/pull/1275
|
||||
[#1301]: https://github.com/tj/commander.js/issues/1301
|
||||
[#1306]: https://github.com/tj/commander.js/pull/1306
|
||||
[#1312]: https://github.com/tj/commander.js/pull/1312
|
||||
[#1322]: https://github.com/tj/commander.js/pull/1322
|
||||
[#1323]: https://github.com/tj/commander.js/pull/1323
|
||||
[#1325]: https://github.com/tj/commander.js/pull/1325
|
||||
[#1326]: https://github.com/tj/commander.js/pull/1326
|
||||
[#1332]: https://github.com/tj/commander.js/pull/1332
|
||||
[#1353]: https://github.com/tj/commander.js/pull/1353
|
||||
[#1360]: https://github.com/tj/commander.js/pull/1360
|
||||
[#1361]: https://github.com/tj/commander.js/pull/1361
|
||||
[#1368]: https://github.com/tj/commander.js/pull/1368
|
||||
[#1375]: https://github.com/tj/commander.js/pull/1375
|
||||
[#1390]: https://github.com/tj/commander.js/pull/1390
|
||||
|
||||
[Unreleased]: https://github.com/tj/commander.js/compare/master...develop
|
||||
[6.2.1]: https://github.com/tj/commander.js/compare/v6.2.0..v6.2.1
|
||||
[6.2.0]: https://github.com/tj/commander.js/compare/v6.1.0..v6.2.0
|
||||
[6.1.0]: https://github.com/tj/commander.js/compare/v6.0.0..v6.1.0
|
||||
[6.0.0]: https://github.com/tj/commander.js/compare/v5.1.0..v6.0.0
|
||||
[6.0.0-0]: https://github.com/tj/commander.js/compare/v5.1.0..v6.0.0-0
|
||||
[5.1.0]: https://github.com/tj/commander.js/compare/v5.0.0..v5.1.0
|
||||
[5.0.0]: https://github.com/tj/commander.js/compare/v4.1.1..v5.0.0
|
||||
[5.0.0-4]: https://github.com/tj/commander.js/compare/v5.0.0-3..v5.0.0-4
|
||||
[5.0.0-3]: https://github.com/tj/commander.js/compare/v5.0.0-2..v5.0.0-3
|
||||
[5.0.0-2]: https://github.com/tj/commander.js/compare/v5.0.0-1..v5.0.0-2
|
||||
[5.0.0-1]: https://github.com/tj/commander.js/compare/v5.0.0-0..v5.0.0-1
|
||||
[5.0.0-0]: https://github.com/tj/commander.js/compare/v4.1.1..v5.0.0-0
|
||||
[4.1.1]: https://github.com/tj/commander.js/compare/v4.1.0..v4.1.1
|
||||
[4.1.0]: https://github.com/tj/commander.js/compare/v4.0.1..v4.1.0
|
||||
[4.0.1]: https://github.com/tj/commander.js/compare/v4.0.0..v4.0.1
|
||||
[4.0.0]: https://github.com/tj/commander.js/compare/v3.0.2..v4.0.0
|
||||
[4.0.0-1]: https://github.com/tj/commander.js/compare/v4.0.0-0..v4.0.0-1
|
||||
[4.0.0-0]: https://github.com/tj/commander.js/compare/v3.0.2...v4.0.0-0
|
||||
22
book/node_modules/juice/node_modules/commander/LICENSE
generated
vendored
Normal file
22
book/node_modules/juice/node_modules/commander/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
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.
|
||||
791
book/node_modules/juice/node_modules/commander/Readme.md
generated
vendored
Normal file
791
book/node_modules/juice/node_modules/commander/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,791 @@
|
||||
# Commander.js
|
||||
|
||||
[](http://travis-ci.org/tj/commander.js)
|
||||
[](https://www.npmjs.org/package/commander)
|
||||
[](https://npmcharts.com/compare/commander?minimal=true)
|
||||
[](https://packagephobia.now.sh/result?p=commander)
|
||||
|
||||
The complete solution for [node.js](http://nodejs.org) command-line interfaces.
|
||||
|
||||
Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
|
||||
|
||||
- [Commander.js](#commanderjs)
|
||||
- [Installation](#installation)
|
||||
- [Declaring _program_ variable](#declaring-program-variable)
|
||||
- [Options](#options)
|
||||
- [Common option types, boolean and value](#common-option-types-boolean-and-value)
|
||||
- [Default option value](#default-option-value)
|
||||
- [Other option types, negatable boolean and boolean|value](#other-option-types-negatable-boolean-and-booleanvalue)
|
||||
- [Custom option processing](#custom-option-processing)
|
||||
- [Required option](#required-option)
|
||||
- [Variadic option](#variadic-option)
|
||||
- [Version option](#version-option)
|
||||
- [Commands](#commands)
|
||||
- [Specify the argument syntax](#specify-the-argument-syntax)
|
||||
- [Action handler (sub)commands](#action-handler-subcommands)
|
||||
- [Stand-alone executable (sub)commands](#stand-alone-executable-subcommands)
|
||||
- [Automated help](#automated-help)
|
||||
- [Custom help](#custom-help)
|
||||
- [.usage and .name](#usage-and-name)
|
||||
- [.help(cb)](#helpcb)
|
||||
- [.outputHelp(cb)](#outputhelpcb)
|
||||
- [.helpInformation()](#helpinformation)
|
||||
- [.helpOption(flags, description)](#helpoptionflags-description)
|
||||
- [.addHelpCommand()](#addhelpcommand)
|
||||
- [Custom event listeners](#custom-event-listeners)
|
||||
- [Bits and pieces](#bits-and-pieces)
|
||||
- [.parse() and .parseAsync()](#parse-and-parseasync)
|
||||
- [Avoiding option name clashes](#avoiding-option-name-clashes)
|
||||
- [TypeScript](#typescript)
|
||||
- [createCommand()](#createcommand)
|
||||
- [Import into ECMAScript Module](#import-into-ecmascript-module)
|
||||
- [Node options such as `--harmony`](#node-options-such-as---harmony)
|
||||
- [Debugging stand-alone executable subcommands](#debugging-stand-alone-executable-subcommands)
|
||||
- [Override exit handling](#override-exit-handling)
|
||||
- [Examples](#examples)
|
||||
- [Support](#support)
|
||||
- [Commander for enterprise](#commander-for-enterprise)
|
||||
|
||||
For information about terms used in this document see: [terminology](./docs/terminology.md)
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install commander
|
||||
```
|
||||
|
||||
## Declaring _program_ variable
|
||||
|
||||
Commander exports a global object which is convenient for quick programs.
|
||||
This is used in the examples in this README for brevity.
|
||||
|
||||
```js
|
||||
const { program } = require('commander');
|
||||
program.version('0.0.1');
|
||||
```
|
||||
|
||||
For larger programs which may use commander in multiple ways, including unit testing, it is better to create a local Command object to use.
|
||||
|
||||
```js
|
||||
const { Command } = require('commander');
|
||||
const program = new Command();
|
||||
program.version('0.0.1');
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
Options are defined with the `.option()` method, also serving as documentation for the options. Each option can have a short flag (single character) and a long name, separated by a comma or space or vertical bar ('|').
|
||||
|
||||
The options can be accessed as properties on the Command object. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc. See also optional new behaviour to [avoid name clashes](#avoiding-option-name-clashes).
|
||||
|
||||
Multiple short flags may optionally be combined in a single argument following the dash: boolean flags, followed by a single option taking a value (possibly followed by the value).
|
||||
For example `-a -b -p 80` may be written as `-ab -p80` or even `-abp80`.
|
||||
|
||||
You can use `--` to indicate the end of the options, and any remaining arguments will be used without being interpreted.
|
||||
|
||||
Options on the command line are not positional, and can be specified before or after other arguments.
|
||||
|
||||
### Common option types, boolean and value
|
||||
|
||||
The two most used option types are a boolean option, and an option which takes its value
|
||||
from the following argument (declared with angle brackets like `--expect <value>`). Both are `undefined` unless specified on command line.
|
||||
|
||||
Example file: [options-common.js](./examples/options-common.js)
|
||||
|
||||
```js
|
||||
program
|
||||
.option('-d, --debug', 'output extra debugging')
|
||||
.option('-s, --small', 'small pizza size')
|
||||
.option('-p, --pizza-type <type>', 'flavour of pizza');
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
if (program.debug) console.log(program.opts());
|
||||
console.log('pizza details:');
|
||||
if (program.small) console.log('- small pizza size');
|
||||
if (program.pizzaType) console.log(`- ${program.pizzaType}`);
|
||||
```
|
||||
|
||||
```bash
|
||||
$ pizza-options -d
|
||||
{ debug: true, small: undefined, pizzaType: undefined }
|
||||
pizza details:
|
||||
$ pizza-options -p
|
||||
error: option '-p, --pizza-type <type>' argument missing
|
||||
$ pizza-options -ds -p vegetarian
|
||||
{ debug: true, small: true, pizzaType: 'vegetarian' }
|
||||
pizza details:
|
||||
- small pizza size
|
||||
- vegetarian
|
||||
$ pizza-options --pizza-type=cheese
|
||||
pizza details:
|
||||
- cheese
|
||||
```
|
||||
|
||||
`program.parse(arguments)` processes the arguments, leaving any args not consumed by the program options in the `program.args` array.
|
||||
|
||||
### Default option value
|
||||
|
||||
You can specify a default value for an option which takes a value.
|
||||
|
||||
Example file: [options-defaults.js](./examples/options-defaults.js)
|
||||
|
||||
```js
|
||||
program
|
||||
.option('-c, --cheese <type>', 'add the specified type of cheese', 'blue');
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
console.log(`cheese: ${program.cheese}`);
|
||||
```
|
||||
|
||||
```bash
|
||||
$ pizza-options
|
||||
cheese: blue
|
||||
$ pizza-options --cheese stilton
|
||||
cheese: stilton
|
||||
```
|
||||
|
||||
### Other option types, negatable boolean and boolean|value
|
||||
|
||||
You can define a boolean option long name with a leading `no-` to set the option value to false when used.
|
||||
Defined alone this also makes the option true by default.
|
||||
|
||||
If you define `--foo` first, adding `--no-foo` does not change the default value from what it would
|
||||
otherwise be. You can specify a default boolean value for a boolean option and it can be overridden on command line.
|
||||
|
||||
Example file: [options-negatable.js](./examples/options-negatable.js)
|
||||
|
||||
```js
|
||||
program
|
||||
.option('--no-sauce', 'Remove sauce')
|
||||
.option('--cheese <flavour>', 'cheese flavour', 'mozzarella')
|
||||
.option('--no-cheese', 'plain with no cheese')
|
||||
.parse(process.argv);
|
||||
|
||||
const sauceStr = program.sauce ? 'sauce' : 'no sauce';
|
||||
const cheeseStr = (program.cheese === false) ? 'no cheese' : `${program.cheese} cheese`;
|
||||
console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);
|
||||
```
|
||||
|
||||
```bash
|
||||
$ pizza-options
|
||||
You ordered a pizza with sauce and mozzarella cheese
|
||||
$ pizza-options --sauce
|
||||
error: unknown option '--sauce'
|
||||
$ pizza-options --cheese=blue
|
||||
You ordered a pizza with sauce and blue cheese
|
||||
$ pizza-options --no-sauce --no-cheese
|
||||
You ordered a pizza with no sauce and no cheese
|
||||
```
|
||||
|
||||
You can specify an option which may be used as a boolean option but may optionally take an option-argument
|
||||
(declared with square brackets like `--optional [value]`).
|
||||
|
||||
Example file: [options-boolean-or-value.js](./examples/options-boolean-or-value.js)
|
||||
|
||||
```js
|
||||
program
|
||||
.option('-c, --cheese [type]', 'Add cheese with optional type');
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
if (program.cheese === undefined) console.log('no cheese');
|
||||
else if (program.cheese === true) console.log('add cheese');
|
||||
else console.log(`add cheese type ${program.cheese}`);
|
||||
```
|
||||
|
||||
```bash
|
||||
$ pizza-options
|
||||
no cheese
|
||||
$ pizza-options --cheese
|
||||
add cheese
|
||||
$ pizza-options --cheese mozzarella
|
||||
add cheese type mozzarella
|
||||
```
|
||||
|
||||
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
|
||||
|
||||
### Custom option processing
|
||||
|
||||
You may specify a function to do custom processing of option-arguments. The callback function receives two parameters,
|
||||
the user specified option-argument and the previous value for the option. It returns the new value for the option.
|
||||
|
||||
This allows you to coerce the option-argument to the desired type, or accumulate values, or do entirely custom processing.
|
||||
|
||||
You can optionally specify the default/starting value for the option after the function parameter.
|
||||
|
||||
Example file: [options-custom-processing.js](./examples/options-custom-processing.js)
|
||||
|
||||
```js
|
||||
function myParseInt(value, dummyPrevious) {
|
||||
// parseInt takes a string and an optional radix
|
||||
return parseInt(value);
|
||||
}
|
||||
|
||||
function increaseVerbosity(dummyValue, previous) {
|
||||
return previous + 1;
|
||||
}
|
||||
|
||||
function collect(value, previous) {
|
||||
return previous.concat([value]);
|
||||
}
|
||||
|
||||
function commaSeparatedList(value, dummyPrevious) {
|
||||
return value.split(',');
|
||||
}
|
||||
|
||||
program
|
||||
.option('-f, --float <number>', 'float argument', parseFloat)
|
||||
.option('-i, --integer <number>', 'integer argument', myParseInt)
|
||||
.option('-v, --verbose', 'verbosity that can be increased', increaseVerbosity, 0)
|
||||
.option('-c, --collect <value>', 'repeatable value', collect, [])
|
||||
.option('-l, --list <items>', 'comma separated list', commaSeparatedList)
|
||||
;
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
if (program.float !== undefined) console.log(`float: ${program.float}`);
|
||||
if (program.integer !== undefined) console.log(`integer: ${program.integer}`);
|
||||
if (program.verbose > 0) console.log(`verbosity: ${program.verbose}`);
|
||||
if (program.collect.length > 0) console.log(program.collect);
|
||||
if (program.list !== undefined) console.log(program.list);
|
||||
```
|
||||
|
||||
```bash
|
||||
$ custom -f 1e2
|
||||
float: 100
|
||||
$ custom --integer 2
|
||||
integer: 2
|
||||
$ custom -v -v -v
|
||||
verbose: 3
|
||||
$ custom -c a -c b -c c
|
||||
[ 'a', 'b', 'c' ]
|
||||
$ custom --list x,y,z
|
||||
[ 'x', 'y', 'z' ]
|
||||
```
|
||||
|
||||
### Required option
|
||||
|
||||
You may specify a required (mandatory) option using `.requiredOption`. The option must have a value after parsing, usually specified on the command line, or perhaps from a default value (say from environment). The method is otherwise the same as `.option` in format, taking flags and description, and optional default value or custom processing.
|
||||
|
||||
Example file: [options-required.js](./examples/options-required.js)
|
||||
|
||||
```js
|
||||
program
|
||||
.requiredOption('-c, --cheese <type>', 'pizza must have cheese');
|
||||
|
||||
program.parse(process.argv);
|
||||
```
|
||||
|
||||
```bash
|
||||
$ pizza
|
||||
error: required option '-c, --cheese <type>' not specified
|
||||
```
|
||||
|
||||
### Variadic option
|
||||
|
||||
You may make an option variadic by appending `...` to the value placeholder when declaring the option. On the command line you
|
||||
can then specify multiple option-arguments, and the parsed option value will be an array. The extra arguments
|
||||
are read until the first argument starting with a dash. The special argument `--` stops option processing entirely. If a value
|
||||
is specified in the same argument as the option then no further values are read.
|
||||
|
||||
Example file: [options-variadic.js](./examples/options-variadic.js)
|
||||
|
||||
```js
|
||||
program
|
||||
.option('-n, --number <numbers...>', 'specify numbers')
|
||||
.option('-l, --letter [letters...]', 'specify letters');
|
||||
|
||||
program.parse();
|
||||
|
||||
console.log('Options: ', program.opts());
|
||||
console.log('Remaining arguments: ', program.args);
|
||||
```
|
||||
|
||||
```bash
|
||||
$ collect -n 1 2 3 --letter a b c
|
||||
Options: { number: [ '1', '2', '3' ], letter: [ 'a', 'b', 'c' ] }
|
||||
Remaining arguments: []
|
||||
$ collect --letter=A -n80 operand
|
||||
Options: { number: [ '80' ], letter: [ 'A' ] }
|
||||
Remaining arguments: [ 'operand' ]
|
||||
$ collect --letter -n 1 -n 2 3 -- operand
|
||||
Options: { number: [ '1', '2', '3' ], letter: true }
|
||||
Remaining arguments: [ 'operand' ]
|
||||
```
|
||||
|
||||
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
|
||||
|
||||
### Version option
|
||||
|
||||
The optional `version` method adds handling for displaying the command version. The default option flags are `-V` and `--version`, and when present the command prints the version number and exits.
|
||||
|
||||
```js
|
||||
program.version('0.0.1');
|
||||
```
|
||||
|
||||
```bash
|
||||
$ ./examples/pizza -V
|
||||
0.0.1
|
||||
```
|
||||
|
||||
You may change the flags and description by passing additional parameters to the `version` method, using
|
||||
the same syntax for flags as the `option` method.
|
||||
|
||||
```js
|
||||
program.version('0.0.1', '-v, --vers', 'output the current version');
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
||||
You can specify (sub)commands using `.command()` or `.addCommand()`. There are two ways these can be implemented: using an action handler attached to the command, or as a stand-alone executable file (described in more detail later). The subcommands may be nested ([example](./examples/nestedCommands.js)).
|
||||
|
||||
In the first parameter to `.command()` you specify the command name and any command-arguments. The arguments may be `<required>` or `[optional]`, and the last argument may also be `variadic...`.
|
||||
|
||||
You can use `.addCommand()` to add an already configured subcommand to the program.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
// Command implemented using action handler (description is supplied separately to `.command`)
|
||||
// Returns new command for configuring.
|
||||
program
|
||||
.command('clone <source> [destination]')
|
||||
.description('clone a repository into a newly created directory')
|
||||
.action((source, destination) => {
|
||||
console.log('clone command called');
|
||||
});
|
||||
|
||||
// Command implemented using stand-alone executable file (description is second parameter to `.command`)
|
||||
// Returns `this` for adding more commands.
|
||||
program
|
||||
.command('start <service>', 'start named service')
|
||||
.command('stop [service]', 'stop named service, or all if no name supplied');
|
||||
|
||||
// Command prepared separately.
|
||||
// Returns `this` for adding more commands.
|
||||
program
|
||||
.addCommand(build.makeBuildCommand());
|
||||
```
|
||||
|
||||
Configuration options can be passed with the call to `.command()` and `.addCommand()`. Specifying `hidden: true` will
|
||||
remove the command from the generated help output. Specifying `isDefault: true` will run the subcommand if no other
|
||||
subcommand is specified ([example](./examples/defaultCommand.js)).
|
||||
|
||||
### Specify the argument syntax
|
||||
|
||||
You use `.arguments` to specify the expected command-arguments for the top-level command, and for subcommands they are usually
|
||||
included in the `.command` call. Angled brackets (e.g. `<required>`) indicate required command-arguments.
|
||||
Square brackets (e.g. `[optional]`) indicate optional command-arguments.
|
||||
You can optionally describe the arguments in the help by supplying a hash as second parameter to `.description()`.
|
||||
|
||||
Example file: [env](./examples/env)
|
||||
|
||||
```js
|
||||
program
|
||||
.version('0.1.0')
|
||||
.arguments('<cmd> [env]')
|
||||
.description('test command', {
|
||||
cmd: 'command to run',
|
||||
env: 'environment to run test in'
|
||||
})
|
||||
.action(function (cmd, env) {
|
||||
console.log('command:', cmd);
|
||||
console.log('environment:', env || 'no environment given');
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
```
|
||||
|
||||
The last argument of a command can be variadic, and only the last argument. To make an argument variadic you
|
||||
append `...` to the argument name. For example:
|
||||
|
||||
```js
|
||||
const { program } = require('commander');
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.command('rmdir <dir> [otherDirs...]')
|
||||
.action(function (dir, otherDirs) {
|
||||
console.log('rmdir %s', dir);
|
||||
if (otherDirs) {
|
||||
otherDirs.forEach(function (oDir) {
|
||||
console.log('rmdir %s', oDir);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
```
|
||||
|
||||
The variadic argument is passed to the action handler as an array.
|
||||
|
||||
### Action handler (sub)commands
|
||||
|
||||
You can add options to a command that uses an action handler.
|
||||
The action handler gets passed a parameter for each argument you declared, and one additional argument which is the
|
||||
command object itself. This command argument has the values for the command-specific options added as properties.
|
||||
|
||||
```js
|
||||
const { program } = require('commander');
|
||||
|
||||
program
|
||||
.command('rm <dir>')
|
||||
.option('-r, --recursive', 'Remove recursively')
|
||||
.action(function (dir, cmdObj) {
|
||||
console.log('remove ' + dir + (cmdObj.recursive ? ' recursively' : ''))
|
||||
})
|
||||
|
||||
program.parse(process.argv)
|
||||
```
|
||||
|
||||
You may supply an `async` action handler, in which case you call `.parseAsync` rather than `.parse`.
|
||||
|
||||
```js
|
||||
async function run() { /* code goes here */ }
|
||||
|
||||
async function main() {
|
||||
program
|
||||
.command('run')
|
||||
.action(run);
|
||||
await program.parseAsync(process.argv);
|
||||
}
|
||||
```
|
||||
|
||||
A command's options on the command line are validated when the command is used. Any unknown options will be reported as an error.
|
||||
|
||||
### Stand-alone executable (sub)commands
|
||||
|
||||
When `.command()` is invoked with a description argument, this tells Commander that you're going to use stand-alone executables for subcommands.
|
||||
Commander will search the executables in the directory of the entry script (like `./examples/pm`) with the name `program-subcommand`, like `pm-install`, `pm-search`.
|
||||
You can specify a custom name with the `executableFile` configuration option.
|
||||
|
||||
You handle the options for an executable (sub)command in the executable, and don't declare them at the top-level.
|
||||
|
||||
Example file: [pm](./examples/pm)
|
||||
|
||||
```js
|
||||
program
|
||||
.version('0.1.0')
|
||||
.command('install [name]', 'install one or more packages')
|
||||
.command('search [query]', 'search with optional query')
|
||||
.command('update', 'update installed packages', { executableFile: 'myUpdateSubCommand' })
|
||||
.command('list', 'list packages installed', { isDefault: true });
|
||||
|
||||
program.parse(process.argv);
|
||||
```
|
||||
|
||||
If the program is designed to be installed globally, make sure the executables have proper modes, like `755`.
|
||||
|
||||
## Automated help
|
||||
|
||||
The help information is auto-generated based on the information commander already knows about your program. The default
|
||||
help option is `-h,--help`.
|
||||
|
||||
Example file: [pizza](./examples/pizza)
|
||||
|
||||
```bash
|
||||
$ node ./examples/pizza --help
|
||||
Usage: pizza [options]
|
||||
|
||||
An application for pizzas ordering
|
||||
|
||||
Options:
|
||||
-V, --version output the version number
|
||||
-p, --peppers Add peppers
|
||||
-c, --cheese <type> Add the specified type of cheese (default: "marble")
|
||||
-C, --no-cheese You do not want any cheese
|
||||
-h, --help display help for command
|
||||
```
|
||||
|
||||
A `help` command is added by default if your command has subcommands. It can be used alone, or with a subcommand name to show
|
||||
further help for the subcommand. These are effectively the same if the `shell` program has implicit help:
|
||||
|
||||
```bash
|
||||
shell help
|
||||
shell --help
|
||||
|
||||
shell help spawn
|
||||
shell spawn --help
|
||||
```
|
||||
|
||||
### Custom help
|
||||
|
||||
You can display extra information by listening for "--help".
|
||||
|
||||
Example file: [custom-help](./examples/custom-help)
|
||||
|
||||
```js
|
||||
program
|
||||
.option('-f, --foo', 'enable some foo');
|
||||
|
||||
// must be before .parse()
|
||||
program.on('--help', () => {
|
||||
console.log('');
|
||||
console.log('Example call:');
|
||||
console.log(' $ custom-help --help');
|
||||
});
|
||||
```
|
||||
|
||||
Yields the following help output:
|
||||
|
||||
```Text
|
||||
Usage: custom-help [options]
|
||||
|
||||
Options:
|
||||
-f, --foo enable some foo
|
||||
-h, --help display help for command
|
||||
|
||||
Example call:
|
||||
$ custom-help --help
|
||||
```
|
||||
|
||||
### .usage and .name
|
||||
|
||||
These allow you to customise the usage description in the first line of the help. The name is otherwise
|
||||
deduced from the (full) program arguments. Given:
|
||||
|
||||
```js
|
||||
program
|
||||
.name("my-command")
|
||||
.usage("[global options] command")
|
||||
```
|
||||
|
||||
The help will start with:
|
||||
|
||||
```Text
|
||||
Usage: my-command [global options] command
|
||||
```
|
||||
|
||||
### .help(cb)
|
||||
|
||||
Output help information and exit immediately. Optional callback cb allows post-processing of help text before it is displayed.
|
||||
|
||||
### .outputHelp(cb)
|
||||
|
||||
Output help information without exiting.
|
||||
Optional callback cb allows post-processing of help text before it is displayed.
|
||||
|
||||
### .helpInformation()
|
||||
|
||||
Get the command help information as a string for processing or displaying yourself. (The text does not include the custom help
|
||||
from `--help` listeners.)
|
||||
|
||||
### .helpOption(flags, description)
|
||||
|
||||
Override the default help flags and description. Pass false to disable the built-in help option.
|
||||
|
||||
```js
|
||||
program
|
||||
.helpOption('-e, --HELP', 'read more information');
|
||||
```
|
||||
|
||||
### .addHelpCommand()
|
||||
|
||||
You can explicitly turn on or off the implicit help command with `.addHelpCommand()` and `.addHelpCommand(false)`.
|
||||
|
||||
You can both turn on and customise the help command by supplying the name and description:
|
||||
|
||||
```js
|
||||
program.addHelpCommand('assist [command]', 'show assistance');
|
||||
```
|
||||
|
||||
## Custom event listeners
|
||||
|
||||
You can execute custom actions by listening to command and option events.
|
||||
|
||||
```js
|
||||
program.on('option:verbose', function () {
|
||||
process.env.VERBOSE = this.verbose;
|
||||
});
|
||||
|
||||
program.on('command:*', function (operands) {
|
||||
console.error(`error: unknown command '${operands[0]}'`);
|
||||
const availableCommands = program.commands.map(cmd => cmd.name());
|
||||
mySuggestBestMatch(operands[0], availableCommands);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
```
|
||||
|
||||
## Bits and pieces
|
||||
|
||||
### .parse() and .parseAsync()
|
||||
|
||||
The first argument to `.parse` is the array of strings to parse. You may omit the parameter to implicitly use `process.argv`.
|
||||
|
||||
If the arguments follow different conventions than node you can pass a `from` option in the second parameter:
|
||||
|
||||
- 'node': default, `argv[0]` is the application and `argv[1]` is the script being run, with user parameters after that
|
||||
- 'electron': `argv[1]` varies depending on whether the electron application is packaged
|
||||
- 'user': all of the arguments from the user
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
program.parse(process.argv); // Explicit, node conventions
|
||||
program.parse(); // Implicit, and auto-detect electron
|
||||
program.parse(['-f', 'filename'], { from: 'user' });
|
||||
```
|
||||
|
||||
### Avoiding option name clashes
|
||||
|
||||
The original and default behaviour is that the option values are stored
|
||||
as properties on the program, and the action handler is passed a
|
||||
command object with the options values stored as properties.
|
||||
This is very convenient to code, but the downside is possible clashes with
|
||||
existing properties of Command.
|
||||
|
||||
There are two new routines to change the behaviour, and the default behaviour may change in the future:
|
||||
|
||||
- `storeOptionsAsProperties`: whether to store option values as properties on command object, or store separately (specify false) and access using `.opts()`
|
||||
- `passCommandToAction`: whether to pass command to action handler,
|
||||
or just the options (specify false)
|
||||
|
||||
Example file: [storeOptionsAsProperties-action.js](./examples/storeOptionsAsProperties-action.js)
|
||||
|
||||
```js
|
||||
program
|
||||
.storeOptionsAsProperties(false)
|
||||
.passCommandToAction(false);
|
||||
|
||||
program
|
||||
.name('my-program-name')
|
||||
.option('-n,--name <name>');
|
||||
|
||||
program
|
||||
.command('show')
|
||||
.option('-a,--action <action>')
|
||||
.action((options) => {
|
||||
console.log(options.action);
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
const programOptions = program.opts();
|
||||
console.log(programOptions.name);
|
||||
```
|
||||
|
||||
### TypeScript
|
||||
|
||||
The Commander package includes its TypeScript Definition file.
|
||||
|
||||
If you use `ts-node` and stand-alone executable subcommands written as `.ts` files, you need to call your program through node to get the subcommands called correctly. e.g.
|
||||
|
||||
```bash
|
||||
node -r ts-node/register pm.ts
|
||||
```
|
||||
|
||||
### createCommand()
|
||||
|
||||
This factory function creates a new command. It is exported and may be used instead of using `new`, like:
|
||||
|
||||
```js
|
||||
const { createCommand } = require('commander');
|
||||
const program = createCommand();
|
||||
```
|
||||
|
||||
`createCommand` is also a method of the Command object, and creates a new command rather than a subcommand. This gets used internally
|
||||
when creating subcommands using `.command()`, and you may override it to
|
||||
customise the new subcommand (examples using [subclass](./examples/custom-command-class.js) and [function](./examples/custom-command-function.js)).
|
||||
|
||||
### Import into ECMAScript Module
|
||||
|
||||
Commander is currently a CommonJS package, and the default export can be imported into an ES Module:
|
||||
|
||||
```js
|
||||
// index.mjs
|
||||
import commander from 'commander';
|
||||
const program = commander.program;
|
||||
const newCommand = new commander.Command();
|
||||
```
|
||||
|
||||
### Node options such as `--harmony`
|
||||
|
||||
You can enable `--harmony` option in two ways:
|
||||
|
||||
- Use `#! /usr/bin/env node --harmony` in the subcommands scripts. (Note Windows does not support this pattern.)
|
||||
- Use the `--harmony` option when call the command, like `node --harmony examples/pm publish`. The `--harmony` option will be preserved when spawning subcommand process.
|
||||
|
||||
### Debugging stand-alone executable subcommands
|
||||
|
||||
An executable subcommand is launched as a separate child process.
|
||||
|
||||
If you are using the node inspector for [debugging](https://nodejs.org/en/docs/guides/debugging-getting-started/) executable subcommands using `node --inspect` et al,
|
||||
the inspector port is incremented by 1 for the spawned subcommand.
|
||||
|
||||
If you are using VSCode to debug executable subcommands you need to set the `"autoAttachChildProcesses": true` flag in your launch.json configuration.
|
||||
|
||||
### Override exit handling
|
||||
|
||||
By default Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override
|
||||
this behaviour and optionally supply a callback. The default override throws a `CommanderError`.
|
||||
|
||||
The override callback is passed a `CommanderError` with properties `exitCode` number, `code` string, and `message`. The default override behaviour is to throw the error, except for async handling of executable subcommand completion which carries on. The normal display of error messages or version or help
|
||||
is not affected by the override which is called after the display.
|
||||
|
||||
```js
|
||||
program.exitOverride();
|
||||
|
||||
try {
|
||||
program.parse(process.argv);
|
||||
} catch (err) {
|
||||
// custom processing...
|
||||
}
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
Example file: [deploy](./examples/deploy)
|
||||
|
||||
```js
|
||||
const { program } = require('commander');
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.option('-C, --chdir <path>', 'change the working directory')
|
||||
.option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
|
||||
.option('-T, --no-tests', 'ignore test hook');
|
||||
|
||||
program
|
||||
.command('setup [env]')
|
||||
.description('run setup commands for all envs')
|
||||
.option("-s, --setup_mode [mode]", "Which setup mode to use")
|
||||
.action(function(env, options){
|
||||
const mode = options.setup_mode || "normal";
|
||||
env = env || 'all';
|
||||
console.log('setup for %s env(s) with %s mode', env, mode);
|
||||
});
|
||||
|
||||
program
|
||||
.command('exec <cmd>')
|
||||
.alias('ex')
|
||||
.description('execute the given remote cmd')
|
||||
.option("-e, --exec_mode <mode>", "Which exec mode to use")
|
||||
.action(function(cmd, options){
|
||||
console.log('exec "%s" using %s mode', cmd, options.exec_mode);
|
||||
}).on('--help', function() {
|
||||
console.log('');
|
||||
console.log('Examples:');
|
||||
console.log('');
|
||||
console.log(' $ deploy exec sequential');
|
||||
console.log(' $ deploy exec async');
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
```
|
||||
|
||||
More Demos can be found in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory.
|
||||
|
||||
## Support
|
||||
|
||||
The current version of Commander is fully supported on Long Term Support versions of Node, and is likely to work with Node 6 but not tested.
|
||||
(For versions of Node below Node 6, use Commander 3.x or 2.x.)
|
||||
|
||||
The main forum for free and community support is the project [Issues](https://github.com/tj/commander.js/issues) on GitHub.
|
||||
|
||||
### Commander for enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription
|
||||
|
||||
The maintainers of Commander and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-commander?utm_source=npm-commander&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
1881
book/node_modules/juice/node_modules/commander/index.js
generated
vendored
Normal file
1881
book/node_modules/juice/node_modules/commander/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
51
book/node_modules/juice/node_modules/commander/package.json
generated
vendored
Normal file
51
book/node_modules/juice/node_modules/commander/package.json
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "commander",
|
||||
"version": "6.2.1",
|
||||
"description": "the complete solution for node.js command-line programs",
|
||||
"keywords": [
|
||||
"commander",
|
||||
"command",
|
||||
"option",
|
||||
"parser",
|
||||
"cli",
|
||||
"argument",
|
||||
"args",
|
||||
"argv"
|
||||
],
|
||||
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/tj/commander.js.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint index.js \"tests/**/*.js\"",
|
||||
"typescript-lint": "eslint typings/*.ts",
|
||||
"test": "jest && npm run test-typings",
|
||||
"test-typings": "tsc -p tsconfig.json"
|
||||
},
|
||||
"main": "index",
|
||||
"files": [
|
||||
"index.js",
|
||||
"typings/index.d.ts"
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/node": "^14.14.2",
|
||||
"@typescript-eslint/eslint-plugin": "^4.5.0",
|
||||
"eslint": "^7.11.0",
|
||||
"eslint-config-standard-with-typescript": "^19.0.1",
|
||||
"eslint-plugin-jest": "^24.1.0",
|
||||
"jest": "^26.6.0",
|
||||
"standard": "^15.0.0",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"typings": "typings/index.d.ts",
|
||||
"jest": {
|
||||
"collectCoverage": true
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
}
|
||||
410
book/node_modules/juice/node_modules/commander/typings/index.d.ts
generated
vendored
Normal file
410
book/node_modules/juice/node_modules/commander/typings/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,410 @@
|
||||
// Type definitions for commander
|
||||
// Original definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>, Jules Randolph <https://github.com/sveinburne>
|
||||
|
||||
declare namespace commander {
|
||||
|
||||
interface CommanderError extends Error {
|
||||
code: string;
|
||||
exitCode: number;
|
||||
message: string;
|
||||
nestedError?: string;
|
||||
}
|
||||
type CommanderErrorConstructor = new (exitCode: number, code: string, message: string) => CommanderError;
|
||||
|
||||
interface Option {
|
||||
flags: string;
|
||||
required: boolean; // A value must be supplied when the option is specified.
|
||||
optional: boolean; // A value is optional when the option is specified.
|
||||
mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line.
|
||||
bool: boolean;
|
||||
short?: string;
|
||||
long: string;
|
||||
description: string;
|
||||
}
|
||||
type OptionConstructor = new (flags: string, description?: string) => Option;
|
||||
|
||||
interface ParseOptions {
|
||||
from: 'node' | 'electron' | 'user';
|
||||
}
|
||||
|
||||
interface Command {
|
||||
[key: string]: any; // options as properties
|
||||
|
||||
args: string[];
|
||||
|
||||
commands: Command[];
|
||||
|
||||
/**
|
||||
* Set the program version to `str`.
|
||||
*
|
||||
* This method auto-registers the "-V, --version" flag
|
||||
* which will print the version number when passed.
|
||||
*
|
||||
* You can optionally supply the flags and description to override the defaults.
|
||||
*/
|
||||
version(str: string, flags?: string, description?: string): this;
|
||||
|
||||
/**
|
||||
* Define a command, implemented using an action handler.
|
||||
*
|
||||
* @remarks
|
||||
* The command description is supplied using `.description`, not as a parameter to `.command`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* program
|
||||
* .command('clone <source> [destination]')
|
||||
* .description('clone a repository into a newly created directory')
|
||||
* .action((source, destination) => {
|
||||
* console.log('clone command called');
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
||||
* @param opts - configuration options
|
||||
* @returns new command
|
||||
*/
|
||||
command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>;
|
||||
/**
|
||||
* Define a command, implemented in a separate executable file.
|
||||
*
|
||||
* @remarks
|
||||
* The command description is supplied as the second parameter to `.command`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* program
|
||||
* .command('start <service>', 'start named service')
|
||||
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
||||
* ```
|
||||
*
|
||||
* @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
||||
* @param description - description of executable command
|
||||
* @param opts - configuration options
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
command(nameAndArgs: string, description: string, opts?: commander.ExecutableCommandOptions): this;
|
||||
|
||||
/**
|
||||
* Factory routine to create a new unattached command.
|
||||
*
|
||||
* See .command() for creating an attached subcommand, which uses this routine to
|
||||
* create the command. You can override createCommand to customise subcommands.
|
||||
*/
|
||||
createCommand(name?: string): Command;
|
||||
|
||||
/**
|
||||
* Add a prepared subcommand.
|
||||
*
|
||||
* See .command() for creating an attached subcommand which inherits settings from its parent.
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
addCommand(cmd: Command, opts?: CommandOptions): this;
|
||||
|
||||
/**
|
||||
* Define argument syntax for command.
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
arguments(desc: string): this;
|
||||
|
||||
/**
|
||||
* Override default decision whether to add implicit help command.
|
||||
*
|
||||
* addHelpCommand() // force on
|
||||
* addHelpCommand(false); // force off
|
||||
* addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
addHelpCommand(enableOrNameAndArgs?: string | boolean, description?: string): this;
|
||||
|
||||
/**
|
||||
* Register callback to use as replacement for calling process.exit.
|
||||
*/
|
||||
exitOverride(callback?: (err: CommanderError) => never|void): this;
|
||||
|
||||
/**
|
||||
* Register callback `fn` for the command.
|
||||
*
|
||||
* @example
|
||||
* program
|
||||
* .command('help')
|
||||
* .description('display verbose help')
|
||||
* .action(function() {
|
||||
* // output help here
|
||||
* });
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
action(fn: (...args: any[]) => void | Promise<void>): this;
|
||||
|
||||
/**
|
||||
* Define option with `flags`, `description` and optional
|
||||
* coercion `fn`.
|
||||
*
|
||||
* The `flags` string should contain both the short and long flags,
|
||||
* separated by comma, a pipe or space. The following are all valid
|
||||
* all will output this way when `--help` is used.
|
||||
*
|
||||
* "-p, --pepper"
|
||||
* "-p|--pepper"
|
||||
* "-p --pepper"
|
||||
*
|
||||
* @example
|
||||
* // simple boolean defaulting to false
|
||||
* program.option('-p, --pepper', 'add pepper');
|
||||
*
|
||||
* --pepper
|
||||
* program.pepper
|
||||
* // => Boolean
|
||||
*
|
||||
* // simple boolean defaulting to true
|
||||
* program.option('-C, --no-cheese', 'remove cheese');
|
||||
*
|
||||
* program.cheese
|
||||
* // => true
|
||||
*
|
||||
* --no-cheese
|
||||
* program.cheese
|
||||
* // => false
|
||||
*
|
||||
* // required argument
|
||||
* program.option('-C, --chdir <path>', 'change the working directory');
|
||||
*
|
||||
* --chdir /tmp
|
||||
* program.chdir
|
||||
* // => "/tmp"
|
||||
*
|
||||
* // optional argument
|
||||
* program.option('-c, --cheese [type]', 'add cheese [marble]');
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
option(flags: string, description?: string, defaultValue?: string | boolean): this;
|
||||
option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
|
||||
option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
|
||||
|
||||
/**
|
||||
* Define a required option, which must have a value after parsing. This usually means
|
||||
* the option must be specified on the command line. (Otherwise the same as .option().)
|
||||
*
|
||||
* The `flags` string should contain both the short and long flags, separated by comma, a pipe or space.
|
||||
*/
|
||||
requiredOption(flags: string, description?: string, defaultValue?: string | boolean): this;
|
||||
requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
|
||||
requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
|
||||
|
||||
/**
|
||||
* Whether to store option values as properties on command object,
|
||||
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
storeOptionsAsProperties(value?: boolean): this;
|
||||
|
||||
/**
|
||||
* Whether to pass command to action handler,
|
||||
* or just the options (specify false).
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
passCommandToAction(value?: boolean): this;
|
||||
|
||||
/**
|
||||
* Alter parsing of short flags with optional values.
|
||||
*
|
||||
* @example
|
||||
* // for `.option('-f,--flag [value]'):
|
||||
* .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
|
||||
* .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
combineFlagAndOptionalValue(arg?: boolean): this;
|
||||
|
||||
/**
|
||||
* Allow unknown options on the command line.
|
||||
*
|
||||
* @param [arg] if `true` or omitted, no error will be thrown for unknown options.
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
allowUnknownOption(arg?: boolean): this;
|
||||
|
||||
/**
|
||||
* Parse `argv`, setting options and invoking commands when defined.
|
||||
*
|
||||
* The default expectation is that the arguments are from node and have the application as argv[0]
|
||||
* and the script being run in argv[1], with user parameters after that.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* program.parse(process.argv);
|
||||
* program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
|
||||
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
parse(argv?: string[], options?: ParseOptions): this;
|
||||
|
||||
/**
|
||||
* Parse `argv`, setting options and invoking commands when defined.
|
||||
*
|
||||
* Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
|
||||
*
|
||||
* The default expectation is that the arguments are from node and have the application as argv[0]
|
||||
* and the script being run in argv[1], with user parameters after that.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* program.parseAsync(process.argv);
|
||||
* program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
|
||||
* program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
||||
*
|
||||
* @returns Promise
|
||||
*/
|
||||
parseAsync(argv?: string[], options?: ParseOptions): Promise<this>;
|
||||
|
||||
/**
|
||||
* Parse options from `argv` removing known options,
|
||||
* and return argv split into operands and unknown arguments.
|
||||
*
|
||||
* @example
|
||||
* argv => operands, unknown
|
||||
* --known kkk op => [op], []
|
||||
* op --known kkk => [op], []
|
||||
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
||||
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
||||
*/
|
||||
parseOptions(argv: string[]): commander.ParseOptionsResult;
|
||||
|
||||
/**
|
||||
* Return an object containing options as key-value pairs
|
||||
*/
|
||||
opts(): { [key: string]: any };
|
||||
|
||||
/**
|
||||
* Set the description.
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
description(str: string, argsDescription?: {[argName: string]: string}): this;
|
||||
/**
|
||||
* Get the description.
|
||||
*/
|
||||
description(): string;
|
||||
|
||||
/**
|
||||
* Set an alias for the command.
|
||||
*
|
||||
* You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
alias(alias: string): this;
|
||||
/**
|
||||
* Get alias for the command.
|
||||
*/
|
||||
alias(): string;
|
||||
|
||||
/**
|
||||
* Set aliases for the command.
|
||||
*
|
||||
* Only the first alias is shown in the auto-generated help.
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
aliases(aliases: string[]): this;
|
||||
/**
|
||||
* Get aliases for the command.
|
||||
*/
|
||||
aliases(): string[];
|
||||
|
||||
/**
|
||||
* Set the command usage.
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
usage(str: string): this;
|
||||
/**
|
||||
* Get the command usage.
|
||||
*/
|
||||
usage(): string;
|
||||
|
||||
/**
|
||||
* Set the name of the command.
|
||||
*
|
||||
* @returns `this` command for chaining
|
||||
*/
|
||||
name(str: string): this;
|
||||
/**
|
||||
* Get the name of the command.
|
||||
*/
|
||||
name(): string;
|
||||
|
||||
/**
|
||||
* Output help information for this command.
|
||||
*
|
||||
* When listener(s) are available for the helpLongFlag
|
||||
* those callbacks are invoked.
|
||||
*/
|
||||
outputHelp(cb?: (str: string) => string): void;
|
||||
|
||||
/**
|
||||
* Return command help documentation.
|
||||
*/
|
||||
helpInformation(): string;
|
||||
|
||||
/**
|
||||
* You can pass in flags and a description to override the help
|
||||
* flags and help description for your command. Pass in false
|
||||
* to disable the built-in help option.
|
||||
*/
|
||||
helpOption(flags?: string | boolean, description?: string): this;
|
||||
|
||||
/**
|
||||
* Output help information and exit.
|
||||
*/
|
||||
help(cb?: (str: string) => string): never;
|
||||
|
||||
/**
|
||||
* Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
|
||||
*
|
||||
* @example
|
||||
* program
|
||||
* .on('--help', () -> {
|
||||
* console.log('See web site for more information.');
|
||||
* });
|
||||
*/
|
||||
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
||||
}
|
||||
type CommandConstructor = new (name?: string) => Command;
|
||||
|
||||
interface CommandOptions {
|
||||
noHelp?: boolean; // old name for hidden
|
||||
hidden?: boolean;
|
||||
isDefault?: boolean;
|
||||
}
|
||||
interface ExecutableCommandOptions extends CommandOptions {
|
||||
executableFile?: string;
|
||||
}
|
||||
|
||||
interface ParseOptionsResult {
|
||||
operands: string[];
|
||||
unknown: string[];
|
||||
}
|
||||
|
||||
interface CommanderStatic extends Command {
|
||||
program: Command;
|
||||
Command: CommandConstructor;
|
||||
Option: OptionConstructor;
|
||||
CommanderError: CommanderErrorConstructor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Declaring namespace AND global
|
||||
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
||||
declare const commander: commander.CommanderStatic;
|
||||
export = commander;
|
||||
11
book/node_modules/juice/node_modules/css-select/LICENSE
generated
vendored
Normal file
11
book/node_modules/juice/node_modules/css-select/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
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.
|
||||
255
book/node_modules/juice/node_modules/css-select/README.md
generated
vendored
Normal file
255
book/node_modules/juice/node_modules/css-select/README.md
generated
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
# css-select [](https://npmjs.org/package/css-select) [](http://travis-ci.com/fb55/css-select) [](https://npmjs.org/package/css-select) [](https://coveralls.io/r/fb55/css-select)
|
||||
|
||||
A CSS selector compiler and engine
|
||||
|
||||
## What?
|
||||
|
||||
As a **compiler**, css-select turns CSS selectors into functions that tests if
|
||||
elements match them.
|
||||
|
||||
As an **engine**, css-select looks through a DOM tree, searching for elements.
|
||||
Elements are tested "from the top", similar to how browsers execute CSS
|
||||
selectors.
|
||||
|
||||
In its default configuration, css-select queries the DOM structure of the
|
||||
[`domhandler`](https://github.com/fb55/domhandler) module (also known as
|
||||
htmlparser2 DOM). To query alternative DOM structures, see [`Options`](#options)
|
||||
below.
|
||||
|
||||
**Features:**
|
||||
|
||||
- 🔬 Full implementation of CSS3 selectors, as well as most CSS4 selectors
|
||||
- 🧪 Partial implementation of jQuery/Sizzle extensions (see
|
||||
[cheerio-select](https://github.com/cheeriojs/cheerio-select) for the
|
||||
remaining selectors)
|
||||
- 🧑🔬 High test coverage, including the full test suites from Sizzle, Qwery and
|
||||
NWMatcher.
|
||||
- 🥼 Reliably great performance
|
||||
|
||||
## Why?
|
||||
|
||||
Most CSS engines written in JavaScript execute selectors left-to-right. That
|
||||
means thet execute every component of the selector in order, from left to right
|
||||
_(duh)_. As an example: For the selector `a b`, these engines will first query
|
||||
for `a` elements, then search these for `b` elements. (That's the approach of
|
||||
eg. [`Sizzle`](https://github.com/jquery/sizzle),
|
||||
[`nwmatcher`](https://github.com/dperini/nwmatcher/) and
|
||||
[`qwery`](https://github.com/ded/qwery).)
|
||||
|
||||
While this works, it has some downsides: Children of `a`s will be checked
|
||||
multiple times; first, to check if they are also `a`s, then, for every superior
|
||||
`a` once, if they are `b`s. Using
|
||||
[Big O notation](http://en.wikipedia.org/wiki/Big_O_notation), that would be
|
||||
`O(n^(k+1))`, where `k` is the number of descendant selectors (that's the space
|
||||
in the example above).
|
||||
|
||||
The far more efficient approach is to first look for `b` elements, then check if
|
||||
they have superior `a` elements: Using big O notation again, that would be
|
||||
`O(n)`. That's called right-to-left execution.
|
||||
|
||||
And that's what css-select does – and why it's quite performant.
|
||||
|
||||
## How does it work?
|
||||
|
||||
By building a stack of functions.
|
||||
|
||||
_Wait, what?_
|
||||
|
||||
Okay, so let's suppose we want to compile the selector `a b`, for right-to-left
|
||||
execution. We start by _parsing_ the selector. This turns the selector into an
|
||||
array of the building blocks. That's what the
|
||||
[`css-what`](https://github.com/fb55/css-what) module is for, if you want to
|
||||
have a look.
|
||||
|
||||
Anyway, after parsing, we end up with an array like this one:
|
||||
|
||||
```js
|
||||
[
|
||||
{ type: "tag", name: "a" },
|
||||
{ type: "descendant" },
|
||||
{ type: "tag", name: "b" },
|
||||
];
|
||||
```
|
||||
|
||||
(Actually, this array is wrapped in another array, but that's another story,
|
||||
involving commas in selectors.)
|
||||
|
||||
Now that we know the meaning of every part of the selector, we can compile it.
|
||||
That is where things become interesting.
|
||||
|
||||
The basic idea is to turn every part of the selector into a function, which
|
||||
takes an element as its only argument. The function checks whether a passed
|
||||
element matches its part of the selector: If it does, the element is passed to
|
||||
the next function representing the next part of the selector. That function does
|
||||
the same. If an element is accepted by all parts of the selector, it _matches_
|
||||
the selector and double rainbow ALL THE WAY.
|
||||
|
||||
As said before, we want to do right-to-left execution with all the big O
|
||||
improvements. That means elements are passed from the rightmost part of the
|
||||
selector (`b` in our example) to the leftmost (~~which would be `c`~~ of course
|
||||
`a`).
|
||||
|
||||
For traversals, such as the _descendant_ operating the space between `a` and
|
||||
`b`, we walk up the DOM tree, starting from the element passed as argument.
|
||||
|
||||
_//TODO: More in-depth description. Implementation details. Build a spaceship._
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
const CSSselect = require("css-select");
|
||||
```
|
||||
|
||||
**Note:** css-select throws errors when invalid selectors are passed to it.This
|
||||
is done to aid with writing css selectors, but can be unexpected when processing
|
||||
arbitrary strings.
|
||||
|
||||
#### `CSSselect.selectAll(query, elems, options)`
|
||||
|
||||
Queries `elems`, returns an array containing all matches.
|
||||
|
||||
- `query` can be either a CSS selector or a function.
|
||||
- `elems` can be either an array of elements, or a single element. If it is an
|
||||
element, its children will be queried.
|
||||
- `options` is described below.
|
||||
|
||||
Aliases: `default` export, `CSSselect.iterate(query, elems)`.
|
||||
|
||||
#### `CSSselect.compile(query, options)`
|
||||
|
||||
Compiles the query, returns a function.
|
||||
|
||||
#### `CSSselect.is(elem, query, options)`
|
||||
|
||||
Tests whether or not an element is matched by `query`. `query` can be either a
|
||||
CSS selector or a function.
|
||||
|
||||
#### `CSSselect.selectOne(query, elems, options)`
|
||||
|
||||
Arguments are the same as for `CSSselect.selectAll(query, elems)`. Only returns
|
||||
the first match, or `null` if there was no match.
|
||||
|
||||
### Options
|
||||
|
||||
All options are optional.
|
||||
|
||||
- `xmlMode`: When enabled, tag names will be case-sensitive. Default: `false`.
|
||||
- `rootFunc`: The last function in the stack, will be called with the last
|
||||
element that's looked at.
|
||||
- `adapter`: The adapter to use when interacting with the backing DOM
|
||||
structure. By default it uses the `domutils` module.
|
||||
- `context`: The context of the current query. Used to limit the scope of
|
||||
searches. Can be matched directly using the `:scope` pseudo-selector.
|
||||
- `cacheResults`: Allow css-select to cache results for some selectors,
|
||||
sometimes greatly improving querying performance. Disable this if your
|
||||
document can change in between queries with the same compiled selector.
|
||||
Default: `true`.
|
||||
|
||||
#### Custom Adapters
|
||||
|
||||
A custom adapter must match the interface described
|
||||
[here](https://github.com/fb55/css-select/blob/1aa44bdd64aaf2ebdfd7f338e2e76bed36521957/src/types.ts#L6-L96).
|
||||
|
||||
You may want to have a look at [`domutils`](https://github.com/fb55/domutils) to
|
||||
see the default implementation, or at
|
||||
[`css-select-browser-adapter`](https://github.com/nrkn/css-select-browser-adapter/blob/master/index.js)
|
||||
for an implementation backed by the DOM.
|
||||
|
||||
## Supported selectors
|
||||
|
||||
_As defined by CSS 4 and / or jQuery._
|
||||
|
||||
- [Selector lists](https://developer.mozilla.org/en-US/docs/Web/CSS/Selector_list)
|
||||
(`,`)
|
||||
- [Universal](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors)
|
||||
(`*`)
|
||||
- [Type](https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors)
|
||||
(`<tagname>`)
|
||||
- [Descendant](https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator)
|
||||
(` `)
|
||||
- [Child](https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator)
|
||||
(`>`)
|
||||
- Parent (`<`)
|
||||
- [Adjacent sibling](https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_combinator)
|
||||
(`+`)
|
||||
- [General sibling](https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_combinator)
|
||||
(`~`)
|
||||
- [Attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors)
|
||||
(`[attr=foo]`), with supported comparisons:
|
||||
- `[attr]` (existential)
|
||||
- `=`
|
||||
- `~=`
|
||||
- `|=`
|
||||
- `*=`
|
||||
- `^=`
|
||||
- `$=`
|
||||
- `!=`
|
||||
- `i` and `s` can be added after the comparison to make the comparison
|
||||
case-insensitive or case-sensitive (eg. `[attr=foo i]`). If neither is
|
||||
supplied, css-select will follow the HTML spec's
|
||||
[case-sensitivity rules](https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors).
|
||||
- Pseudos:
|
||||
- [`:not`](https://developer.mozilla.org/en-US/docs/Web/CSS/:not)
|
||||
- [`:contains`](https://api.jquery.com/contains-selector)
|
||||
- `:icontains` (case-insensitive version of `:contains`)
|
||||
- [`:has`](https://developer.mozilla.org/en-US/docs/Web/CSS/:has)
|
||||
- [`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root)
|
||||
- [`:empty`](https://developer.mozilla.org/en-US/docs/Web/CSS/:empty)
|
||||
- [`:parent`](https://api.jquery.com/parent-selector)
|
||||
- [`:first-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:first-child),
|
||||
[`:last-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:last-child),
|
||||
[`:first-of-type`](https://developer.mozilla.org/en-US/docs/Web/CSS/:first-of-type),
|
||||
[`:last-of-type`](https://developer.mozilla.org/en-US/docs/Web/CSS/:last-of-type)
|
||||
- [`:only-of-type`](https://developer.mozilla.org/en-US/docs/Web/CSS/:only-of-type),
|
||||
[`:only-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:only-child)
|
||||
- [`:nth-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child),
|
||||
[`:nth-last-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-last-child),
|
||||
[`:nth-of-type`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type),
|
||||
[`:nth-last-of-type`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-last-of-type),
|
||||
- [`:link`](https://developer.mozilla.org/en-US/docs/Web/CSS/:link),
|
||||
[`:any-link`](https://developer.mozilla.org/en-US/docs/Web/CSS/:any-link)
|
||||
- [`:visited`](https://developer.mozilla.org/en-US/docs/Web/CSS/:visited),
|
||||
[`:hover`](https://developer.mozilla.org/en-US/docs/Web/CSS/:hover),
|
||||
[`:active`](https://developer.mozilla.org/en-US/docs/Web/CSS/:active)
|
||||
(these depend on optional `Adapter` methods, so these will only match
|
||||
elements if implemented in `Adapter`)
|
||||
- [`:selected`](https://api.jquery.com/selected-selector),
|
||||
[`:checked`](https://developer.mozilla.org/en-US/docs/Web/CSS/:checked)
|
||||
- [`:enabled`](https://developer.mozilla.org/en-US/docs/Web/CSS/:enabled),
|
||||
[`:disabled`](https://developer.mozilla.org/en-US/docs/Web/CSS/:disabled)
|
||||
- [`:required`](https://developer.mozilla.org/en-US/docs/Web/CSS/:required),
|
||||
[`:optional`](https://developer.mozilla.org/en-US/docs/Web/CSS/:optional)
|
||||
- [`:header`](https://api.jquery.com/header-selector),
|
||||
[`:button`](https://api.jquery.com/button-selector),
|
||||
[`:input`](https://api.jquery.com/input-selector),
|
||||
[`:text`](https://api.jquery.com/text-selector),
|
||||
[`:checkbox`](https://api.jquery.com/checkbox-selector),
|
||||
[`:file`](https://api.jquery.com/file-selector),
|
||||
[`:password`](https://api.jquery.com/password-selector),
|
||||
[`:reset`](https://api.jquery.com/reset-selector),
|
||||
[`:radio`](https://api.jquery.com/radio-selector) etc.
|
||||
- [`:is`](https://developer.mozilla.org/en-US/docs/Web/CSS/:is), plus its
|
||||
legacy alias `:matches`
|
||||
- [`:scope`](https://developer.mozilla.org/en-US/docs/Web/CSS/:scope)
|
||||
(uses the context from the passed options)
|
||||
|
||||
---
|
||||
|
||||
License: BSD-2-Clause
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the
|
||||
[Tidelift security contact](https://tidelift.com/security). Tidelift will
|
||||
coordinate the fix and disclosure.
|
||||
|
||||
## `css-select` for enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription
|
||||
|
||||
The maintainers of `css-select` and thousands of other packages are working with
|
||||
Tidelift to deliver commercial support and maintenance for the open source
|
||||
dependencies you use to build your applications. Save time, reduce risk, and
|
||||
improve code health, while paying the maintainers of the exact dependencies you
|
||||
use.
|
||||
[Learn more.](https://tidelift.com/subscription/pkg/npm-css-select?utm_source=npm-css-select&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
7
book/node_modules/juice/node_modules/css-select/lib/attributes.d.ts
generated
vendored
Normal file
7
book/node_modules/juice/node_modules/css-select/lib/attributes.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
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
|
||||
1
book/node_modules/juice/node_modules/css-select/lib/attributes.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/css-select/lib/attributes.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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;AA+EnE;;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,CAsLlC,CAAC"}
|
||||
232
book/node_modules/juice/node_modules/css-select/lib/attributes.js
generated
vendored
Normal file
232
book/node_modules/juice/node_modules/css-select/lib/attributes.js
generated
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
"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, "\\$&");
|
||||
}
|
||||
/**
|
||||
* Attributes that are case-insensitive in HTML.
|
||||
*
|
||||
* @private
|
||||
* @see https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors
|
||||
*/
|
||||
var caseInsensitiveAttributes = new Set([
|
||||
"accept",
|
||||
"accept-charset",
|
||||
"align",
|
||||
"alink",
|
||||
"axis",
|
||||
"bgcolor",
|
||||
"charset",
|
||||
"checked",
|
||||
"clear",
|
||||
"codetype",
|
||||
"color",
|
||||
"compact",
|
||||
"declare",
|
||||
"defer",
|
||||
"dir",
|
||||
"direction",
|
||||
"disabled",
|
||||
"enctype",
|
||||
"face",
|
||||
"frame",
|
||||
"hreflang",
|
||||
"http-equiv",
|
||||
"lang",
|
||||
"language",
|
||||
"link",
|
||||
"media",
|
||||
"method",
|
||||
"multiple",
|
||||
"nohref",
|
||||
"noresize",
|
||||
"noshade",
|
||||
"nowrap",
|
||||
"readonly",
|
||||
"rel",
|
||||
"rev",
|
||||
"rules",
|
||||
"scope",
|
||||
"scrolling",
|
||||
"selected",
|
||||
"shape",
|
||||
"target",
|
||||
"text",
|
||||
"type",
|
||||
"valign",
|
||||
"valuetype",
|
||||
"vlink",
|
||||
]);
|
||||
function shouldIgnoreCase(selector, options) {
|
||||
return typeof selector.ignoreCase === "boolean"
|
||||
? selector.ignoreCase
|
||||
: selector.ignoreCase === "quirks"
|
||||
? !!options.quirksMode
|
||||
: !options.xmlMode && caseInsensitiveAttributes.has(selector.name);
|
||||
}
|
||||
/**
|
||||
* Attribute selectors
|
||||
*/
|
||||
exports.attributeRules = {
|
||||
equals: function (next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
if (shouldIgnoreCase(data, options)) {
|
||||
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, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
var len = value.length;
|
||||
if (shouldIgnoreCase(data, options)) {
|
||||
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, data, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name, value = data.value;
|
||||
if (/\s/.test(value)) {
|
||||
return boolbase_1.falseFunc;
|
||||
}
|
||||
var regex = new RegExp("(?:^|\\s)".concat(escapeRegex(value), "(?:$|\\s)"), shouldIgnoreCase(data, options) ? "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, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
var len = value.length;
|
||||
if (len === 0) {
|
||||
return boolbase_1.falseFunc;
|
||||
}
|
||||
if (shouldIgnoreCase(data, options)) {
|
||||
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, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
var len = -value.length;
|
||||
if (len === 0) {
|
||||
return boolbase_1.falseFunc;
|
||||
}
|
||||
if (shouldIgnoreCase(data, options)) {
|
||||
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, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name, value = data.value;
|
||||
if (value === "") {
|
||||
return boolbase_1.falseFunc;
|
||||
}
|
||||
if (shouldIgnoreCase(data, options)) {
|
||||
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, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
if (value === "") {
|
||||
return function (elem) {
|
||||
return !!adapter.getAttributeValue(elem, name) && next(elem);
|
||||
};
|
||||
}
|
||||
else if (shouldIgnoreCase(data, options)) {
|
||||
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);
|
||||
};
|
||||
},
|
||||
};
|
||||
14
book/node_modules/juice/node_modules/css-select/lib/compile.d.ts
generated
vendored
Normal file
14
book/node_modules/juice/node_modules/css-select/lib/compile.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
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<Node>;
|
||||
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
|
||||
1
book/node_modules/juice/node_modules/css-select/lib/compile.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/css-select/lib/compile.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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,EAAgB,MAAM,UAAU,CAAC;AASzD,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,IAAI,CAAC,CAGrB;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,CAG5B;AAiDD,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"}
|
||||
119
book/node_modules/juice/node_modules/css-select/lib/compile.js
generated
vendored
Normal file
119
book/node_modules/juice/node_modules/css-select/lib/compile.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
"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 (0, subselects_1.ensureIsTag)(next, options.adapter);
|
||||
}
|
||||
exports.compile = compile;
|
||||
function compileUnsafe(selector, options, context) {
|
||||
var token = typeof selector === "string" ? (0, css_what_1.parse)(selector) : 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: css_what_1.SelectorType.Descendant };
|
||||
var FLEXIBLE_DESCENDANT_TOKEN = {
|
||||
type: "_flexibleDescendant",
|
||||
};
|
||||
var SCOPE_TOKEN = {
|
||||
type: css_what_1.SelectorType.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 && (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
|
||||
: (0, 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);
|
||||
};
|
||||
}
|
||||
3
book/node_modules/juice/node_modules/css-select/lib/general.d.ts
generated
vendored
Normal file
3
book/node_modules/juice/node_modules/css-select/lib/general.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
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
|
||||
1
book/node_modules/juice/node_modules/css-select/lib/general.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/css-select/lib/general.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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;AAOjB,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,CAiK5B"}
|
||||
140
book/node_modules/juice/node_modules/css-select/lib/general.js
generated
vendored
Normal file
140
book/node_modules/juice/node_modules/css-select/lib/general.js
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.compileGeneralSelector = void 0;
|
||||
var attributes_1 = require("./attributes");
|
||||
var pseudo_selectors_1 = require("./pseudo-selectors");
|
||||
var css_what_1 = require("css-what");
|
||||
/*
|
||||
* All available rules
|
||||
*/
|
||||
function compileGeneralSelector(next, selector, options, context, compileToken) {
|
||||
var adapter = options.adapter, equals = options.equals;
|
||||
switch (selector.type) {
|
||||
case css_what_1.SelectorType.PseudoElement: {
|
||||
throw new Error("Pseudo-elements are not supported by css-select");
|
||||
}
|
||||
case css_what_1.SelectorType.ColumnCombinator: {
|
||||
throw new Error("Column combinators are not yet supported by css-select");
|
||||
}
|
||||
case css_what_1.SelectorType.Attribute: {
|
||||
if (selector.namespace != null) {
|
||||
throw new Error("Namespaced attributes are not yet supported by css-select");
|
||||
}
|
||||
if (!options.xmlMode || options.lowerCaseAttributeNames) {
|
||||
selector.name = selector.name.toLowerCase();
|
||||
}
|
||||
return attributes_1.attributeRules[selector.action](next, selector, options);
|
||||
}
|
||||
case css_what_1.SelectorType.Pseudo: {
|
||||
return (0, pseudo_selectors_1.compilePseudoSelector)(next, selector, options, context, compileToken);
|
||||
}
|
||||
// Tags
|
||||
case css_what_1.SelectorType.Tag: {
|
||||
if (selector.namespace != null) {
|
||||
throw new Error("Namespaced tag names are not yet supported by css-select");
|
||||
}
|
||||
var name_1 = selector.name;
|
||||
if (!options.xmlMode || options.lowerCaseTags) {
|
||||
name_1 = name_1.toLowerCase();
|
||||
}
|
||||
return function tag(elem) {
|
||||
return adapter.getName(elem) === name_1 && next(elem);
|
||||
};
|
||||
}
|
||||
// Traversal
|
||||
case css_what_1.SelectorType.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
|
||||
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 css_what_1.SelectorType.Parent: {
|
||||
return function parent(elem) {
|
||||
return adapter
|
||||
.getChildren(elem)
|
||||
.some(function (elem) { return adapter.isTag(elem) && next(elem); });
|
||||
};
|
||||
}
|
||||
case css_what_1.SelectorType.Child: {
|
||||
return function child(elem) {
|
||||
var parent = adapter.getParent(elem);
|
||||
return parent != null && adapter.isTag(parent) && next(parent);
|
||||
};
|
||||
}
|
||||
case css_what_1.SelectorType.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 css_what_1.SelectorType.Adjacent: {
|
||||
if (adapter.prevElementSibling) {
|
||||
return function adjacent(elem) {
|
||||
var previous = adapter.prevElementSibling(elem);
|
||||
return previous != null && next(previous);
|
||||
};
|
||||
}
|
||||
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 css_what_1.SelectorType.Universal: {
|
||||
if (selector.namespace != null && selector.namespace !== "*") {
|
||||
throw new Error("Namespaced universal selectors are not yet supported by css-select");
|
||||
}
|
||||
return next;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.compileGeneralSelector = compileGeneralSelector;
|
||||
49
book/node_modules/juice/node_modules/css-select/lib/index.d.ts
generated
vendored
Normal file
49
book/node_modules/juice/node_modules/css-select/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
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<Node_1>;
|
||||
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
|
||||
1
book/node_modules/juice/node_modules/css-select/lib/index.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/css-select/lib/index.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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,gNAA0B,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;AAiBD;;;;;;;;;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"}
|
||||
149
book/node_modules/juice/node_modules/css-select/lib/index.js
generated
vendored
Normal file
149
book/node_modules/juice/node_modules/css-select/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (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 = (0, 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];
|
||||
var elemsLength = elems.length;
|
||||
for (var i = 0; i < elemsLength; i++) {
|
||||
var nextSiblings = (0, 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 : (0, 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; } });
|
||||
5
book/node_modules/juice/node_modules/css-select/lib/procedure.d.ts
generated
vendored
Normal file
5
book/node_modules/juice/node_modules/css-select/lib/procedure.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
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
|
||||
1
book/node_modules/juice/node_modules/css-select/lib/procedure.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/css-select/lib/procedure.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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,CAa9D,CAAC;AAEF,wBAAgB,WAAW,CAAC,CAAC,EAAE,gBAAgB,GAAG,CAAC,IAAI,SAAS,CAE/D"}
|
||||
21
book/node_modules/juice/node_modules/css-select/lib/procedure.js
generated
vendored
Normal file
21
book/node_modules/juice/node_modules/css-select/lib/procedure.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"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,
|
||||
"column-combinator": -1,
|
||||
descendant: -1,
|
||||
child: -1,
|
||||
parent: -1,
|
||||
sibling: -1,
|
||||
adjacent: -1,
|
||||
_flexibleDescendant: -1,
|
||||
};
|
||||
function isTraversal(t) {
|
||||
return exports.procedure[t.type] < 0;
|
||||
}
|
||||
exports.isTraversal = isTraversal;
|
||||
5
book/node_modules/juice/node_modules/css-select/lib/pseudo-selectors/aliases.d.ts
generated
vendored
Normal file
5
book/node_modules/juice/node_modules/css-select/lib/pseudo-selectors/aliases.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Aliases are pseudos that are expressed as selectors.
|
||||
*/
|
||||
export declare const aliases: Record<string, string>;
|
||||
//# sourceMappingURL=aliases.d.ts.map
|
||||
1
book/node_modules/juice/node_modules/css-select/lib/pseudo-selectors/aliases.d.ts.map
generated
vendored
Normal file
1
book/node_modules/juice/node_modules/css-select/lib/pseudo-selectors/aliases.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"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"}
|
||||
33
book/node_modules/juice/node_modules/css-select/lib/pseudo-selectors/aliases.js
generated
vendored
Normal file
33
book/node_modules/juice/node_modules/css-select/lib/pseudo-selectors/aliases.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
"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])",
|
||||
};
|
||||
4
book/node_modules/juice/node_modules/css-select/lib/pseudo-selectors/filters.d.ts
generated
vendored
Normal file
4
book/node_modules/juice/node_modules/css-select/lib/pseudo-selectors/filters.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user