@common.js/decode-uri-component 0.4.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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @common.js/decode-uri-component
2
+
3
+ The [decode-uri-component](https://www.npmjs.com/package/decode-uri-component) package exported as CommonJS modules.
4
+
5
+ Exported from [decode-uri-component@0.4.1](https://www.npmjs.com/package/decode-uri-component/v/0.4.1) using https://github.com/etienne-martin/common.js.
package/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ Decodes a Uniform Resource Identifier (URI) component previously created by `encodeURIComponent()`
3
+ or by a similar routine.
4
+
5
+ @param encodedURI - An encoded component of a URI.
6
+
7
+ @returns The decoded URI component.
8
+
9
+ @example
10
+ ```
11
+ decodeUriComponent('st%C3%A5le')
12
+ //=> 'ståle'
13
+ ```
14
+ */
15
+ export default function decodeUriComponent(encodedURI: string): string;
package/index.js ADDED
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return decodeUriComponent;
9
+ }
10
+ });
11
+ var _typeof = function(obj) {
12
+ "@swc/helpers - typeof";
13
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
14
+ };
15
+ var token = "%[a-f0-9]{2}";
16
+ var singleMatcher = new RegExp("(" + token + ")|([^%]+?)", "gi");
17
+ var multiMatcher = new RegExp("(" + token + ")+", "gi");
18
+ function decodeComponents(components, split) {
19
+ try {
20
+ // Try to decode the entire string first
21
+ return [
22
+ decodeURIComponent(components.join(""))
23
+ ];
24
+ } catch (e) {
25
+ // Do nothing
26
+ }
27
+ if (components.length === 1) {
28
+ return components;
29
+ }
30
+ split = split || 1;
31
+ // Split the array in 2 parts
32
+ var left = components.slice(0, split);
33
+ var right = components.slice(split);
34
+ return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
35
+ }
36
+ function decode(input) {
37
+ try {
38
+ return decodeURIComponent(input);
39
+ } catch (e) {
40
+ var tokens = input.match(singleMatcher) || [];
41
+ for(var i = 1; i < tokens.length; i++){
42
+ input = decodeComponents(tokens, i).join("");
43
+ tokens = input.match(singleMatcher) || [];
44
+ }
45
+ return input;
46
+ }
47
+ }
48
+ function customDecodeURIComponent(input) {
49
+ // Keep track of all the replacements and prefill the map with the `BOM`
50
+ var replaceMap = {
51
+ "%FE%FF": "��",
52
+ "%FF%FE": "��"
53
+ };
54
+ var match = multiMatcher.exec(input);
55
+ while(match){
56
+ try {
57
+ // Decode as big chunks as possible
58
+ replaceMap[match[0]] = decodeURIComponent(match[0]);
59
+ } catch (e) {
60
+ var result = decode(match[0]);
61
+ if (result !== match[0]) {
62
+ replaceMap[match[0]] = result;
63
+ }
64
+ }
65
+ match = multiMatcher.exec(input);
66
+ }
67
+ // Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
68
+ replaceMap["%C2"] = "�";
69
+ var entries = Object.keys(replaceMap);
70
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
71
+ try {
72
+ for(var _iterator = entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
73
+ var key = _step.value;
74
+ // Replace all decoded components
75
+ input = input.replace(new RegExp(key, "g"), replaceMap[key]);
76
+ }
77
+ } catch (err) {
78
+ _didIteratorError = true;
79
+ _iteratorError = err;
80
+ } finally{
81
+ try {
82
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
83
+ _iterator.return();
84
+ }
85
+ } finally{
86
+ if (_didIteratorError) {
87
+ throw _iteratorError;
88
+ }
89
+ }
90
+ }
91
+ return input;
92
+ }
93
+ function decodeUriComponent(encodedURI) {
94
+ if (typeof encodedURI !== "string") {
95
+ throw new TypeError("Expected `encodedURI` to be of type `string`, got `" + (typeof encodedURI === "undefined" ? "undefined" : _typeof(encodedURI)) + "`");
96
+ }
97
+ try {
98
+ // Try the built in decoder first
99
+ return decodeURIComponent(encodedURI);
100
+ } catch (e) {
101
+ // Fallback to a more advanced decoder
102
+ return customDecodeURIComponent(encodedURI);
103
+ }
104
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017, Sam Verschueren <sam.verschueren@gmail.com> (github.com/SamVerschueren)
4
+
5
+ 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:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ 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.
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@common.js/decode-uri-component",
3
+ "version": "0.4.1",
4
+ "description": "decode-uri-component package exported as CommonJS modules",
5
+ "license": "MIT",
6
+ "repository": "etienne-martin/common.js",
7
+ "type": "commonjs",
8
+ "engines": {
9
+ "node": ">=14.16"
10
+ },
11
+ "scripts": {
12
+ "test": "xo && nyc ava && tsd",
13
+ "coveralls": "nyc report --reporter=text-lcov | coveralls"
14
+ },
15
+ "files": [
16
+ "index.js",
17
+ "index.d.ts"
18
+ ],
19
+ "devDependencies": {
20
+ "ava": "^5.1.0",
21
+ "coveralls": "^3.1.1",
22
+ "nyc": "^15.1.0",
23
+ "tsd": "^0.25.0",
24
+ "xo": "^0.53.1"
25
+ },
26
+ "tsd": {
27
+ "compilerOptions": {
28
+ "module": "node16"
29
+ }
30
+ },
31
+ "homepage": "https://github.com/etienne-martin/common.js#readme",
32
+ "dependencies": {},
33
+ "types": "./index.d.ts",
34
+ "main": "./index.js"
35
+ }