@cjser/is-relative-url 4.1.0-cjser.2
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/dist-cjser/index.cjs +42 -0
- package/index.d.ts +46 -0
- package/index.js +12 -0
- package/license +9 -0
- package/package.json +73 -0
- package/readme.md +59 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// packages/@cjser/is-relative-url.tmp-26-1778152882259/index.js
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
default: () => isRelativeUrl
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var import_is_absolute_url_v4_0_1 = __toESM(require("@cjser/is-absolute-url__v4_0_1"), 1);
|
|
36
|
+
function isRelativeUrl(url, options = {}) {
|
|
37
|
+
const { allowProtocolRelative = true } = options;
|
|
38
|
+
if (!allowProtocolRelative && typeof url === "string" && url.startsWith("//")) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return !(0, import_is_absolute_url_v4_0_1.default)(url);
|
|
42
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/**
|
|
3
|
+
Allow protocol-relative URLs (e.g., `//example.com`) to be considered relative.
|
|
4
|
+
|
|
5
|
+
When set to `false`, protocol-relative URLs are treated as absolute, which can be useful for security purposes when you want to ensure a URL won't redirect to an external domain.
|
|
6
|
+
|
|
7
|
+
__Note:__ Protocol-relative URLs are [technically relative](https://datatracker.ietf.org/doc/html/rfc3986#section-4.2) according to [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986), as they require the current page's protocol to resolve into absolute URLs. However, they can still navigate to external domains, which may be a security concern in certain contexts (e.g., preventing open redirects).
|
|
8
|
+
|
|
9
|
+
@default true
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import isRelativeUrl from '@cjser/is-relative-url';
|
|
14
|
+
|
|
15
|
+
// Default behavior (allowProtocolRelative: true)
|
|
16
|
+
isRelativeUrl('//example.com');
|
|
17
|
+
//=> true
|
|
18
|
+
|
|
19
|
+
// Strict mode (allowProtocolRelative: false)
|
|
20
|
+
isRelativeUrl('//example.com', {allowProtocolRelative: false});
|
|
21
|
+
//=> false
|
|
22
|
+
```
|
|
23
|
+
*/
|
|
24
|
+
readonly allowProtocolRelative?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
Check if a URL is relative.
|
|
29
|
+
|
|
30
|
+
@param url - The URL to check.
|
|
31
|
+
|
|
32
|
+
@example
|
|
33
|
+
```
|
|
34
|
+
import isRelativeUrl from '@cjser/is-relative-url';
|
|
35
|
+
|
|
36
|
+
isRelativeUrl('foo/bar');
|
|
37
|
+
//=> true
|
|
38
|
+
|
|
39
|
+
isRelativeUrl('https://sindresorhus.com/foo/bar');
|
|
40
|
+
//=> false
|
|
41
|
+
|
|
42
|
+
isRelativeUrl('//sindresorhus.com');
|
|
43
|
+
//=> true
|
|
44
|
+
```
|
|
45
|
+
*/
|
|
46
|
+
export default function isRelativeUrl(url: string, options?: Options): boolean;
|
package/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import isAbsoluteUrl from '@cjser/is-absolute-url__v4_0_1';
|
|
2
|
+
|
|
3
|
+
export default function isRelativeUrl(url, options = {}) {
|
|
4
|
+
const {allowProtocolRelative = true} = options;
|
|
5
|
+
|
|
6
|
+
// Check if it's a protocol-relative URL (starts with //)
|
|
7
|
+
if (!allowProtocolRelative && typeof url === 'string' && url.startsWith('//')) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return !isAbsoluteUrl(url);
|
|
12
|
+
}
|
package/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
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,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cjser/is-relative-url",
|
|
3
|
+
"version": "4.1.0-cjser.2",
|
|
4
|
+
"description": "Check if a URL is relative",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://code.moenext.com/3rdeye/cjser.git"
|
|
9
|
+
},
|
|
10
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Sindre Sorhus",
|
|
13
|
+
"email": "sindresorhus@gmail.com",
|
|
14
|
+
"url": "https://sindresorhus.com"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
"require": "./dist-cjser/index.cjs",
|
|
19
|
+
"default": "./index.js"
|
|
20
|
+
},
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=14.16"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"//test": "xo && ava && tsd",
|
|
28
|
+
"test": "ava && tsd"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"index.js",
|
|
32
|
+
"index.d.ts",
|
|
33
|
+
"dist-cjser"
|
|
34
|
+
],
|
|
35
|
+
"keywords": [
|
|
36
|
+
"url",
|
|
37
|
+
"relative",
|
|
38
|
+
"absolute",
|
|
39
|
+
"uri",
|
|
40
|
+
"is",
|
|
41
|
+
"check"
|
|
42
|
+
],
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@cjser/is-absolute-url__v4_0_1": "4.0.1-cjser.2"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"ava": "^4.3.0",
|
|
48
|
+
"tsd": "^0.20.0",
|
|
49
|
+
"xo": "^0.49.0"
|
|
50
|
+
},
|
|
51
|
+
"main": "./dist-cjser/index.cjs",
|
|
52
|
+
"cjser": {
|
|
53
|
+
"sourceVersion": "4.1.0",
|
|
54
|
+
"cjserVersion": 2,
|
|
55
|
+
"original": {
|
|
56
|
+
"name": "is-relative-url",
|
|
57
|
+
"version": "4.1.0",
|
|
58
|
+
"exports": "./index.js",
|
|
59
|
+
"repository": "sindresorhus/is-relative-url",
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"is-absolute-url": "^4.0.1"
|
|
62
|
+
},
|
|
63
|
+
"files": [
|
|
64
|
+
"index.js",
|
|
65
|
+
"index.d.ts"
|
|
66
|
+
],
|
|
67
|
+
"scripts": {
|
|
68
|
+
"//test": "xo && ava && tsd",
|
|
69
|
+
"test": "ava && tsd"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# is-relative-url
|
|
2
|
+
|
|
3
|
+
> Check if a URL is relative
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install is-relative-url
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import isRelativeUrl from 'is-relative-url';
|
|
15
|
+
|
|
16
|
+
isRelativeUrl('foo/bar');
|
|
17
|
+
//=> true
|
|
18
|
+
|
|
19
|
+
isRelativeUrl('https://sindresorhus.com/foo/bar');
|
|
20
|
+
//=> false
|
|
21
|
+
|
|
22
|
+
isRelativeUrl('//sindresorhus.com');
|
|
23
|
+
//=> true
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## API
|
|
27
|
+
|
|
28
|
+
### isRelativeUrl(url, options?)
|
|
29
|
+
|
|
30
|
+
#### url
|
|
31
|
+
|
|
32
|
+
Type: `string`
|
|
33
|
+
|
|
34
|
+
The URL to check.
|
|
35
|
+
|
|
36
|
+
#### options
|
|
37
|
+
|
|
38
|
+
Type: `object`
|
|
39
|
+
|
|
40
|
+
##### allowProtocolRelative
|
|
41
|
+
|
|
42
|
+
Type: `boolean`\
|
|
43
|
+
Default: `true`
|
|
44
|
+
|
|
45
|
+
Allow [protocol-relative URLs](https://en.wikipedia.org/wiki/URL#Protocol-relative_URLs) (e.g., `//example.com`) to be considered relative.
|
|
46
|
+
|
|
47
|
+
Setting this to `false` will treat protocol-relative URLs as absolute, which can be useful for security purposes when you want to ensure a URL won't redirect to an external domain.
|
|
48
|
+
|
|
49
|
+
> [!NOTE]
|
|
50
|
+
> Protocol-relative URLs are [technically relative](https://datatracker.ietf.org/doc/html/rfc3986#section-4.2) according to [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986), as they require the current page's protocol to resolve into absolute URLs. However, they can still navigate to external domains, which may be a security concern in certain contexts (e.g., preventing open redirects).
|
|
51
|
+
|
|
52
|
+
## Related
|
|
53
|
+
|
|
54
|
+
See [is-absolute-url](https://github.com/sindresorhus/is-absolute-url) for the inverse.
|
|
55
|
+
|
|
56
|
+
## cjser
|
|
57
|
+
|
|
58
|
+
This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
|
|
59
|
+
Original repository: https://github.com/sindresorhus/is-relative-url
|