Comparing version 1.0.12 to 1.0.13
@@ -6,2 +6,13 @@ # Change Log | ||
## [1.0.12](https://github.com/bluelovers/lazy-url/compare/lazy-url@1.0.11...lazy-url@1.0.12) (2021-07-19) | ||
### 🔖 Miscellaneous | ||
* update readme ([37dd3d6](https://github.com/bluelovers/lazy-url/commit/37dd3d6666d08cd73caea346cb29168500ebe697)) | ||
## 1.0.11 (2021-07-19) | ||
@@ -8,0 +19,0 @@ |
@@ -7,2 +7,6 @@ /** | ||
export declare const SYM_HIDDEN: unique symbol; | ||
export declare const enum ENUM_FAKE { | ||
protocol = "fake+http:", | ||
hostname = "url-fake-hostname" | ||
} | ||
export declare class LazyURL extends URL implements URL { | ||
@@ -30,2 +34,5 @@ /** | ||
set hostname(value: string); | ||
get href(): string; | ||
set href(value: string); | ||
get origin(): string; | ||
get port(): string; | ||
@@ -108,2 +115,4 @@ set port(value: string | number); | ||
} | ||
export declare function isFakeProtocol(protocol: string): protocol is ENUM_FAKE.protocol; | ||
export declare function isFakeHostname(hostname: string): hostname is ENUM_FAKE.protocol; | ||
export default LazyURL; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._core = exports.findSymbolContext = exports.LazyURL = exports.SYM_HIDDEN = exports.SYM_URL = void 0; | ||
exports.isFakeHostname = exports.isFakeProtocol = exports._core = exports.findSymbolContext = exports.LazyURL = exports.ENUM_FAKE = exports.SYM_HIDDEN = exports.SYM_URL = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -15,2 +15,3 @@ const url_parse_1 = (0, tslib_1.__importDefault)(require("url-parse")); | ||
const clean_stack_1 = (0, tslib_1.__importDefault)(require("clean-stack")); | ||
const replace_url_protocol_1 = require("replace-url-protocol"); | ||
exports.SYM_URL = Symbol('url'); | ||
@@ -22,3 +23,3 @@ exports.SYM_HIDDEN = Symbol('hidden'); | ||
ENUM_FAKE["hostname"] = "url-fake-hostname"; | ||
})(ENUM_FAKE || (ENUM_FAKE = {})); | ||
})(ENUM_FAKE = exports.ENUM_FAKE || (exports.ENUM_FAKE = {})); | ||
const SymbolContext = findSymbolContext(); | ||
@@ -146,20 +147,30 @@ class LazyURL extends URL { | ||
set hostname(value) { | ||
delete this[exports.SYM_HIDDEN].hostname; | ||
if (!isFakeHostname(value)) { | ||
delete this[exports.SYM_HIDDEN].hostname; | ||
} | ||
super.hostname = value; | ||
} | ||
/* | ||
get href() | ||
{ | ||
return this[SYM_URL].href | ||
get href() { | ||
return super.href; | ||
} | ||
set href(value) | ||
{ | ||
this[SYM_URL].href = value | ||
set href(value) { | ||
super.href = value; | ||
if (isFakeProtocol(super.protocol)) { | ||
this[exports.SYM_HIDDEN].protocol = "fake+http:" /* protocol */; | ||
} | ||
if (isFakeHostname(super.hostname)) { | ||
this[exports.SYM_HIDDEN].hostname = "url-fake-hostname" /* hostname */; | ||
} | ||
} | ||
get origin() | ||
{ | ||
return this[SYM_URL].origin | ||
get origin() { | ||
let origin = super.origin; | ||
if ((typeof origin === 'undefined' || origin === null || origin === 'null' || origin === 'undefined') && super.protocol.length) { | ||
/** | ||
* @see https://github.com/nodejs/node/issues/39732#issuecomment-896624653 | ||
*/ | ||
origin = super.protocol + '//' + super.hostname; | ||
} | ||
return origin; | ||
} | ||
/* | ||
@@ -210,4 +221,16 @@ get password() | ||
set protocol(value) { | ||
delete this[exports.SYM_HIDDEN].protocol; | ||
super.protocol = value; | ||
if (typeof value !== 'string' || value.length < 2 || !value.endsWith(':')) { | ||
throw new TypeError(`Invalid protocol input: ${value}`); | ||
} | ||
if (!isFakeProtocol(value)) { | ||
delete this[exports.SYM_HIDDEN].protocol; | ||
} | ||
const old = super.protocol; | ||
if (old !== value) { | ||
super.protocol = value; | ||
/** | ||
* avoid bug of https://github.com/nodejs/node/issues/39732 | ||
*/ | ||
(0, replace_url_protocol_1._fixReplaceURLProtocol)(this, old, value); | ||
} | ||
} | ||
@@ -503,3 +526,11 @@ /* | ||
} | ||
function isFakeProtocol(protocol) { | ||
return protocol === "fake+http:" /* protocol */; | ||
} | ||
exports.isFakeProtocol = isFakeProtocol; | ||
function isFakeHostname(hostname) { | ||
return hostname === "url-fake-hostname" /* hostname */; | ||
} | ||
exports.isFakeHostname = isFakeHostname; | ||
exports.default = LazyURL; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "lazy-url", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "a more easy use URL", | ||
@@ -59,15 +59,16 @@ "keywords": [ | ||
"indent-string": ">=4.0.0 <5", | ||
"replace-url-protocol": "^1.0.2", | ||
"symbol.inspect": "^1.0.1", | ||
"ts-type-predicates": "^1.0.3", | ||
"ts-type-predicates": "^1.0.5", | ||
"tslib": "^2.3.0", | ||
"url-parse": "^1.5.1" | ||
"url-parse": "^1.5.3" | ||
}, | ||
"devDependencies": { | ||
"@bluelovers/tsconfig": "^1.0.25", | ||
"@types/jest": "^26.0.24", | ||
"@types/node": "^16.3.3", | ||
"@types/jest": "^27.0.0", | ||
"@types/node": "^16.4.13", | ||
"@types/url-parse": "^1.4.3", | ||
"jest": "^27.0.6", | ||
"ts-jest": "^27.0.3" | ||
"ts-jest": "^27.0.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49850
629
8
1
+ Addedreplace-url-protocol@^1.0.2
+ Addedreplace-url-protocol@1.0.10(transitive)
Updatedts-type-predicates@^1.0.5
Updatedurl-parse@^1.5.3