@gjsify/url 0.0.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/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # @gjsify/url
2
+
3
+ Node.js url module for Gjs
4
+ ## Inspirations
5
+ - https://github.com/defunctzombie/node-url
6
+ - https://github.com/denoland/deno_std/blob/main/node/url.ts
@@ -0,0 +1,36 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var src_exports = {};
30
+ __export(src_exports, {
31
+ default: () => src_default
32
+ });
33
+ module.exports = __toCommonJS(src_exports);
34
+ __reExport(src_exports, require("@gjsify/deno_std/node/url"), module.exports);
35
+ var import_url = __toESM(require("@gjsify/deno_std/node/url"), 1);
36
+ var src_default = import_url.default;
@@ -0,0 +1,6 @@
1
+ export * from "@gjsify/deno_std/node/url";
2
+ import _default from "@gjsify/deno_std/node/url";
3
+ var src_default = _default;
4
+ export {
5
+ src_default as default
6
+ };
@@ -0,0 +1,3 @@
1
+ export type * from 'node:url';
2
+ import type url from 'node:url';
3
+ export default url;
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@gjsify/url",
3
+ "version": "0.0.2",
4
+ "description": "Node.js url module for Gjs",
5
+ "type": "module",
6
+ "main": "lib/cjs/index.js",
7
+ "module": "lib/esm/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./lib/types/index.d.ts",
12
+ "default": "./lib/esm/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./lib/types/index.d.ts",
16
+ "default": "./lib/cjs/index.js"
17
+ }
18
+ }
19
+ },
20
+ "scripts": {
21
+ "clear": "rm -rf lib/cjs lib/esm tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo || exit 0",
22
+ "print:name": "echo '@gjsify/url'",
23
+ "build": "yarn print:name && yarn build:gjsify && yarn build:types",
24
+ "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.ts' 'src/test.ts'",
25
+ "build:types": "echo 'The types are currently handwritten'",
26
+ "build:real_types": "tsc --project tsconfig.types.json || exit 0",
27
+ "build:test": "yarn build:test:gjs && yarn build:test:node",
28
+ "build:test:gjs": "gjsify build src/test.ts --app gjs --outfile test.gjs.mjs",
29
+ "build:test:node": "gjsify build src/test.ts --app node --outfile test.node.mjs",
30
+ "test": "yarn print:name && yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
31
+ "test:gjs": "gjs -m test.gjs.mjs",
32
+ "test:node": "node test.node.mjs"
33
+ },
34
+ "keywords": [
35
+ "gjs",
36
+ "node",
37
+ "fs"
38
+ ],
39
+ "devDependencies": {
40
+ "@gjsify/cli": "^0.0.2",
41
+ "@gjsify/unit": "^0.0.2",
42
+ "typescript": "^5.1.3"
43
+ },
44
+ "dependencies": {
45
+ "@gjsify/deno_std": "^0.0.2",
46
+ "@types/node": "^20.3.1"
47
+ }
48
+ }
@@ -0,0 +1,88 @@
1
+ // TODO port more tests from https://github.com/defunctzombie/node-url
2
+
3
+ import { describe, it, expect } from '@gjsify/unit';
4
+ import { fileURLToPath, URL } from "url"
5
+
6
+ export default async () => {
7
+ var fileURLToPathTestCases = [
8
+ // Lowercase ascii alpha
9
+ { path: '/foo', fileURL: 'file:///foo' },
10
+ // Uppercase ascii alpha
11
+ { path: '/FOO', fileURL: 'file:///FOO' },
12
+ // dir
13
+ { path: '/dir/foo', fileURL: 'file:///dir/foo' },
14
+ // trailing separator
15
+ { path: '/dir/', fileURL: 'file:///dir/' },
16
+ // dot
17
+ { path: '/foo.mjs', fileURL: 'file:///foo.mjs' },
18
+ // space
19
+ { path: '/foo bar', fileURL: 'file:///foo%20bar' },
20
+ // question mark
21
+ { path: '/foo?bar', fileURL: 'file:///foo%3Fbar' },
22
+ // number sign
23
+ { path: '/foo#bar', fileURL: 'file:///foo%23bar' },
24
+ // ampersand
25
+ { path: '/foo&bar', fileURL: 'file:///foo&bar' },
26
+ // equals
27
+ { path: '/foo=bar', fileURL: 'file:///foo=bar' },
28
+ // colon
29
+ { path: '/foo:bar', fileURL: 'file:///foo:bar' },
30
+ // semicolon
31
+ { path: '/foo;bar', fileURL: 'file:///foo;bar' },
32
+ // percent
33
+ { path: '/foo%bar', fileURL: 'file:///foo%25bar' },
34
+ // backslash
35
+ { path: '/foo\\bar', fileURL: 'file:///foo%5Cbar' },
36
+ // backspace
37
+ { path: '/foo\bbar', fileURL: 'file:///foo%08bar' },
38
+ // tab
39
+ { path: '/foo\tbar', fileURL: 'file:///foo%09bar' },
40
+ // newline
41
+ { path: '/foo\nbar', fileURL: 'file:///foo%0Abar' },
42
+ // carriage return
43
+ { path: '/foo\rbar', fileURL: 'file:///foo%0Dbar' },
44
+ // latin1
45
+ { path: '/fóóbàr', fileURL: 'file:///f%C3%B3%C3%B3b%C3%A0r' },
46
+ // Euro sign (BMP code point)
47
+ { path: '/€', fileURL: 'file:///%E2%82%AC' },
48
+ // Rocket emoji (non-BMP code point)
49
+ { path: '/🚀', fileURL: 'file:///%F0%9F%9A%80' }
50
+ ];
51
+
52
+ for (const fileURLToPathTestCase of fileURLToPathTestCases) {
53
+ await describe('url.fileURLToPath(' + fileURLToPathTestCase.fileURL + ')', async () => {
54
+
55
+ await it(`should return ${fileURLToPathTestCase.path} from string`, async () => {
56
+ var fromString = fileURLToPath(fileURLToPathTestCase.fileURL);
57
+ expect(fromString).toEqual(fileURLToPathTestCase.path)
58
+ });
59
+
60
+ await it(`should return ${fileURLToPathTestCase.path} from URL`, async () => {
61
+ var fromURL = fileURLToPath(new URL(fileURLToPathTestCase.fileURL));
62
+ expect(fromURL).toEqual(fileURLToPathTestCase.path)
63
+ });
64
+ });
65
+ }
66
+
67
+ for (const val in [
68
+ 'https://host/y',
69
+ 'file://host/a',
70
+ new URL('https://host/y'),
71
+ 'file:///a%2F/',
72
+ '',
73
+ null,
74
+ undefined,
75
+ 1,
76
+ {},
77
+ true
78
+ ]) {
79
+ await describe('url.fileURLToPath(' + val + ')', async () => {
80
+ await it(`should throw an Error`, async () => {
81
+ expect(() => {
82
+ fileURLToPath(val);
83
+ }).toThrow()
84
+ });
85
+
86
+ });
87
+ }
88
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from '@gjsify/deno_std/node/url';
2
+ import _default from '@gjsify/deno_std/node/url';
3
+ export default _default;
package/src/test.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { run } from '@gjsify/unit';
2
+ import indexTestSuite from './index.spec.js';
3
+
4
+ run({indexTestSuite});
package/test/file.txt ADDED
@@ -0,0 +1 @@
1
+ Hello World