@gjsify/querystring 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 +7 -0
- package/lib/cjs/error.js +44 -0
- package/lib/cjs/index.js +1054 -0
- package/lib/esm/error.js +25 -0
- package/lib/esm/index.js +1035 -0
- package/package.json +44 -0
- package/src/error.ts +32 -0
- package/src/index.spec.ts +67 -0
- package/src/index.ts +574 -0
- package/src/test.mts +4 -0
- package/test.gjs.js +33178 -0
- package/test.gjs.mjs +35804 -0
- package/test.gjs.mjs.meta.json +1 -0
- package/test.node.js +231 -0
- package/test.node.mjs +353 -0
- package/tsconfig.json +19 -0
- package/tsconfig.types.json +8 -0
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gjsify/querystring",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Node.js querystring 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 tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo || exit 0",
|
|
22
|
+
"print:name": "echo '@gjsify/querystring'",
|
|
23
|
+
"build": "yarn print:name && yarn build:gjsify",
|
|
24
|
+
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
25
|
+
"build:test": "yarn build:test:gjs && yarn build:test:node",
|
|
26
|
+
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
27
|
+
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
28
|
+
"test": "yarn print:name && yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
|
|
29
|
+
"test:gjs": "gjs -m test.gjs.mjs",
|
|
30
|
+
"test:node": "node test.node.mjs"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"gjs",
|
|
34
|
+
"node",
|
|
35
|
+
"fs"
|
|
36
|
+
],
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@gjsify/cli": "^0.0.2",
|
|
39
|
+
"@gjsify/esbuild-plugin-gjsify": "^0.0.2",
|
|
40
|
+
"@gjsify/unit": "^0.0.2",
|
|
41
|
+
"@types/inherits": "^0.0.30",
|
|
42
|
+
"@types/node": "^20.3.1"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/error.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// TODO create module for node errors?
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* All error instances in Node have additional methods and properties
|
|
5
|
+
* This export class is meant to be extended by these instances abstracting native JS error instances
|
|
6
|
+
*/
|
|
7
|
+
export class NodeErrorAbstraction extends Error {
|
|
8
|
+
code: string;
|
|
9
|
+
|
|
10
|
+
constructor(name: string, code: string, message: string) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.name = name;
|
|
14
|
+
//This number changes depending on the name of this class
|
|
15
|
+
//20 characters as of now
|
|
16
|
+
this.stack = this.stack && `${name} [${this.code}]${this.stack.slice(20)}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override toString() {
|
|
20
|
+
return `${this.name} [${this.code}]: ${this.message}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class NodeURIError extends NodeErrorAbstraction implements URIError {
|
|
25
|
+
constructor(code: string, message: string) {
|
|
26
|
+
super(URIError.prototype.name, code, message);
|
|
27
|
+
Object.setPrototypeOf(this, URIError.prototype);
|
|
28
|
+
this.toString = function () {
|
|
29
|
+
return `${this.name} [${this.code}]: ${this.message}`;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, it, expect } from '@gjsify/unit';
|
|
2
|
+
import * as qs from 'querystring';
|
|
3
|
+
|
|
4
|
+
// TODO: Port more tests from https://github.com/SpainTrain/querystring-es3/tree/master/test
|
|
5
|
+
|
|
6
|
+
export default async () => {
|
|
7
|
+
await describe('querystring', async () => {
|
|
8
|
+
await it('performs basic parsing', async () => {
|
|
9
|
+
expect(qs.parse('id=918854443121279438895193').id).toBe('918854443121279438895193');
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
await it('test stringifying invalid surrogate pair throws URIError', async () => {
|
|
14
|
+
expect(() => {
|
|
15
|
+
qs.stringify({ foo: '\udc00' });
|
|
16
|
+
}).toThrow();
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
qs.stringify({ foo: '\udc00' });
|
|
20
|
+
} catch (error) {
|
|
21
|
+
expect(error instanceof URIError).toBeTruthy();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
await it('test stringifying coerce numbers to string', async () => {
|
|
27
|
+
expect('foo=0').toBe(qs.stringify({ foo: 0 }));
|
|
28
|
+
expect('foo=0').toBe(qs.stringify({ foo: -0 }));
|
|
29
|
+
expect('foo=3').toBe(qs.stringify({ foo: 3 }));
|
|
30
|
+
expect('foo=-72.42').toBe(qs.stringify({ foo: -72.42 }));
|
|
31
|
+
expect('foo=').toBe(qs.stringify({ foo: NaN }));
|
|
32
|
+
expect('foo=').toBe(qs.stringify({ foo: Infinity }));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
await it('test stringifying nested', async () => {
|
|
36
|
+
const f = qs.stringify({
|
|
37
|
+
a: 'b',
|
|
38
|
+
q: qs.stringify({
|
|
39
|
+
x: 'y',
|
|
40
|
+
y: 'z'
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
expect(f).toBe('a=b&q=x%3Dy%26y%3Dz');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await it('test stringifying nested in colon', async () => {
|
|
47
|
+
const f = qs.stringify({
|
|
48
|
+
a: 'b',
|
|
49
|
+
q: qs.stringify({
|
|
50
|
+
x: 'y',
|
|
51
|
+
y: 'z'
|
|
52
|
+
}, ';', ':')
|
|
53
|
+
}, ';', ':');
|
|
54
|
+
expect(f).toBe('a:b;q:x%3Ay%3By%3Az');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await it('test stringifying empty string', async () => {
|
|
58
|
+
expect(qs.stringify()).toBe('');
|
|
59
|
+
expect(qs.stringify(0 as any)).toBe('');
|
|
60
|
+
expect(qs.stringify([] as any)).toBe('');
|
|
61
|
+
expect(qs.stringify(null as any)).toBe('');
|
|
62
|
+
expect(qs.stringify(true as any)).toBe('');
|
|
63
|
+
|
|
64
|
+
// TODO
|
|
65
|
+
// expect((qs as any).parse()).toBeEmptyObject();
|
|
66
|
+
});
|
|
67
|
+
}
|