@opacedev/astro-ai-content-checker 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +138 -0
- package/LICENSE +9 -0
- package/README.md +236 -0
- package/SBOM.cdx.json +172 -0
- package/SECURITY.md +9 -0
- package/THIRD_PARTY_NOTICES.md +36 -0
- package/dist/build-report-html.d.ts +3 -0
- package/dist/highlight.js +155 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +43 -0
- package/dist/options.d.ts +21 -0
- package/dist/options.js +6 -0
- package/dist/receipt.d.ts +15 -0
- package/dist/receipt.js +100 -0
- package/dist/report.d.ts +55 -0
- package/dist/report.js +12 -0
- package/dist/sections.js +181 -0
- package/dist/share.d.ts +47 -0
- package/dist/share.js +72 -0
- package/dist/shared-EX54KI6H.js +1503 -0
- package/dist/shared-MMXWTX2U.js +43 -0
- package/dist/toolbar.js +13478 -0
- package/node_modules/@opacedev/ai-content-checker-browser/LICENSE +21 -0
- package/node_modules/@opacedev/ai-content-checker-browser/README.md +145 -0
- package/node_modules/@opacedev/ai-content-checker-browser/dist/dom/visible-text.d.ts +14 -0
- package/node_modules/@opacedev/ai-content-checker-browser/dist/dom/visible-text.js +47 -0
- package/node_modules/@opacedev/ai-content-checker-browser/dist/index.d.ts +3 -0
- package/node_modules/@opacedev/ai-content-checker-browser/dist/index.js +99 -0
- package/node_modules/@opacedev/ai-content-checker-browser/dist/worker/client.d.ts +12 -0
- package/node_modules/@opacedev/ai-content-checker-browser/dist/worker/client.js +17 -0
- package/node_modules/@opacedev/ai-content-checker-browser/dist/worker/entry.d.ts +1 -0
- package/node_modules/@opacedev/ai-content-checker-browser/dist/worker/entry.js +3984 -0
- package/node_modules/@opacedev/ai-content-checker-browser/dist/worker/protocol.d.ts +30 -0
- package/node_modules/@opacedev/ai-content-checker-browser/dist/worker/protocol.js +1 -0
- package/node_modules/@opacedev/ai-content-checker-browser/package.json +60 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/LICENSE +21 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/README.md +93 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/dist/index.d.ts +58 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/dist/index.js +17 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/package.json +57 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/analysis-request.schema.d.ts +44 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/analysis-result.schema.d.ts +122 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/candidate.schema.d.ts +81 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/capabilities.schema.d.ts +24 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/checker-result.schema.d.ts +342 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/common.schema.d.ts +10 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/envelope.schema.d.ts +14 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/gate-result.schema.d.ts +19 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/integrity-receipt.schema.d.ts +122 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/job.schema.d.ts +188 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/method-result.schema.d.ts +39 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/pattern-finding.schema.d.ts +26 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/protected-span.schema.d.ts +35 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/generated/rewrite-request.schema.d.ts +65 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/index.ts +63 -0
- package/node_modules/@opacedev/ai-content-checker-contracts/src/semantic-validation.mjs +32 -0
- package/node_modules/@opacedev/ai-content-checker-core/LICENSE +21 -0
- package/node_modules/@opacedev/ai-content-checker-core/README.md +186 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/bundle.js +4744 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/capabilities.d.ts +16 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/capabilities.js +7 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/diff/diff.d.ts +17 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/diff/diff.js +76 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/fixes/preview.d.ts +27 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/fixes/preview.js +47 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/gates/policy.d.ts +14 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/gates/policy.js +16 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/index.d.ts +15 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/index.js +15 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/inspect.d.ts +8 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/inspect.js +84 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-gb-v1.d.ts +12 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-gb-v1.js +68 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v2-data.d.ts +73 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v2-data.js +499 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v2.d.ts +76 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v2.js +1067 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v3-data.d.ts +165 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v3-data.js +614 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v3.d.ts +19 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v3.js +542 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v4-corpus.d.ts +40 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v4-corpus.js +40 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v4-data.d.ts +138 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v4-data.js +200 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v4.d.ts +71 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/patterns/en-signals-v4.js +388 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/protected/extract.d.ts +17 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/protected/extract.js +75 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/protected/validate.d.ts +3 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/protected/validate.js +17 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/provenance/c2pa-text.d.ts +55 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/provenance/c2pa-text.js +86 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/receipts/build.d.ts +48 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/receipts/build.js +61 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/report/checker-result.d.ts +241 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/report/checker-result.js +419 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/source/offsets.d.ts +34 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/source/offsets.js +51 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/source/utf8.d.ts +3 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/source/utf8.js +58 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/source/visible-text.d.ts +12 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/source/visible-text.js +30 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/unicode/data.d.ts +22 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/unicode/data.js +137 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/unicode/inspect.d.ts +16 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/unicode/inspect.js +84 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/verdict/combine.d.ts +162 -0
- package/node_modules/@opacedev/ai-content-checker-core/dist/verdict/combine.js +501 -0
- package/node_modules/@opacedev/ai-content-checker-core/package.json +62 -0
- package/node_modules/canonicalize/LICENSE +201 -0
- package/node_modules/canonicalize/README.md +65 -0
- package/node_modules/canonicalize/bin/canonicalize.js +17 -0
- package/node_modules/canonicalize/lib/canonicalize.d.ts +2 -0
- package/node_modules/canonicalize/lib/canonicalize.js +74 -0
- package/node_modules/canonicalize/package.json +64 -0
- package/node_modules/entities/LICENSE +11 -0
- package/node_modules/entities/lib/decode.d.ts +211 -0
- package/node_modules/entities/lib/decode.d.ts.map +1 -0
- package/node_modules/entities/lib/decode.js +536 -0
- package/node_modules/entities/lib/decode.js.map +1 -0
- package/node_modules/entities/lib/decode_codepoint.d.ts +19 -0
- package/node_modules/entities/lib/decode_codepoint.d.ts.map +1 -0
- package/node_modules/entities/lib/decode_codepoint.js +76 -0
- package/node_modules/entities/lib/decode_codepoint.js.map +1 -0
- package/node_modules/entities/lib/encode.d.ts +22 -0
- package/node_modules/entities/lib/encode.d.ts.map +1 -0
- package/node_modules/entities/lib/encode.js +77 -0
- package/node_modules/entities/lib/encode.js.map +1 -0
- package/node_modules/entities/lib/escape.d.ts +43 -0
- package/node_modules/entities/lib/escape.d.ts.map +1 -0
- package/node_modules/entities/lib/escape.js +122 -0
- package/node_modules/entities/lib/escape.js.map +1 -0
- package/node_modules/entities/lib/esm/decode.d.ts +211 -0
- package/node_modules/entities/lib/esm/decode.d.ts.map +1 -0
- package/node_modules/entities/lib/esm/decode.js +496 -0
- package/node_modules/entities/lib/esm/decode.js.map +1 -0
- package/node_modules/entities/lib/esm/decode_codepoint.d.ts +19 -0
- package/node_modules/entities/lib/esm/decode_codepoint.d.ts.map +1 -0
- package/node_modules/entities/lib/esm/decode_codepoint.js +71 -0
- package/node_modules/entities/lib/esm/decode_codepoint.js.map +1 -0
- package/node_modules/entities/lib/esm/encode.d.ts +22 -0
- package/node_modules/entities/lib/esm/encode.d.ts.map +1 -0
- package/node_modules/entities/lib/esm/encode.js +69 -0
- package/node_modules/entities/lib/esm/encode.js.map +1 -0
- package/node_modules/entities/lib/esm/escape.d.ts +43 -0
- package/node_modules/entities/lib/esm/escape.d.ts.map +1 -0
- package/node_modules/entities/lib/esm/escape.js +116 -0
- package/node_modules/entities/lib/esm/escape.js.map +1 -0
- package/node_modules/entities/lib/esm/generated/decode-data-html.d.ts +3 -0
- package/node_modules/entities/lib/esm/generated/decode-data-html.d.ts.map +1 -0
- package/node_modules/entities/lib/esm/generated/decode-data-html.js +7 -0
- package/node_modules/entities/lib/esm/generated/decode-data-html.js.map +1 -0
- package/node_modules/entities/lib/esm/generated/decode-data-xml.d.ts +3 -0
- package/node_modules/entities/lib/esm/generated/decode-data-xml.d.ts.map +1 -0
- package/node_modules/entities/lib/esm/generated/decode-data-xml.js +7 -0
- package/node_modules/entities/lib/esm/generated/decode-data-xml.js.map +1 -0
- package/node_modules/entities/lib/esm/generated/encode-html.d.ts +8 -0
- package/node_modules/entities/lib/esm/generated/encode-html.d.ts.map +1 -0
- package/node_modules/entities/lib/esm/generated/encode-html.js +10 -0
- package/node_modules/entities/lib/esm/generated/encode-html.js.map +1 -0
- package/node_modules/entities/lib/esm/index.d.ts +96 -0
- package/node_modules/entities/lib/esm/index.d.ts.map +1 -0
- package/node_modules/entities/lib/esm/index.js +99 -0
- package/node_modules/entities/lib/esm/index.js.map +1 -0
- package/node_modules/entities/lib/esm/package.json +1 -0
- package/node_modules/entities/lib/generated/decode-data-html.d.ts +3 -0
- package/node_modules/entities/lib/generated/decode-data-html.d.ts.map +1 -0
- package/node_modules/entities/lib/generated/decode-data-html.js +9 -0
- package/node_modules/entities/lib/generated/decode-data-html.js.map +1 -0
- package/node_modules/entities/lib/generated/decode-data-xml.d.ts +3 -0
- package/node_modules/entities/lib/generated/decode-data-xml.d.ts.map +1 -0
- package/node_modules/entities/lib/generated/decode-data-xml.js +9 -0
- package/node_modules/entities/lib/generated/decode-data-xml.js.map +1 -0
- package/node_modules/entities/lib/generated/encode-html.d.ts +8 -0
- package/node_modules/entities/lib/generated/encode-html.d.ts.map +1 -0
- package/node_modules/entities/lib/generated/encode-html.js +12 -0
- package/node_modules/entities/lib/generated/encode-html.js.map +1 -0
- package/node_modules/entities/lib/index.d.ts +96 -0
- package/node_modules/entities/lib/index.d.ts.map +1 -0
- package/node_modules/entities/lib/index.js +126 -0
- package/node_modules/entities/lib/index.js.map +1 -0
- package/node_modules/entities/package.json +90 -0
- package/node_modules/entities/readme.md +122 -0
- package/package.json +91 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[](https://github.com/erdtman/canonicalize/actions/workflows/ci.yml)
|
|
2
|
+
# canonicalize
|
|
3
|
+
JSON canonicalize function. Creates crypto safe predictable canonicalization of
|
|
4
|
+
JSON as defined by [RFC8785](https://tools.ietf.org/html/rfc8785).
|
|
5
|
+
|
|
6
|
+
TypeScript type definitions are included.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
### Normal Example
|
|
10
|
+
```js
|
|
11
|
+
import canonicalize from 'canonicalize';
|
|
12
|
+
const json = {
|
|
13
|
+
"from_account": "543 232 625-3",
|
|
14
|
+
"to_account": "321 567 636-4",
|
|
15
|
+
"amount": 500,
|
|
16
|
+
"currency": "USD"
|
|
17
|
+
}
|
|
18
|
+
console.log(canonicalize(json));
|
|
19
|
+
// output: {"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}
|
|
20
|
+
```
|
|
21
|
+
### Crazy Example
|
|
22
|
+
```js
|
|
23
|
+
import canonicalize from 'canonicalize';
|
|
24
|
+
const json = {
|
|
25
|
+
"1": {"f": {"f": "hi","F": 5} ,"\n": 56.0},
|
|
26
|
+
"10": { },
|
|
27
|
+
"": "empty",
|
|
28
|
+
"a": { },
|
|
29
|
+
"111": [ {"e": "yes","E": "no" } ],
|
|
30
|
+
"A": { }
|
|
31
|
+
}
|
|
32
|
+
console.log(canonicalize(json));
|
|
33
|
+
// output: {"":"empty","1":{"\n":56,"f":{"F":5,"f":"hi"}},"10":{},"111":[{"E":"no","e":"yes"}],"A":{},"a":{}}
|
|
34
|
+
```
|
|
35
|
+
### Via CLI
|
|
36
|
+
The function can be executed directly using npx without explicit installation. This allows JSON files and arbitrary input to be canonicalized with standard input/output:
|
|
37
|
+
```bash
|
|
38
|
+
# Input from file
|
|
39
|
+
npx canonicalize < input.json > output.json
|
|
40
|
+
|
|
41
|
+
# Input from string
|
|
42
|
+
echo '{
|
|
43
|
+
"from_account": "543 232 625-3",
|
|
44
|
+
"to_account": "321 567 636-4",
|
|
45
|
+
"amount": 500,
|
|
46
|
+
"currency": "USD"
|
|
47
|
+
}' | npx canonicalize > simple-data.json
|
|
48
|
+
|
|
49
|
+
# Input from web API
|
|
50
|
+
curl --silent https://pokeapi.co/api/v2/pokemon/pikachu | npx canonicalize > pikachu.json
|
|
51
|
+
```
|
|
52
|
+
## Install
|
|
53
|
+
As a library:
|
|
54
|
+
```
|
|
55
|
+
npm install canonicalize --save
|
|
56
|
+
```
|
|
57
|
+
As a CLI tool:
|
|
58
|
+
```
|
|
59
|
+
npm install -g canonicalize
|
|
60
|
+
canonicalize < input.json > output.json
|
|
61
|
+
```
|
|
62
|
+
## Test
|
|
63
|
+
```
|
|
64
|
+
npm test
|
|
65
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import canonicalize from '../lib/canonicalize.js';
|
|
4
|
+
|
|
5
|
+
let input = '';
|
|
6
|
+
|
|
7
|
+
process.stdin
|
|
8
|
+
.on('data', (data) => { input += data.toString(); })
|
|
9
|
+
.on('end', () => {
|
|
10
|
+
try {
|
|
11
|
+
const output = canonicalize(JSON.parse(input));
|
|
12
|
+
process.stdout.write(output, 'utf-8');
|
|
13
|
+
} catch (e) {
|
|
14
|
+
process.stderr.write(`Error: ${e.message}\n`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
function hasLoneSurrogate (value) {
|
|
2
|
+
for (let i = 0; i < value.length; i++) {
|
|
3
|
+
const code = value.charCodeAt(i);
|
|
4
|
+
|
|
5
|
+
if (code >= 0xD800 && code <= 0xDBFF) {
|
|
6
|
+
if (i === value.length - 1) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
const next = value.charCodeAt(i + 1);
|
|
10
|
+
if (!(next >= 0xDC00 && next <= 0xDFFF)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
i++;
|
|
14
|
+
} else if (code >= 0xDC00 && code <= 0xDFFF) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default function canonicalize (object, seen = new Set()) {
|
|
23
|
+
if (typeof object === 'number' && isNaN(object)) {
|
|
24
|
+
throw new Error('NaN is not allowed');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (typeof object === 'number' && !isFinite(object)) {
|
|
28
|
+
throw new Error('Infinity is not allowed');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (typeof object === 'string' && hasLoneSurrogate(object)) {
|
|
32
|
+
throw new Error('Lone surrogate is not allowed');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (object === null || typeof object !== 'object') {
|
|
36
|
+
return JSON.stringify(object);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof object.toJSON === 'function') {
|
|
40
|
+
if (seen.has(object)) {
|
|
41
|
+
throw new Error('Circular reference detected');
|
|
42
|
+
}
|
|
43
|
+
seen.add(object);
|
|
44
|
+
const result = canonicalize(object.toJSON(), seen);
|
|
45
|
+
seen.delete(object);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (seen.has(object)) {
|
|
50
|
+
throw new Error('Circular reference detected');
|
|
51
|
+
}
|
|
52
|
+
seen.add(object);
|
|
53
|
+
|
|
54
|
+
let result;
|
|
55
|
+
if (Array.isArray(object)) {
|
|
56
|
+
const values = object.map((cv) => {
|
|
57
|
+
const value = cv === undefined || typeof cv === 'symbol' ? null : cv;
|
|
58
|
+
return canonicalize(value, seen);
|
|
59
|
+
});
|
|
60
|
+
result = `[${values.join(',')}]`;
|
|
61
|
+
} else {
|
|
62
|
+
const parts = [];
|
|
63
|
+
for (const key of Object.keys(object).sort()) {
|
|
64
|
+
if (object[key] === undefined || typeof object[key] === 'symbol') {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
parts.push(`${canonicalize(key)}:${canonicalize(object[key], seen)}`);
|
|
68
|
+
}
|
|
69
|
+
result = `{${parts.join(',')}}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
seen.delete(object);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "canonicalize",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "JSON canonicalize function",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./lib/canonicalize.js",
|
|
9
|
+
"types": "./lib/canonicalize.d.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"main": "lib/canonicalize.js",
|
|
13
|
+
"types": "lib/canonicalize.d.ts",
|
|
14
|
+
"bin": {
|
|
15
|
+
"canonicalize": "bin/canonicalize.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib/",
|
|
19
|
+
"bin/"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"lint": "eslint .",
|
|
26
|
+
"lint:fix": "eslint --fix .",
|
|
27
|
+
"test": "node --test test/*.js",
|
|
28
|
+
"coverage": "c8 npm test",
|
|
29
|
+
"coveragehtml": "c8 report -r html",
|
|
30
|
+
"precoveragehtml": "npm run coverage"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/erdtman/canonicalize.git"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"json",
|
|
38
|
+
"canonical",
|
|
39
|
+
"canonicalize",
|
|
40
|
+
"signing",
|
|
41
|
+
"crypto"
|
|
42
|
+
],
|
|
43
|
+
"contributors": [
|
|
44
|
+
{
|
|
45
|
+
"name": "Samuel Erdtman",
|
|
46
|
+
"email": "samuel@erdtman.se"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "Anders Rundgren",
|
|
50
|
+
"email": "anders.rundgren.net@gmail.com"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@eslint/js": "^9.0.0",
|
|
55
|
+
"c8": "^10.0.0",
|
|
56
|
+
"eslint": "^9.0.0",
|
|
57
|
+
"globals": "^15.0.0"
|
|
58
|
+
},
|
|
59
|
+
"license": "Apache-2.0",
|
|
60
|
+
"bugs": {
|
|
61
|
+
"url": "https://github.com/erdtman/canonicalize/issues"
|
|
62
|
+
},
|
|
63
|
+
"homepage": "https://github.com/erdtman/canonicalize#readme"
|
|
64
|
+
}
|
|
@@ -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,211 @@
|
|
|
1
|
+
import htmlDecodeTree from "./generated/decode-data-html.js";
|
|
2
|
+
import xmlDecodeTree from "./generated/decode-data-xml.js";
|
|
3
|
+
import decodeCodePoint from "./decode_codepoint.js";
|
|
4
|
+
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint };
|
|
5
|
+
export { replaceCodePoint, fromCodePoint } from "./decode_codepoint.js";
|
|
6
|
+
export declare enum BinTrieFlags {
|
|
7
|
+
VALUE_LENGTH = 49152,
|
|
8
|
+
BRANCH_LENGTH = 16256,
|
|
9
|
+
JUMP_TABLE = 127
|
|
10
|
+
}
|
|
11
|
+
export declare enum DecodingMode {
|
|
12
|
+
/** Entities in text nodes that can end with any character. */
|
|
13
|
+
Legacy = 0,
|
|
14
|
+
/** Only allow entities terminated with a semicolon. */
|
|
15
|
+
Strict = 1,
|
|
16
|
+
/** Entities in attributes have limitations on ending characters. */
|
|
17
|
+
Attribute = 2
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Producers for character reference errors as defined in the HTML spec.
|
|
21
|
+
*/
|
|
22
|
+
export interface EntityErrorProducer {
|
|
23
|
+
missingSemicolonAfterCharacterReference(): void;
|
|
24
|
+
absenceOfDigitsInNumericCharacterReference(consumedCharacters: number): void;
|
|
25
|
+
validateNumericCharacterReference(code: number): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Token decoder with support of writing partial entities.
|
|
29
|
+
*/
|
|
30
|
+
export declare class EntityDecoder {
|
|
31
|
+
/** The tree used to decode entities. */
|
|
32
|
+
private readonly decodeTree;
|
|
33
|
+
/**
|
|
34
|
+
* The function that is called when a codepoint is decoded.
|
|
35
|
+
*
|
|
36
|
+
* For multi-byte named entities, this will be called multiple times,
|
|
37
|
+
* with the second codepoint, and the same `consumed` value.
|
|
38
|
+
*
|
|
39
|
+
* @param codepoint The decoded codepoint.
|
|
40
|
+
* @param consumed The number of bytes consumed by the decoder.
|
|
41
|
+
*/
|
|
42
|
+
private readonly emitCodePoint;
|
|
43
|
+
/** An object that is used to produce errors. */
|
|
44
|
+
private readonly errors?;
|
|
45
|
+
constructor(
|
|
46
|
+
/** The tree used to decode entities. */
|
|
47
|
+
decodeTree: Uint16Array,
|
|
48
|
+
/**
|
|
49
|
+
* The function that is called when a codepoint is decoded.
|
|
50
|
+
*
|
|
51
|
+
* For multi-byte named entities, this will be called multiple times,
|
|
52
|
+
* with the second codepoint, and the same `consumed` value.
|
|
53
|
+
*
|
|
54
|
+
* @param codepoint The decoded codepoint.
|
|
55
|
+
* @param consumed The number of bytes consumed by the decoder.
|
|
56
|
+
*/
|
|
57
|
+
emitCodePoint: (cp: number, consumed: number) => void,
|
|
58
|
+
/** An object that is used to produce errors. */
|
|
59
|
+
errors?: EntityErrorProducer | undefined);
|
|
60
|
+
/** The current state of the decoder. */
|
|
61
|
+
private state;
|
|
62
|
+
/** Characters that were consumed while parsing an entity. */
|
|
63
|
+
private consumed;
|
|
64
|
+
/**
|
|
65
|
+
* The result of the entity.
|
|
66
|
+
*
|
|
67
|
+
* Either the result index of a numeric entity, or the codepoint of a
|
|
68
|
+
* numeric entity.
|
|
69
|
+
*/
|
|
70
|
+
private result;
|
|
71
|
+
/** The current index in the decode tree. */
|
|
72
|
+
private treeIndex;
|
|
73
|
+
/** The number of characters that were consumed in excess. */
|
|
74
|
+
private excess;
|
|
75
|
+
/** The mode in which the decoder is operating. */
|
|
76
|
+
private decodeMode;
|
|
77
|
+
/** Resets the instance to make it reusable. */
|
|
78
|
+
startEntity(decodeMode: DecodingMode): void;
|
|
79
|
+
/**
|
|
80
|
+
* Write an entity to the decoder. This can be called multiple times with partial entities.
|
|
81
|
+
* If the entity is incomplete, the decoder will return -1.
|
|
82
|
+
*
|
|
83
|
+
* Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
|
|
84
|
+
* entity is incomplete, and resume when the next string is written.
|
|
85
|
+
*
|
|
86
|
+
* @param string The string containing the entity (or a continuation of the entity).
|
|
87
|
+
* @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
|
|
88
|
+
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
89
|
+
*/
|
|
90
|
+
write(str: string, offset: number): number;
|
|
91
|
+
/**
|
|
92
|
+
* Switches between the numeric decimal and hexadecimal states.
|
|
93
|
+
*
|
|
94
|
+
* Equivalent to the `Numeric character reference state` in the HTML spec.
|
|
95
|
+
*
|
|
96
|
+
* @param str The string containing the entity (or a continuation of the entity).
|
|
97
|
+
* @param offset The current offset.
|
|
98
|
+
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
99
|
+
*/
|
|
100
|
+
private stateNumericStart;
|
|
101
|
+
private addToNumericResult;
|
|
102
|
+
/**
|
|
103
|
+
* Parses a hexadecimal numeric entity.
|
|
104
|
+
*
|
|
105
|
+
* Equivalent to the `Hexademical character reference state` in the HTML spec.
|
|
106
|
+
*
|
|
107
|
+
* @param str The string containing the entity (or a continuation of the entity).
|
|
108
|
+
* @param offset The current offset.
|
|
109
|
+
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
110
|
+
*/
|
|
111
|
+
private stateNumericHex;
|
|
112
|
+
/**
|
|
113
|
+
* Parses a decimal numeric entity.
|
|
114
|
+
*
|
|
115
|
+
* Equivalent to the `Decimal character reference state` in the HTML spec.
|
|
116
|
+
*
|
|
117
|
+
* @param str The string containing the entity (or a continuation of the entity).
|
|
118
|
+
* @param offset The current offset.
|
|
119
|
+
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
120
|
+
*/
|
|
121
|
+
private stateNumericDecimal;
|
|
122
|
+
/**
|
|
123
|
+
* Validate and emit a numeric entity.
|
|
124
|
+
*
|
|
125
|
+
* Implements the logic from the `Hexademical character reference start
|
|
126
|
+
* state` and `Numeric character reference end state` in the HTML spec.
|
|
127
|
+
*
|
|
128
|
+
* @param lastCp The last code point of the entity. Used to see if the
|
|
129
|
+
* entity was terminated with a semicolon.
|
|
130
|
+
* @param expectedLength The minimum number of characters that should be
|
|
131
|
+
* consumed. Used to validate that at least one digit
|
|
132
|
+
* was consumed.
|
|
133
|
+
* @returns The number of characters that were consumed.
|
|
134
|
+
*/
|
|
135
|
+
private emitNumericEntity;
|
|
136
|
+
/**
|
|
137
|
+
* Parses a named entity.
|
|
138
|
+
*
|
|
139
|
+
* Equivalent to the `Named character reference state` in the HTML spec.
|
|
140
|
+
*
|
|
141
|
+
* @param str The string containing the entity (or a continuation of the entity).
|
|
142
|
+
* @param offset The current offset.
|
|
143
|
+
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
144
|
+
*/
|
|
145
|
+
private stateNamedEntity;
|
|
146
|
+
/**
|
|
147
|
+
* Emit a named entity that was not terminated with a semicolon.
|
|
148
|
+
*
|
|
149
|
+
* @returns The number of characters consumed.
|
|
150
|
+
*/
|
|
151
|
+
private emitNotTerminatedNamedEntity;
|
|
152
|
+
/**
|
|
153
|
+
* Emit a named entity.
|
|
154
|
+
*
|
|
155
|
+
* @param result The index of the entity in the decode tree.
|
|
156
|
+
* @param valueLength The number of bytes in the entity.
|
|
157
|
+
* @param consumed The number of characters consumed.
|
|
158
|
+
*
|
|
159
|
+
* @returns The number of characters consumed.
|
|
160
|
+
*/
|
|
161
|
+
private emitNamedEntityData;
|
|
162
|
+
/**
|
|
163
|
+
* Signal to the parser that the end of the input was reached.
|
|
164
|
+
*
|
|
165
|
+
* Remaining data will be emitted and relevant errors will be produced.
|
|
166
|
+
*
|
|
167
|
+
* @returns The number of characters consumed.
|
|
168
|
+
*/
|
|
169
|
+
end(): number;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Determines the branch of the current node that is taken given the current
|
|
173
|
+
* character. This function is used to traverse the trie.
|
|
174
|
+
*
|
|
175
|
+
* @param decodeTree The trie.
|
|
176
|
+
* @param current The current node.
|
|
177
|
+
* @param nodeIdx The index right after the current node and its value.
|
|
178
|
+
* @param char The current character.
|
|
179
|
+
* @returns The index of the next node, or -1 if no branch is taken.
|
|
180
|
+
*/
|
|
181
|
+
export declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIdx: number, char: number): number;
|
|
182
|
+
/**
|
|
183
|
+
* Decodes an HTML string.
|
|
184
|
+
*
|
|
185
|
+
* @param str The string to decode.
|
|
186
|
+
* @param mode The decoding mode.
|
|
187
|
+
* @returns The decoded string.
|
|
188
|
+
*/
|
|
189
|
+
export declare function decodeHTML(str: string, mode?: DecodingMode): string;
|
|
190
|
+
/**
|
|
191
|
+
* Decodes an HTML string in an attribute.
|
|
192
|
+
*
|
|
193
|
+
* @param str The string to decode.
|
|
194
|
+
* @returns The decoded string.
|
|
195
|
+
*/
|
|
196
|
+
export declare function decodeHTMLAttribute(str: string): string;
|
|
197
|
+
/**
|
|
198
|
+
* Decodes an HTML string, requiring all entities to be terminated by a semicolon.
|
|
199
|
+
*
|
|
200
|
+
* @param str The string to decode.
|
|
201
|
+
* @returns The decoded string.
|
|
202
|
+
*/
|
|
203
|
+
export declare function decodeHTMLStrict(str: string): string;
|
|
204
|
+
/**
|
|
205
|
+
* Decodes an XML string, requiring all entities to be terminated by a semicolon.
|
|
206
|
+
*
|
|
207
|
+
* @param str The string to decode.
|
|
208
|
+
* @returns The decoded string.
|
|
209
|
+
*/
|
|
210
|
+
export declare function decodeXML(str: string): string;
|
|
211
|
+
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/61afd4701eaa736978b13c7351cd3de9a96b04bc/src/","sources":["decode.ts"],"names":[],"mappings":"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"}
|