@php-wasm/scopes 0.1.2 → 0.1.3
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/{src/index.ts → index.d.ts} +4 -40
- package/index.js +32 -0
- package/package.json +26 -21
- package/.eslintrc.json +0 -18
- package/README.md +0 -7
- package/project.json +0 -48
- package/src/index.spec.ts +0 -58
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -19
- package/vite.config.ts +0 -47
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
*
|
|
12
12
|
* For more information, see the README section on scopes.
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
14
|
/**
|
|
16
15
|
* Checks if the given URL contains scope information.
|
|
17
16
|
*
|
|
@@ -27,10 +26,7 @@
|
|
|
27
26
|
* @param url The URL to check.
|
|
28
27
|
* @returns `true` if the URL contains scope information, `false` otherwise.
|
|
29
28
|
*/
|
|
30
|
-
export function isURLScoped(url: URL): boolean
|
|
31
|
-
return url.pathname.startsWith(`/scope:`);
|
|
32
|
-
}
|
|
33
|
-
|
|
29
|
+
export declare function isURLScoped(url: URL): boolean;
|
|
34
30
|
/**
|
|
35
31
|
* Returns the scope stored in the given URL.
|
|
36
32
|
*
|
|
@@ -46,13 +42,7 @@ export function isURLScoped(url: URL): boolean {
|
|
|
46
42
|
* @param url The URL.
|
|
47
43
|
* @returns The scope if the URL contains a scope, `null` otherwise.
|
|
48
44
|
*/
|
|
49
|
-
export function getURLScope(url: URL): string | null
|
|
50
|
-
if (isURLScoped(url)) {
|
|
51
|
-
return url.pathname.split('/')[1].split(':')[1];
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
45
|
+
export declare function getURLScope(url: URL): string | null;
|
|
56
46
|
/**
|
|
57
47
|
* Returns a new URL with the requested scope information.
|
|
58
48
|
*
|
|
@@ -72,25 +62,7 @@ export function getURLScope(url: URL): string | null {
|
|
|
72
62
|
* @param scope The scope value.
|
|
73
63
|
* @returns A new URL with the scope information in it.
|
|
74
64
|
*/
|
|
75
|
-
export function setURLScope(url: URL | string, scope: string | null): URL
|
|
76
|
-
let newUrl = new URL(url);
|
|
77
|
-
|
|
78
|
-
if (isURLScoped(newUrl)) {
|
|
79
|
-
if (scope) {
|
|
80
|
-
const parts = newUrl.pathname.split('/');
|
|
81
|
-
parts[1] = `scope:${scope}`;
|
|
82
|
-
newUrl.pathname = parts.join('/');
|
|
83
|
-
} else {
|
|
84
|
-
newUrl = removeURLScope(newUrl);
|
|
85
|
-
}
|
|
86
|
-
} else if (scope) {
|
|
87
|
-
const suffix = newUrl.pathname === '/' ? '' : newUrl.pathname;
|
|
88
|
-
newUrl.pathname = `/scope:${scope}${suffix}`;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return newUrl;
|
|
92
|
-
}
|
|
93
|
-
|
|
65
|
+
export declare function setURLScope(url: URL | string, scope: string | null): URL;
|
|
94
66
|
/**
|
|
95
67
|
* Returns a new URL without any scope information.
|
|
96
68
|
*
|
|
@@ -106,12 +78,4 @@ export function setURLScope(url: URL | string, scope: string | null): URL {
|
|
|
106
78
|
* @param url The URL to remove scope information from.
|
|
107
79
|
* @returns A new URL without the scope information.
|
|
108
80
|
*/
|
|
109
|
-
export function removeURLScope(url: URL): URL
|
|
110
|
-
if (!isURLScoped(url)) {
|
|
111
|
-
return url;
|
|
112
|
-
}
|
|
113
|
-
const newUrl = new URL(url);
|
|
114
|
-
const parts = newUrl.pathname.split('/');
|
|
115
|
-
newUrl.pathname = '/' + parts.slice(2).join('/');
|
|
116
|
-
return newUrl;
|
|
117
|
-
}
|
|
81
|
+
export declare function removeURLScope(url: URL): URL;
|
package/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function p(e) {
|
|
2
|
+
return e.pathname.startsWith("/scope:");
|
|
3
|
+
}
|
|
4
|
+
function s(e) {
|
|
5
|
+
return p(e) ? e.pathname.split("/")[1].split(":")[1] : null;
|
|
6
|
+
}
|
|
7
|
+
function o(e, n) {
|
|
8
|
+
let t = new URL(e);
|
|
9
|
+
if (p(t))
|
|
10
|
+
if (n) {
|
|
11
|
+
const a = t.pathname.split("/");
|
|
12
|
+
a[1] = `scope:${n}`, t.pathname = a.join("/");
|
|
13
|
+
} else
|
|
14
|
+
t = i(t);
|
|
15
|
+
else if (n) {
|
|
16
|
+
const a = t.pathname === "/" ? "" : t.pathname;
|
|
17
|
+
t.pathname = `/scope:${n}${a}`;
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
}
|
|
21
|
+
function i(e) {
|
|
22
|
+
if (!p(e))
|
|
23
|
+
return e;
|
|
24
|
+
const n = new URL(e), t = n.pathname.split("/");
|
|
25
|
+
return n.pathname = "/" + t.slice(2).join("/"), n;
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
s as getURLScope,
|
|
29
|
+
p as isURLScoped,
|
|
30
|
+
i as removeURLScope,
|
|
31
|
+
o as setURLScope
|
|
32
|
+
};
|
package/package.json
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
"name": "@php-wasm/scopes",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "PHP.wasm – scoped URLs utils",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/WordPress/wordpress-playground"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://developer.wordpress.org/playground",
|
|
10
|
+
"author": "The WordPress contributors",
|
|
11
|
+
"contributors": [
|
|
12
|
+
{
|
|
13
|
+
"name": "Adam Zielinski",
|
|
14
|
+
"email": "adam@adamziel.com",
|
|
15
|
+
"url": "https://github.com/adamziel"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public",
|
|
20
|
+
"directory": "../../../dist/packages/php-wasm/scopes"
|
|
21
|
+
},
|
|
22
|
+
"license": "GPL-2.0-or-later",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "index.js",
|
|
25
|
+
"types": "index.d.ts",
|
|
26
|
+
"gitHead": "ac5bf6b09cb425d650bc57eff03eac6417cccd49",
|
|
27
|
+
"dependencies": {}
|
|
23
28
|
}
|
package/.eslintrc.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["../../../.eslintrc.json"],
|
|
3
|
-
"ignorePatterns": ["!**/*"],
|
|
4
|
-
"overrides": [
|
|
5
|
-
{
|
|
6
|
-
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
7
|
-
"rules": {}
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"files": ["*.ts", "*.tsx"],
|
|
11
|
-
"rules": {}
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"files": ["*.js", "*.jsx"],
|
|
15
|
-
"rules": {}
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
}
|
package/README.md
DELETED
package/project.json
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "php-wasm-scopes",
|
|
3
|
-
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "packages/php-wasm/scopes/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"targets": {
|
|
7
|
-
"build": {
|
|
8
|
-
"executor": "@wp-playground/nx-extensions:package-json",
|
|
9
|
-
"options": {
|
|
10
|
-
"tsConfig": "packages/php-wasm/scopes/tsconfig.lib.json",
|
|
11
|
-
"outputPath": "dist/packages/php-wasm/scopes",
|
|
12
|
-
"buildTarget": "php-wasm-scopes:build:bundle:production"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"build:bundle": {
|
|
16
|
-
"executor": "@nrwl/vite:build",
|
|
17
|
-
"outputs": ["{options.outputPath}"],
|
|
18
|
-
"options": {
|
|
19
|
-
"outputPath": "dist/packages/php-wasm/scopes"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"lint": {
|
|
23
|
-
"executor": "@nrwl/linter:eslint",
|
|
24
|
-
"outputs": ["{options.outputFile}"],
|
|
25
|
-
"options": {
|
|
26
|
-
"lintFilePatterns": ["packages/php-wasm/scopes/**/*.ts"]
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"test": {
|
|
30
|
-
"executor": "@nrwl/vite:test",
|
|
31
|
-
"outputs": ["coverage/packages/php-wasm/scopes"],
|
|
32
|
-
"options": {
|
|
33
|
-
"passWithNoTests": true,
|
|
34
|
-
"reportsDirectory": "../../../coverage/packages/php-wasm/scopes"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"typecheck": {
|
|
38
|
-
"executor": "@nrwl/workspace:run-commands",
|
|
39
|
-
"options": {
|
|
40
|
-
"commands": [
|
|
41
|
-
"yarn tsc -p packages/php-wasm/scopes/tsconfig.lib.json --noEmit",
|
|
42
|
-
"yarn tsc -p packages/php-wasm/scopes/tsconfig.spec.json --noEmit"
|
|
43
|
-
]
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"tags": []
|
|
48
|
-
}
|
package/src/index.spec.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { getURLScope, isURLScoped, removeURLScope, setURLScope } from './index';
|
|
2
|
-
|
|
3
|
-
describe('getURLScope', () => {
|
|
4
|
-
it('should return the scope from a scoped URL', () => {
|
|
5
|
-
const url = new URL('http://localhost/scope:12345/index.php');
|
|
6
|
-
expect(getURLScope(url)).toBe('12345');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('should return null from a non-scoped URL', () => {
|
|
10
|
-
const url = new URL('http://localhost/index.php');
|
|
11
|
-
expect(getURLScope(url)).toBeNull();
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe('isURLScoped', () => {
|
|
16
|
-
it('should return true for a scoped URL', () => {
|
|
17
|
-
const url = new URL('http://localhost/scope:12345/index.php');
|
|
18
|
-
expect(isURLScoped(url)).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should return false for a non-scoped URL', () => {
|
|
22
|
-
const url = new URL('http://localhost/index.php');
|
|
23
|
-
expect(isURLScoped(url)).toBe(false);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('removeURLScope', () => {
|
|
28
|
-
it('should remove the scope from a scoped URL', () => {
|
|
29
|
-
const url = new URL('http://localhost/scope:12345/index.php');
|
|
30
|
-
expect(removeURLScope(url).href).toBe('http://localhost/index.php');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should return the same URL for a non-scoped URL', () => {
|
|
34
|
-
const url = new URL('http://localhost/index.php');
|
|
35
|
-
expect(removeURLScope(url)).toBe(url);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('setURLScope', () => {
|
|
40
|
-
it('should add the scope to a non-scoped URL', () => {
|
|
41
|
-
const url = new URL('http://localhost/index.php');
|
|
42
|
-
expect(setURLScope(url, '12345').href).toBe(
|
|
43
|
-
'http://localhost/scope:12345/index.php'
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should replace the scope in a scoped URL', () => {
|
|
48
|
-
const url = new URL('http://localhost/scope:12345/index.php');
|
|
49
|
-
expect(setURLScope(url, '67890').href).toBe(
|
|
50
|
-
'http://localhost/scope:67890/index.php'
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should remove the scope from a URL when the scope is null', () => {
|
|
55
|
-
const url = new URL('http://localhost/scope:12345/index.php');
|
|
56
|
-
expect(setURLScope(url, null).href).toBe('http://localhost/index.php');
|
|
57
|
-
});
|
|
58
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"forceConsistentCasingInFileNames": true,
|
|
5
|
-
"strict": true,
|
|
6
|
-
"noImplicitOverride": true,
|
|
7
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
8
|
-
"noImplicitReturns": true,
|
|
9
|
-
"noFallthroughCasesInSwitch": true,
|
|
10
|
-
"types": ["vitest"]
|
|
11
|
-
},
|
|
12
|
-
"files": [],
|
|
13
|
-
"include": [],
|
|
14
|
-
"references": [
|
|
15
|
-
{
|
|
16
|
-
"path": "./tsconfig.lib.json"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"path": "./tsconfig.spec.json"
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
package/tsconfig.lib.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"]
|
|
6
|
-
},
|
|
7
|
-
"include": [
|
|
8
|
-
"vite.config.ts",
|
|
9
|
-
"src/**/*.test.ts",
|
|
10
|
-
"src/**/*.spec.ts",
|
|
11
|
-
"src/**/*.test.tsx",
|
|
12
|
-
"src/**/*.spec.tsx",
|
|
13
|
-
"src/**/*.test.js",
|
|
14
|
-
"src/**/*.spec.js",
|
|
15
|
-
"src/**/*.test.jsx",
|
|
16
|
-
"src/**/*.spec.jsx",
|
|
17
|
-
"src/**/*.d.ts"
|
|
18
|
-
]
|
|
19
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/// <reference types="vitest" />
|
|
2
|
-
import { defineConfig } from 'vite';
|
|
3
|
-
|
|
4
|
-
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
|
5
|
-
import dts from 'vite-plugin-dts';
|
|
6
|
-
import { join } from 'path';
|
|
7
|
-
|
|
8
|
-
export default defineConfig({
|
|
9
|
-
cacheDir: '../../../node_modules/.vite/php-wasm-scope',
|
|
10
|
-
|
|
11
|
-
plugins: [
|
|
12
|
-
dts({
|
|
13
|
-
entryRoot: 'src',
|
|
14
|
-
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
|
15
|
-
skipDiagnostics: true,
|
|
16
|
-
}),
|
|
17
|
-
|
|
18
|
-
viteTsConfigPaths({
|
|
19
|
-
root: '../../../',
|
|
20
|
-
}),
|
|
21
|
-
],
|
|
22
|
-
|
|
23
|
-
// Configuration for building your library.
|
|
24
|
-
// See: https://vitejs.dev/guide/build.html#library-mode
|
|
25
|
-
build: {
|
|
26
|
-
lib: {
|
|
27
|
-
// Could also be a dictionary or array of multiple entry points.
|
|
28
|
-
entry: 'src/index.ts',
|
|
29
|
-
name: 'php-wasm-scope',
|
|
30
|
-
fileName: 'index',
|
|
31
|
-
formats: ['es'],
|
|
32
|
-
},
|
|
33
|
-
rollupOptions: {
|
|
34
|
-
// External packages that should not be bundled into your library.
|
|
35
|
-
external: [],
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
test: {
|
|
40
|
-
globals: true,
|
|
41
|
-
cache: {
|
|
42
|
-
dir: '../../../node_modules/.vitest',
|
|
43
|
-
},
|
|
44
|
-
environment: 'jsdom',
|
|
45
|
-
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
46
|
-
},
|
|
47
|
-
});
|