Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
a8495baf4c | |||
3a29679e66 | |||
08d5627e7e | |||
25a8b750d8 | |||
5eaa7ea0c3 | |||
d255c598b4 | |||
5bb01a2db9 | |||
44b1e67302 | |||
b1162191c6 | |||
60f1368071 | |||
1c503ec655 | |||
2d52a14ec1 | |||
55894a30f2 | |||
249c50a3c5 | |||
6470b05152 | |||
cfe189b02f |
@ -3,10 +3,10 @@
|
|||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smarturl",
|
"gitrepo": "smarturl",
|
||||||
"description": "a url parsing lib",
|
"description": "a url parsing lib",
|
||||||
"npmPackagename": "@pushrocks/smarturl",
|
"npmPackagename": "@push.rocks/smarturl",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks"
|
||||||
}
|
}
|
||||||
|
14567
package-lock.json
generated
14567
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarturl",
|
"name": "@push.rocks/smarturl",
|
||||||
"version": "2.0.2",
|
"version": "3.0.7",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a url parsing lib",
|
"description": "a url parsing lib",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -14,10 +14,11 @@
|
|||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.63",
|
"@gitzone/tsbuild": "^2.1.65",
|
||||||
"@gitzone/tstest": "^1.0.72",
|
"@gitzone/tsrun": "^1.2.39",
|
||||||
|
"@gitzone/tstest": "^1.0.74",
|
||||||
"@pushrocks/tapbundle": "^5.0.4",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^18.6.1"
|
"@types/node": "^18.15.11"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
4457
pnpm-lock.yaml
generated
Normal file
4457
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -22,4 +22,22 @@ tap.test('should parse an URL', async () => {
|
|||||||
console.log(parsedUrl.toString());
|
console.log(parsedUrl.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should parse an URL', async () => {
|
||||||
|
const testUrl = 'https://lossless.com:3000/';
|
||||||
|
const parsedUrl = smarturl.Smarturl.createFromUrl(testUrl, {
|
||||||
|
searchParams: {
|
||||||
|
more: 'overwritten',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(parsedUrl);
|
||||||
|
console.log(parsedUrl.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should correctly parse ans assemble urls', async () => {
|
||||||
|
const testUrl = 'https://lossless.com/';
|
||||||
|
const parsedUrl = smarturl.Smarturl.createFromUrl(testUrl, {});
|
||||||
|
console.log(parsedUrl.toString());
|
||||||
|
expect(parsedUrl.toString()).toEqual('https://lossless.com:443/');
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
17
test/test.searchaprams.both.ts
Normal file
17
test/test.searchaprams.both.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as smarturl from '../ts/index.js';
|
||||||
|
|
||||||
|
let testSmarturl: smarturl.Smarturl;
|
||||||
|
|
||||||
|
tap.test('first test', async () => {
|
||||||
|
testSmarturl = new smarturl.Smarturl();
|
||||||
|
expect(testSmarturl).toBeInstanceOf(smarturl.Smarturl);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should create searchParams only', async () => {
|
||||||
|
const smarturlInstance = new smarturl.Smarturl();
|
||||||
|
smarturlInstance.searchParams['hello'] = 'hi_there';
|
||||||
|
console.log(smarturlInstance.toString());
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.start();
|
@ -2,7 +2,7 @@
|
|||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smarturl',
|
name: '@push.rocks/smarturl',
|
||||||
version: '2.0.2',
|
version: '3.0.7',
|
||||||
description: 'a url parsing lib'
|
description: 'a url parsing lib'
|
||||||
}
|
}
|
||||||
|
@ -27,13 +27,29 @@ export class Smarturl implements IUrlObject {
|
|||||||
searchParams?: ISearchParams;
|
searchParams?: ISearchParams;
|
||||||
}
|
}
|
||||||
): Smarturl {
|
): Smarturl {
|
||||||
const parsedUrlInstance = new plugins.url.URL(urlArg);
|
const parsedUrlInstance = new URL(urlArg);
|
||||||
const searchParams: ISearchParams = {};
|
const searchParams: ISearchParams = {};
|
||||||
|
|
||||||
// enrichment
|
// enrichment
|
||||||
const searchParamKeys = parsedUrlInstance.searchParams.keys();
|
const searchParamPairs: {
|
||||||
for (const key of searchParamKeys) {
|
key: string;
|
||||||
searchParams[key] = parsedUrlInstance.searchParams.get(key);
|
value: string;
|
||||||
|
}[] = []
|
||||||
|
|
||||||
|
if (parsedUrlInstance.search) {
|
||||||
|
parsedUrlInstance.search
|
||||||
|
.replace('?', '')
|
||||||
|
.split('&')
|
||||||
|
.map((searchParamPair) => {
|
||||||
|
searchParamPairs.push({
|
||||||
|
key: searchParamPair.split('=')[0],
|
||||||
|
value: searchParamPair.split('=')[1],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const searchParamPair of searchParamPairs) {
|
||||||
|
searchParams[searchParamPair.key] = searchParamPair.value;
|
||||||
}
|
}
|
||||||
if (optionsArg?.searchParams) {
|
if (optionsArg?.searchParams) {
|
||||||
for (const key of Object.keys(optionsArg.searchParams)) {
|
for (const key of Object.keys(optionsArg.searchParams)) {
|
||||||
@ -41,7 +57,7 @@ export class Smarturl implements IUrlObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = parsedUrlInstance.pathname;
|
let path = parsedUrlInstance.pathname || '';
|
||||||
if (Object.keys(searchParams).length > 0) {
|
if (Object.keys(searchParams).length > 0) {
|
||||||
path += '?';
|
path += '?';
|
||||||
let first = true;
|
let first = true;
|
||||||
@ -56,6 +72,7 @@ export class Smarturl implements IUrlObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const parsedUrl: IUrlObject = {
|
const parsedUrl: IUrlObject = {
|
||||||
|
...parsedUrlInstance,
|
||||||
href: parsedUrlInstance.href,
|
href: parsedUrlInstance.href,
|
||||||
origin: parsedUrlInstance.origin,
|
origin: parsedUrlInstance.origin,
|
||||||
protocol: parsedUrlInstance.protocol,
|
protocol: parsedUrlInstance.protocol,
|
||||||
@ -104,9 +121,20 @@ export class Smarturl implements IUrlObject {
|
|||||||
searchParams: ISearchParams;
|
searchParams: ISearchParams;
|
||||||
hash: string;
|
hash: string;
|
||||||
|
|
||||||
constructor() {}
|
constructor() {
|
||||||
|
this.searchParams = {};
|
||||||
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return `${this.protocol}//${this.hostname}:${this.port}${this.path}`;
|
let userpart = ``;
|
||||||
|
if (this.username && !this.password) {
|
||||||
|
userpart = `${this.username}@`;
|
||||||
|
}
|
||||||
|
if (this.username && this.password) {
|
||||||
|
userpart = `${this.username}:${this.password}@`;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return `${this.protocol}//${userpart}${this.hostname}:${this.port}${this.path}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1 @@
|
|||||||
// node native
|
export {};
|
||||||
import * as url from 'url';
|
|
||||||
|
|
||||||
export { url };
|
|
@ -5,6 +5,6 @@
|
|||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "ES2022",
|
"module": "ES2022",
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "nodenext",
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user