Skip to content

Commit

Permalink
feat: expose constants from root
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Sep 25, 2022
1 parent 6973310 commit e2aefa0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
73 changes: 41 additions & 32 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,44 @@
/* jshint node: true */

"use strict";
module.exports =
{
FAILURE: 999,
State: {
AUTHORITY: 100,
SCHEME_START: 101,
SCHEME: 102,
HOST: 103,
NO_SCHEME: 104,
FRAGMENT: 105,
RELATIVE: 106,
RELATIVE_SLASH: 107,
FILE: 108,
FILE_HOST: 109,
FILE_SLASH: 110,
PATH_OR_AUTHORITY: 111,
SPECIAL_AUTHORITY_IGNORE_SLASHES: 112,
SPECIAL_AUTHORITY_SLASHES: 113,
SPECIAL_RELATIVE_OR_AUTHORITY: 114,
QUERY: 115,
PATH: 116,
PATH_START: 117,
OPAQUE_PATH: 118,
PORT: 119,
},
Regex: {
ASCII_TAB_OR_NEWLINE: /[\u0009\u000A\u000D]/gu,
FORBIDDEN_DOMAIN_CODE_POINTS: /\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\||[\u0000-\u001F]|%|\u007F/u,
FORBIDDEN_HOST_CODE_POINTS: /\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u,
LEADING_TRAILING_C0_CONTROL_OR_SPACE: /^[\u0000-\u001F\u0020]+|[\u0000-\u001F\u0020]+$/gu,
},
};

/**
* @readonly
* @enum {number}
*/
const State = {
AUTHORITY: 100,
SCHEME_START: 101,
SCHEME: 102,
HOST: 103,
NO_SCHEME: 104,
FRAGMENT: 105,
RELATIVE: 106,
RELATIVE_SLASH: 107,
FILE: 108,
FILE_HOST: 109,
FILE_SLASH: 110,
PATH_OR_AUTHORITY: 111,
SPECIAL_AUTHORITY_IGNORE_SLASHES: 112,
SPECIAL_AUTHORITY_SLASHES: 113,
SPECIAL_RELATIVE_OR_AUTHORITY: 114,
QUERY: 115,
PATH: 116,
PATH_START: 117,
OPAQUE_PATH: 118,
PORT: 119,
};

module.exports = {
FAILURE: 999,
State,
Regex: {
ASCII_TAB_OR_NEWLINE: /[\u0009\u000A\u000D]/gu,
FORBIDDEN_DOMAIN_CODE_POINTS:
/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\||[\u0000-\u001F]|%|\u007F/u,
FORBIDDEN_HOST_CODE_POINTS:
/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u,
LEADING_TRAILING_C0_CONTROL_OR_SPACE:
/^[\u0000-\u001F\u0020]+|[\u0000-\u001F\u0020]+$/gu,
},
};
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const special_schemes = {
* @param {string} input URL
* @param {URLStateMachineBase=} [base=null] base
* @param {"utf-8"|null} [encodingOverride="utf-8"] encodingOverride
* @param {State=} stateOverride State to override
* @param {number} stateOverride State to override
*/
function URLStateMachine(input, base = null, encodingOverride, stateOverride) {
this.buffer = "";
Expand Down Expand Up @@ -1140,3 +1140,4 @@ URLStateMachine.prototype.portState = function portState(code) {
};

module.exports = URLStateMachine;
module.exports.Constants = { FAILURE, State, Regex };

0 comments on commit e2aefa0

Please sign in to comment.