@d1g1tal/media-type 4.0.0
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/LICENSE.txt +7 -0
- package/README.md +103 -0
- package/dist/media-type.js +304 -0
- package/dist/media-type.min.js +4 -0
- package/dist/media-type.min.js.map +7 -0
- package/index.d.ts +5 -0
- package/index.js +5 -0
- package/package.json +88 -0
- package/src/media-type-parameters.d.ts +91 -0
- package/src/media-type-parameters.js +141 -0
- package/src/media-type.d.ts +91 -0
- package/src/media-type.js +188 -0
- package/src/parser.d.ts +13 -0
- package/src/parser.js +109 -0
- package/src/serializer.d.ts +11 -0
- package/src/serializer.js +35 -0
- package/src/utils.d.ts +52 -0
- package/src/utils.js +93 -0
package/src/utils.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** @module utils */
|
|
2
|
+
/**
|
|
3
|
+
* A function to remove any leading and trailing HTTP whitespace.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} string The string to process.
|
|
6
|
+
* @returns {string} The processed string.
|
|
7
|
+
*/
|
|
8
|
+
export function removeLeadingAndTrailingHTTPWhitespace(string: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* A function to remove any trailing HTTP whitespace.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} string The string to process.
|
|
13
|
+
* @returns {string} The processed string.
|
|
14
|
+
*/
|
|
15
|
+
export function removeTrailingHTTPWhitespace(string: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Determines if the provided character is whitespace.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} char The character to evaluate.
|
|
20
|
+
* @returns {boolean} true if the character is whitespace, false otherwise.
|
|
21
|
+
*/
|
|
22
|
+
export function isHTTPWhitespaceChar(char: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Determines if the provided string contains only HTTP token code points.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} string The string to evaluate.
|
|
27
|
+
* @returns {boolean} true if the string contains only HTTP token code points.
|
|
28
|
+
*/
|
|
29
|
+
export function solelyContainsHTTPTokenCodePoints(string: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Determines if the provided string contains only quoted HTTP token code points.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} string The string to evaluate.
|
|
34
|
+
* @returns {boolean} true if the string contains only quoted HTTP token code points.
|
|
35
|
+
*/
|
|
36
|
+
export function solelyContainsHTTPQuotedStringTokenCodePoints(string: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* A function to lower case ASCII characters.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} string The string to process.
|
|
41
|
+
* @returns {string} The processed string with all ASCII characters lower cased.
|
|
42
|
+
*/
|
|
43
|
+
export function asciiLowercase(string: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Collects all the HTTP quoted strings.
|
|
46
|
+
* This variant only implements it with the extract-value flag set.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} input The string to process.
|
|
49
|
+
* @param {number} position The starting position.
|
|
50
|
+
* @returns {Array<string | number>} An array that includes the resulting string and updated position.
|
|
51
|
+
*/
|
|
52
|
+
export function collectAnHTTPQuotedString(input: string, position: number): Array<string | number>;
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** @module utils */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A function to remove any leading and trailing HTTP whitespace.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} string The string to process.
|
|
7
|
+
* @returns {string} The processed string.
|
|
8
|
+
*/
|
|
9
|
+
const removeLeadingAndTrailingHTTPWhitespace = (string) => string.replace(/^[ \t\n\r]+/u, '').replace(/[ \t\n\r]+$/u, '');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A function to remove any trailing HTTP whitespace.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} string The string to process.
|
|
15
|
+
* @returns {string} The processed string.
|
|
16
|
+
*/
|
|
17
|
+
const removeTrailingHTTPWhitespace = (string) => string.replace(/[ \t\n\r]+$/u, '');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Determines if the provided character is whitespace.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} char The character to evaluate.
|
|
23
|
+
* @returns {boolean} true if the character is whitespace, false otherwise.
|
|
24
|
+
*/
|
|
25
|
+
const isHTTPWhitespaceChar = (char) => char === ' ' || char === '\t' || char === '\n' || char === '\r';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Determines if the provided string contains only HTTP token code points.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} string The string to evaluate.
|
|
31
|
+
* @returns {boolean} true if the string contains only HTTP token code points.
|
|
32
|
+
*/
|
|
33
|
+
const solelyContainsHTTPTokenCodePoints = (string) => /^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u.test(string);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Determines if the provided string contains only quoted HTTP token code points.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} string The string to evaluate.
|
|
39
|
+
* @returns {boolean} true if the string contains only quoted HTTP token code points.
|
|
40
|
+
*/
|
|
41
|
+
const solelyContainsHTTPQuotedStringTokenCodePoints = (string) => /^[\t\u0020-\u007E\u0080-\u00FF]*$/u.test(string);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A function to lower case ASCII characters.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} string The string to process.
|
|
47
|
+
* @returns {string} The processed string with all ASCII characters lower cased.
|
|
48
|
+
*/
|
|
49
|
+
const asciiLowercase = (string) => string.replace(/[A-Z]/ug, l => l.toLowerCase());
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Collects all the HTTP quoted strings.
|
|
53
|
+
* This variant only implements it with the extract-value flag set.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} input The string to process.
|
|
56
|
+
* @param {number} position The starting position.
|
|
57
|
+
* @returns {Array<string | number>} An array that includes the resulting string and updated position.
|
|
58
|
+
*/
|
|
59
|
+
const collectAnHTTPQuotedString = (input, position) => {
|
|
60
|
+
let value = '';
|
|
61
|
+
|
|
62
|
+
position++;
|
|
63
|
+
|
|
64
|
+
while (true) {
|
|
65
|
+
while (position < input.length && input[position] !== '"' && input[position] !== '\\') {
|
|
66
|
+
value += input[position];
|
|
67
|
+
++position;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (position >= input.length) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const quoteOrBackslash = input[position];
|
|
75
|
+
++position;
|
|
76
|
+
|
|
77
|
+
if (quoteOrBackslash === '\\') {
|
|
78
|
+
if (position >= input.length) {
|
|
79
|
+
value += '\\';
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
value += input[position];
|
|
84
|
+
++position;
|
|
85
|
+
} else {
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return [value, position];
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export { removeLeadingAndTrailingHTTPWhitespace, removeTrailingHTTPWhitespace, isHTTPWhitespaceChar, solelyContainsHTTPTokenCodePoints, solelyContainsHTTPQuotedStringTokenCodePoints, asciiLowercase, collectAnHTTPQuotedString };
|