rahad-media-downloader 2.1.7 → 2.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. package/.cache/typescript/5.3/node_modules/.package-lock.json +54 -0
  2. package/.cache/typescript/5.3/node_modules/@types/cookie/LICENSE +21 -0
  3. package/.cache/typescript/5.3/node_modules/@types/cookie/README.md +15 -0
  4. package/.cache/typescript/5.3/node_modules/@types/cookie/index.d.ts +154 -0
  5. package/.cache/typescript/5.3/node_modules/@types/cookie/package.json +30 -0
  6. package/.cache/typescript/5.3/node_modules/@types/domhandler/LICENSE +21 -0
  7. package/.cache/typescript/5.3/node_modules/@types/domhandler/README.md +92 -0
  8. package/.cache/typescript/5.3/node_modules/@types/domhandler/index.d.ts +73 -0
  9. package/.cache/typescript/5.3/node_modules/@types/domhandler/package.json +25 -0
  10. package/.cache/typescript/5.3/node_modules/@types/domutils/LICENSE +21 -0
  11. package/.cache/typescript/5.3/node_modules/@types/domutils/README.md +15 -0
  12. package/.cache/typescript/5.3/node_modules/@types/domutils/index.d.ts +124 -0
  13. package/.cache/typescript/5.3/node_modules/@types/domutils/package.json +27 -0
  14. package/.cache/typescript/5.3/node_modules/@types/htmlparser2/LICENSE +21 -0
  15. package/.cache/typescript/5.3/node_modules/@types/htmlparser2/README.md +15 -0
  16. package/.cache/typescript/5.3/node_modules/@types/htmlparser2/index.d.ts +120 -0
  17. package/.cache/typescript/5.3/node_modules/@types/htmlparser2/package.json +45 -0
  18. package/.cache/typescript/5.3/node_modules/@types/psl/LICENSE +21 -0
  19. package/.cache/typescript/5.3/node_modules/@types/psl/README.md +52 -0
  20. package/.cache/typescript/5.3/node_modules/@types/psl/index.d.ts +33 -0
  21. package/.cache/typescript/5.3/node_modules/@types/psl/package.json +25 -0
  22. package/.cache/typescript/5.3/node_modules/domelementtype/LICENSE +11 -0
  23. package/.cache/typescript/5.3/node_modules/domelementtype/index.js +15 -0
  24. package/.cache/typescript/5.3/node_modules/domelementtype/package.json +16 -0
  25. package/.cache/typescript/5.3/node_modules/domelementtype/readme.md +1 -0
  26. package/.cache/typescript/5.3/node_modules/domhandler/.travis.yml +6 -0
  27. package/.cache/typescript/5.3/node_modules/domhandler/LICENSE +11 -0
  28. package/.cache/typescript/5.3/node_modules/domhandler/index.js +217 -0
  29. package/.cache/typescript/5.3/node_modules/domhandler/lib/element.js +20 -0
  30. package/.cache/typescript/5.3/node_modules/domhandler/lib/node.js +44 -0
  31. package/.cache/typescript/5.3/node_modules/domhandler/package.json +41 -0
  32. package/.cache/typescript/5.3/node_modules/domhandler/readme.md +116 -0
  33. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/01-basic.json +57 -0
  34. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/02-single_tag_1.json +21 -0
  35. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/03-single_tag_2.json +21 -0
  36. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/04-unescaped_in_script.json +27 -0
  37. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/05-tags_in_comment.json +18 -0
  38. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/06-comment_in_script.json +18 -0
  39. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/07-unescaped_in_style.json +20 -0
  40. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/08-extra_spaces_in_tag.json +20 -0
  41. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/09-unquoted_attrib.json +20 -0
  42. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/10-singular_attribute.json +15 -0
  43. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/11-text_outside_tags.json +40 -0
  44. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/12-text_only.json +11 -0
  45. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/13-comment_in_text.json +19 -0
  46. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/14-comment_in_text_in_script.json +18 -0
  47. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/15-non-verbose.json +22 -0
  48. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/16-normalize_whitespace.json +47 -0
  49. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/17-xml_namespace.json +18 -0
  50. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/18-enforce_empty_tags.json +16 -0
  51. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/19-ignore_empty_tags.json +20 -0
  52. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/20-template_script_tags.json +20 -0
  53. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/21-conditional_comments.json +15 -0
  54. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/22-lowercase_tags.json +41 -0
  55. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/23-dom-lvl1.json +131 -0
  56. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/24-with-start-indices.json +85 -0
  57. package/.cache/typescript/5.3/node_modules/domhandler/test/cases/25-with-end-indices.json +86 -0
  58. package/.cache/typescript/5.3/node_modules/domhandler/test/tests.js +60 -0
  59. package/.cache/typescript/5.3/package-lock.json +57 -0
  60. package/.cache/typescript/5.3/package.json +1 -1
  61. package/README.md +103 -18
  62. package/index.js +1 -1
  63. package/package.json +4 -3
  64. package/test.js +0 -35
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@types/domutils",
3
+ "version": "1.7.8",
4
+ "description": "TypeScript definitions for domutils",
5
+ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/domutils",
6
+ "license": "MIT",
7
+ "contributors": [
8
+ {
9
+ "name": "Johan Davidsson",
10
+ "githubUsername": "johandavidson",
11
+ "url": "https://github.com/johandavidson"
12
+ }
13
+ ],
14
+ "main": "",
15
+ "types": "index.d.ts",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
19
+ "directory": "types/domutils"
20
+ },
21
+ "scripts": {},
22
+ "dependencies": {
23
+ "@types/domhandler": "^2.4.0"
24
+ },
25
+ "typesPublisherContentHash": "47b4f35bd1ab60f1f9aa1d01b90bbd9df04900a53578910effa2218c147ff8aa",
26
+ "typeScriptVersion": "4.5"
27
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1,15 @@
1
+ # Installation
2
+ > `npm install --save @types/htmlparser2`
3
+
4
+ # Summary
5
+ This package contains type definitions for htmlparser2 (https://github.com/fb55/htmlparser2/).
6
+
7
+ # Details
8
+ Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/htmlparser2.
9
+
10
+ ### Additional Details
11
+ * Last updated: Tue, 07 Nov 2023 03:09:37 GMT
12
+ * Dependencies: [@types/domhandler](https://npmjs.com/package/@types/domhandler), [@types/domutils](https://npmjs.com/package/@types/domutils), [@types/node](https://npmjs.com/package/@types/node), [domhandler](https://npmjs.com/package/domhandler)
13
+
14
+ # Credits
15
+ These definitions were written by [James Roland Cabresos](https://github.com/staticfunction), [Linus Unnebäck](https://github.com/LinusU), [Johan Davidsson](https://github.com/johandavidson), and [GP](https://github.com/paambaati).
@@ -0,0 +1,120 @@
1
+ /// <reference types="node"/>
2
+ /// <reference types="domhandler"/>
3
+ /// <reference types="domutils"/>
4
+
5
+ import { DomHandler } from "domhandler";
6
+ import * as DomUtils from "domutils";
7
+ import { Writable } from "stream";
8
+ export { DomElement, DomHandler, DomHandlerOptions, Element, Node } from "domhandler";
9
+
10
+ export interface ParserOptions {
11
+ /***
12
+ * Indicates whether special tags (<script> and <style>) should get special treatment
13
+ * and if "empty" tags (eg. <br>) can have children. If false, the content of special tags
14
+ * will be text only. For feeds and other XML content (documents that don't consist of HTML),
15
+ * set this to true. Default: false.
16
+ */
17
+ xmlMode?: boolean | undefined;
18
+
19
+ /***
20
+ * If set to true, entities within the document will be decoded. Defaults to false.
21
+ */
22
+ decodeEntities?: boolean | undefined;
23
+
24
+ /***
25
+ * If set to true, all tags will be lowercased. If xmlMode is disabled, this defaults to true.
26
+ */
27
+ lowerCaseTags?: boolean | undefined;
28
+
29
+ /***
30
+ * If set to true, all attribute names will be lowercased. This has noticeable impact on speed, so it defaults to false.
31
+ */
32
+ lowerCaseAttributeNames?: boolean | undefined;
33
+
34
+ /***
35
+ * If set to true, CDATA sections will be recognized as text even if the xmlMode option is not enabled.
36
+ * NOTE: If xmlMode is set to true then CDATA sections will always be recognized as text.
37
+ */
38
+ recognizeCDATA?: boolean | undefined;
39
+
40
+ /***
41
+ * If set to true, self-closing tags will trigger the onclosetag event even if xmlMode is not set to true.
42
+ * NOTE: If xmlMode is set to true then self-closing tags will always be recognized.
43
+ */
44
+ recognizeSelfClosing?: boolean | undefined;
45
+ }
46
+ /**
47
+ * @deprecated
48
+ */
49
+ export type Options = ParserOptions;
50
+
51
+ export declare class WritableStream extends Writable {
52
+ constructor(handler: DomHandler, options?: ParserOptions);
53
+ }
54
+
55
+ export declare class Parser {
56
+ constructor(handler: Partial<DomHandler>, options?: ParserOptions);
57
+
58
+ /***
59
+ * Parses a chunk of data and calls the corresponding callbacks.
60
+ * @param input
61
+ */
62
+ write(input: string): void;
63
+
64
+ /***
65
+ * alias for backwards compat
66
+ */
67
+ parseChunk(chunk: string): void;
68
+
69
+ /***
70
+ * Parses the end of the buffer and clears the stack, calls onend.
71
+ */
72
+ end(): void;
73
+
74
+ /***
75
+ * Parses the end of the buffer and clears the stack, calls onend.
76
+ */
77
+ end(chunk: string): void;
78
+
79
+ /***
80
+ * alias for backwards compat
81
+ */
82
+ done(): void;
83
+
84
+ /***
85
+ * Pauses the parser
86
+ */
87
+ pause(): void;
88
+
89
+ /***
90
+ * Resumes the parser
91
+ */
92
+ resume(): void;
93
+
94
+ /***
95
+ * Resets the parser, parses the data & calls end.
96
+ * @param input
97
+ */
98
+ parseComplete(input: string): void;
99
+
100
+ /***
101
+ * Resets buffer & stack, calls onreset.
102
+ */
103
+ reset(): void;
104
+
105
+ ontext(data: any): void;
106
+ onopentagname(name: string): void;
107
+ onopentagend(): void;
108
+ onclosetag(name: string): void;
109
+ onselfclosingtag(): void;
110
+ onattribname(name: string): void;
111
+ onattribend(): void;
112
+ ondeclaration(): void;
113
+ onprocessinginstruction(value: string): void;
114
+ oncomment(value: string): void;
115
+ oncdata(value: string): void;
116
+ onerror(err: Error): void;
117
+ onend(): void;
118
+ }
119
+
120
+ export { DomUtils };
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@types/htmlparser2",
3
+ "version": "3.10.7",
4
+ "description": "TypeScript definitions for htmlparser2",
5
+ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/htmlparser2",
6
+ "license": "MIT",
7
+ "contributors": [
8
+ {
9
+ "name": "James Roland Cabresos",
10
+ "githubUsername": "staticfunction",
11
+ "url": "https://github.com/staticfunction"
12
+ },
13
+ {
14
+ "name": "Linus Unnebäck",
15
+ "githubUsername": "LinusU",
16
+ "url": "https://github.com/LinusU"
17
+ },
18
+ {
19
+ "name": "Johan Davidsson",
20
+ "githubUsername": "johandavidson",
21
+ "url": "https://github.com/johandavidson"
22
+ },
23
+ {
24
+ "name": "GP",
25
+ "githubUsername": "paambaati",
26
+ "url": "https://github.com/paambaati"
27
+ }
28
+ ],
29
+ "main": "",
30
+ "types": "index.d.ts",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
34
+ "directory": "types/htmlparser2"
35
+ },
36
+ "scripts": {},
37
+ "dependencies": {
38
+ "@types/domhandler": "^2.4.3",
39
+ "@types/domutils": "*",
40
+ "@types/node": "*",
41
+ "domhandler": "^2.4.0"
42
+ },
43
+ "typesPublisherContentHash": "7570ab2cb2f14acf512a1ef3bba9d03939e5d09f4c1e62cc1ac7072be9276c51",
44
+ "typeScriptVersion": "4.5"
45
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1,52 @@
1
+ # Installation
2
+ > `npm install --save @types/psl`
3
+
4
+ # Summary
5
+ This package contains type definitions for psl (https://github.com/wrangr/psl#readme).
6
+
7
+ # Details
8
+ Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/psl.
9
+ ## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/psl/index.d.ts)
10
+ ````ts
11
+ export as namespace psl;
12
+
13
+ export function parse(domain: string): ParsedDomain | ParseError;
14
+
15
+ export function get(domain: null | undefined): null;
16
+ export function get(domain: string): string | null;
17
+
18
+ export function isValid(domain: string): boolean;
19
+
20
+ export interface ParsedDomain {
21
+ tld: string | null;
22
+ sld: string | null;
23
+ domain: string | null;
24
+ subdomain: string | null;
25
+ listed: boolean;
26
+ input: string;
27
+ error: undefined;
28
+ }
29
+
30
+ export interface ParseError {
31
+ input: string;
32
+ error: {
33
+ code:
34
+ | "DOMAIN_TOO_SHORT"
35
+ | "DOMAIN_TOO_LONG"
36
+ | "LABEL_STARTS_WITH_DASH"
37
+ | "LABEL_ENDS_WITH_DASH"
38
+ | "LABEL_TOO_LONG"
39
+ | "LABEL_TOO_SHORT"
40
+ | "LABEL_INVALID_CHARS";
41
+ message: string;
42
+ };
43
+ }
44
+
45
+ ````
46
+
47
+ ### Additional Details
48
+ * Last updated: Tue, 07 Nov 2023 09:09:39 GMT
49
+ * Dependencies: none
50
+
51
+ # Credits
52
+ These definitions were written by [BendingBender](https://github.com/BendingBender).
@@ -0,0 +1,33 @@
1
+ export as namespace psl;
2
+
3
+ export function parse(domain: string): ParsedDomain | ParseError;
4
+
5
+ export function get(domain: null | undefined): null;
6
+ export function get(domain: string): string | null;
7
+
8
+ export function isValid(domain: string): boolean;
9
+
10
+ export interface ParsedDomain {
11
+ tld: string | null;
12
+ sld: string | null;
13
+ domain: string | null;
14
+ subdomain: string | null;
15
+ listed: boolean;
16
+ input: string;
17
+ error: undefined;
18
+ }
19
+
20
+ export interface ParseError {
21
+ input: string;
22
+ error: {
23
+ code:
24
+ | "DOMAIN_TOO_SHORT"
25
+ | "DOMAIN_TOO_LONG"
26
+ | "LABEL_STARTS_WITH_DASH"
27
+ | "LABEL_ENDS_WITH_DASH"
28
+ | "LABEL_TOO_LONG"
29
+ | "LABEL_TOO_SHORT"
30
+ | "LABEL_INVALID_CHARS";
31
+ message: string;
32
+ };
33
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@types/psl",
3
+ "version": "1.1.3",
4
+ "description": "TypeScript definitions for psl",
5
+ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/psl",
6
+ "license": "MIT",
7
+ "contributors": [
8
+ {
9
+ "name": "BendingBender",
10
+ "githubUsername": "BendingBender",
11
+ "url": "https://github.com/BendingBender"
12
+ }
13
+ ],
14
+ "main": "",
15
+ "types": "index.d.ts",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
19
+ "directory": "types/psl"
20
+ },
21
+ "scripts": {},
22
+ "dependencies": {},
23
+ "typesPublisherContentHash": "2ac885b5f54b365a7da61c11266487ec8d0f8aa45863110a485cf4b868dde10e",
24
+ "typeScriptVersion": "4.5"
25
+ }
@@ -0,0 +1,11 @@
1
+ Copyright (c) Felix Böhm
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 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.
9
+
10
+ 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,
11
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,15 @@
1
+ //Types of elements found in the DOM
2
+ module.exports = {
3
+ Text: "text", //Text
4
+ Directive: "directive", //<? ... ?>
5
+ Comment: "comment", //<!-- ... -->
6
+ Script: "script", //<script> tags
7
+ Style: "style", //<style> tags
8
+ Tag: "tag", //Any tag
9
+ CDATA: "cdata", //<![CDATA[ ... ]]>
10
+ Doctype: "doctype",
11
+
12
+ isTag: function(elem){
13
+ return elem.type === "tag" || elem.type === "script" || elem.type === "style";
14
+ }
15
+ };
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "domelementtype",
3
+ "version": "1.3.1",
4
+ "description": "all the types of nodes in htmlparser2's dom",
5
+ "main": "index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git://github.com/fb55/domelementtype.git"
9
+ },
10
+ "keywords": [
11
+ "dom",
12
+ "htmlparser2"
13
+ ],
14
+ "author": "Felix Boehm <me@feedic.com>",
15
+ "license": "BSD-2-Clause"
16
+ }
@@ -0,0 +1 @@
1
+ all the types of nodes in htmlparser2's dom
@@ -0,0 +1,6 @@
1
+ before_install:
2
+ - '[ "${TRAVIS_NODE_VERSION}" != "0.8" ] || npm install -g npm@1.4.28'
3
+ - npm install -g npm@latest
4
+ language: node_js
5
+ node_js:
6
+ - 8
@@ -0,0 +1,11 @@
1
+ Copyright (c) Felix Böhm
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 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.
9
+
10
+ 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,
11
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,217 @@
1
+ var ElementType = require("domelementtype");
2
+
3
+ var re_whitespace = /\s+/g;
4
+ var NodePrototype = require("./lib/node");
5
+ var ElementPrototype = require("./lib/element");
6
+
7
+ function DomHandler(callback, options, elementCB){
8
+ if(typeof callback === "object"){
9
+ elementCB = options;
10
+ options = callback;
11
+ callback = null;
12
+ } else if(typeof options === "function"){
13
+ elementCB = options;
14
+ options = defaultOpts;
15
+ }
16
+ this._callback = callback;
17
+ this._options = options || defaultOpts;
18
+ this._elementCB = elementCB;
19
+ this.dom = [];
20
+ this._done = false;
21
+ this._tagStack = [];
22
+ this._parser = this._parser || null;
23
+ }
24
+
25
+ //default options
26
+ var defaultOpts = {
27
+ normalizeWhitespace: false, //Replace all whitespace with single spaces
28
+ withStartIndices: false, //Add startIndex properties to nodes
29
+ withEndIndices: false, //Add endIndex properties to nodes
30
+ };
31
+
32
+ DomHandler.prototype.onparserinit = function(parser){
33
+ this._parser = parser;
34
+ };
35
+
36
+ //Resets the handler back to starting state
37
+ DomHandler.prototype.onreset = function(){
38
+ DomHandler.call(this, this._callback, this._options, this._elementCB);
39
+ };
40
+
41
+ //Signals the handler that parsing is done
42
+ DomHandler.prototype.onend = function(){
43
+ if(this._done) return;
44
+ this._done = true;
45
+ this._parser = null;
46
+ this._handleCallback(null);
47
+ };
48
+
49
+ DomHandler.prototype._handleCallback =
50
+ DomHandler.prototype.onerror = function(error){
51
+ if(typeof this._callback === "function"){
52
+ this._callback(error, this.dom);
53
+ } else {
54
+ if(error) throw error;
55
+ }
56
+ };
57
+
58
+ DomHandler.prototype.onclosetag = function(){
59
+ //if(this._tagStack.pop().name !== name) this._handleCallback(Error("Tagname didn't match!"));
60
+
61
+ var elem = this._tagStack.pop();
62
+
63
+ if(this._options.withEndIndices && elem){
64
+ elem.endIndex = this._parser.endIndex;
65
+ }
66
+
67
+ if(this._elementCB) this._elementCB(elem);
68
+ };
69
+
70
+ DomHandler.prototype._createDomElement = function(properties){
71
+ if (!this._options.withDomLvl1) return properties;
72
+
73
+ var element;
74
+ if (properties.type === "tag") {
75
+ element = Object.create(ElementPrototype);
76
+ } else {
77
+ element = Object.create(NodePrototype);
78
+ }
79
+
80
+ for (var key in properties) {
81
+ if (properties.hasOwnProperty(key)) {
82
+ element[key] = properties[key];
83
+ }
84
+ }
85
+
86
+ return element;
87
+ };
88
+
89
+ DomHandler.prototype._addDomElement = function(element){
90
+ var parent = this._tagStack[this._tagStack.length - 1];
91
+ var siblings = parent ? parent.children : this.dom;
92
+ var previousSibling = siblings[siblings.length - 1];
93
+
94
+ element.next = null;
95
+
96
+ if(this._options.withStartIndices){
97
+ element.startIndex = this._parser.startIndex;
98
+ }
99
+ if(this._options.withEndIndices){
100
+ element.endIndex = this._parser.endIndex;
101
+ }
102
+
103
+ if(previousSibling){
104
+ element.prev = previousSibling;
105
+ previousSibling.next = element;
106
+ } else {
107
+ element.prev = null;
108
+ }
109
+
110
+ siblings.push(element);
111
+ element.parent = parent || null;
112
+ };
113
+
114
+ DomHandler.prototype.onopentag = function(name, attribs){
115
+ var properties = {
116
+ type: name === "script" ? ElementType.Script : name === "style" ? ElementType.Style : ElementType.Tag,
117
+ name: name,
118
+ attribs: attribs,
119
+ children: []
120
+ };
121
+
122
+ var element = this._createDomElement(properties);
123
+
124
+ this._addDomElement(element);
125
+
126
+ this._tagStack.push(element);
127
+ };
128
+
129
+ DomHandler.prototype.ontext = function(data){
130
+ //the ignoreWhitespace is officially dropped, but for now,
131
+ //it's an alias for normalizeWhitespace
132
+ var normalize = this._options.normalizeWhitespace || this._options.ignoreWhitespace;
133
+
134
+ var lastTag;
135
+
136
+ if(!this._tagStack.length && this.dom.length && (lastTag = this.dom[this.dom.length-1]).type === ElementType.Text){
137
+ if(normalize){
138
+ lastTag.data = (lastTag.data + data).replace(re_whitespace, " ");
139
+ } else {
140
+ lastTag.data += data;
141
+ }
142
+ } else {
143
+ if(
144
+ this._tagStack.length &&
145
+ (lastTag = this._tagStack[this._tagStack.length - 1]) &&
146
+ (lastTag = lastTag.children[lastTag.children.length - 1]) &&
147
+ lastTag.type === ElementType.Text
148
+ ){
149
+ if(normalize){
150
+ lastTag.data = (lastTag.data + data).replace(re_whitespace, " ");
151
+ } else {
152
+ lastTag.data += data;
153
+ }
154
+ } else {
155
+ if(normalize){
156
+ data = data.replace(re_whitespace, " ");
157
+ }
158
+
159
+ var element = this._createDomElement({
160
+ data: data,
161
+ type: ElementType.Text
162
+ });
163
+
164
+ this._addDomElement(element);
165
+ }
166
+ }
167
+ };
168
+
169
+ DomHandler.prototype.oncomment = function(data){
170
+ var lastTag = this._tagStack[this._tagStack.length - 1];
171
+
172
+ if(lastTag && lastTag.type === ElementType.Comment){
173
+ lastTag.data += data;
174
+ return;
175
+ }
176
+
177
+ var properties = {
178
+ data: data,
179
+ type: ElementType.Comment
180
+ };
181
+
182
+ var element = this._createDomElement(properties);
183
+
184
+ this._addDomElement(element);
185
+ this._tagStack.push(element);
186
+ };
187
+
188
+ DomHandler.prototype.oncdatastart = function(){
189
+ var properties = {
190
+ children: [{
191
+ data: "",
192
+ type: ElementType.Text
193
+ }],
194
+ type: ElementType.CDATA
195
+ };
196
+
197
+ var element = this._createDomElement(properties);
198
+
199
+ this._addDomElement(element);
200
+ this._tagStack.push(element);
201
+ };
202
+
203
+ DomHandler.prototype.oncommentend = DomHandler.prototype.oncdataend = function(){
204
+ this._tagStack.pop();
205
+ };
206
+
207
+ DomHandler.prototype.onprocessinginstruction = function(name, data){
208
+ var element = this._createDomElement({
209
+ name: name,
210
+ data: data,
211
+ type: ElementType.Directive
212
+ });
213
+
214
+ this._addDomElement(element);
215
+ };
216
+
217
+ module.exports = DomHandler;
@@ -0,0 +1,20 @@
1
+ // DOM-Level-1-compliant structure
2
+ var NodePrototype = require('./node');
3
+ var ElementPrototype = module.exports = Object.create(NodePrototype);
4
+
5
+ var domLvl1 = {
6
+ tagName: "name"
7
+ };
8
+
9
+ Object.keys(domLvl1).forEach(function(key) {
10
+ var shorthand = domLvl1[key];
11
+ Object.defineProperty(ElementPrototype, key, {
12
+ get: function() {
13
+ return this[shorthand] || null;
14
+ },
15
+ set: function(val) {
16
+ this[shorthand] = val;
17
+ return val;
18
+ }
19
+ });
20
+ });