Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
55894a30f2 | |||
249c50a3c5 | |||
6470b05152 | |||
cfe189b02f | |||
f3e9f49af2 | |||
4b6dc9f5c3 | |||
b84c8053ff | |||
544f309dc9 | |||
f6e6697244 | |||
ce6622f858 | |||
105b1ca637 | |||
546c7806bc | |||
d446575e60 | |||
31922529ae | |||
fced2e845e | |||
c7169e37a6 |
@ -12,20 +12,12 @@ stages:
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
@ -36,6 +28,7 @@ auditProductionDependencies:
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
@ -96,10 +89,9 @@ codequality:
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
@ -119,11 +111,10 @@ trigger:
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smarturl",
|
||||
"shortDescription": "a url parsing lib",
|
||||
"description": "a url parsing lib",
|
||||
"npmPackagename": "@pushrocks/smarturl",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
|
20675
package-lock.json
generated
20675
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -1,25 +1,24 @@
|
||||
{
|
||||
"name": "@pushrocks/smarturl",
|
||||
"version": "1.0.5",
|
||||
"version": "3.0.1",
|
||||
"private": false,
|
||||
"description": "a url parsing lib",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)"
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tstest": "^1.0.52",
|
||||
"@pushrocks/tapbundle": "^3.2.14",
|
||||
"@types/node": "^14.14.37",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tstest": "^1.0.72",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.6.1"
|
||||
},
|
||||
"dependencies": {},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
@ -34,5 +33,8 @@
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
],
|
||||
"dependencies": {
|
||||
"parse-url": "^6.0.5"
|
||||
}
|
||||
}
|
||||
|
18
test/test.ts
18
test/test.ts
@ -1,11 +1,25 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smarturl from '../ts/index';
|
||||
import * as smarturl from '../ts/index.js';
|
||||
|
||||
let testSmarturl: smarturl.Smarturl;
|
||||
|
||||
tap.test('first test', async () => {
|
||||
testSmarturl = new smarturl.Smarturl();
|
||||
expect(testSmarturl).to.be.instanceOf(smarturl.Smarturl);
|
||||
expect(testSmarturl).toBeInstanceOf(smarturl.Smarturl);
|
||||
});
|
||||
|
||||
tap.test('should parse an URL', async () => {
|
||||
const testUrl = 'https://lossless.com:3000/?some=cool&more=yes';
|
||||
// const urlMod = await import('url');
|
||||
// const altParsed = urlMod.parse(testUrl);
|
||||
// console.log(altParsed);
|
||||
const parsedUrl = smarturl.Smarturl.createFromUrl(testUrl, {
|
||||
searchParams: {
|
||||
more: 'overwritten',
|
||||
},
|
||||
});
|
||||
console.log(parsedUrl);
|
||||
console.log(parsedUrl.toString());
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smarturl',
|
||||
version: '3.0.1',
|
||||
description: 'a url parsing lib'
|
||||
}
|
@ -1 +1 @@
|
||||
export * from './smarturl.classes.smarturl';
|
||||
export * from './smarturl.classes.smarturl.js';
|
||||
|
@ -1,7 +1,121 @@
|
||||
import * as plugins from './smarturl.plugins';
|
||||
import * as plugins from './smarturl.plugins.js';
|
||||
|
||||
export class Smarturl {
|
||||
public parseUrl(urlArg: string) {
|
||||
return new plugins.url.URL(urlArg);
|
||||
export interface IUrlObject {
|
||||
href: string;
|
||||
origin: string;
|
||||
protocol: string;
|
||||
username: string;
|
||||
password: string;
|
||||
host: string;
|
||||
hostname: string;
|
||||
port: string;
|
||||
path: string;
|
||||
pathname: string;
|
||||
search: string;
|
||||
searchParams: ISearchParams;
|
||||
hash: string;
|
||||
}
|
||||
|
||||
export interface ISearchParams {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export class Smarturl implements IUrlObject {
|
||||
public static createFromUrl(
|
||||
urlArg: string,
|
||||
optionsArg?: {
|
||||
searchParams?: ISearchParams;
|
||||
}
|
||||
): Smarturl {
|
||||
const parsedUrlInstance = plugins.url(urlArg);
|
||||
const searchParams: ISearchParams = {};
|
||||
|
||||
// enrichment
|
||||
const searchParamPairs = parsedUrlInstance.search
|
||||
.replace('?', '')
|
||||
.split('&')
|
||||
.map((searchParamPair) => {
|
||||
return {
|
||||
key: searchParamPair.split('=')[0],
|
||||
value: searchParamPair.split('=')[1],
|
||||
};
|
||||
});
|
||||
|
||||
for (const searchParamPair of searchParamPairs) {
|
||||
searchParams[searchParamPair.key] = searchParamPair.value;
|
||||
}
|
||||
if (optionsArg?.searchParams) {
|
||||
for (const key of Object.keys(optionsArg.searchParams)) {
|
||||
searchParams[key] = optionsArg.searchParams[key];
|
||||
}
|
||||
}
|
||||
|
||||
let path = parsedUrlInstance.pathname;
|
||||
if (Object.keys(searchParams).length > 0) {
|
||||
path += '?';
|
||||
let first = true;
|
||||
for (const key of Object.keys(searchParams)) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
path += '&';
|
||||
}
|
||||
path += `${key}=${searchParams[key]}`;
|
||||
}
|
||||
}
|
||||
|
||||
const parsedUrl: IUrlObject = {
|
||||
href: parsedUrlInstance.href,
|
||||
origin: `${parsedUrlInstance.protocol}://${parsedUrlInstance.resource}`,
|
||||
protocol: parsedUrlInstance.protocol,
|
||||
username: parsedUrlInstance.user.split(':')[0],
|
||||
password: parsedUrlInstance.user.split(':')[1] || '',
|
||||
host: `${parsedUrlInstance.resource}:${parsedUrlInstance.port}`,
|
||||
hostname: parsedUrlInstance.resource,
|
||||
port: parsedUrlInstance.port,
|
||||
path,
|
||||
pathname: parsedUrlInstance.pathname,
|
||||
search: parsedUrlInstance.search,
|
||||
searchParams,
|
||||
hash: parsedUrlInstance.hash,
|
||||
};
|
||||
|
||||
if (!parsedUrl.port && parsedUrl.protocol === 'https:') {
|
||||
// console.log(`inferring port 443 for "https:"`);
|
||||
parsedUrl.port = '443';
|
||||
}
|
||||
if (!parsedUrl.port && parsedUrl.protocol === 'http:') {
|
||||
// console.log(`inferring port 80 for "http:"`);
|
||||
parsedUrl.port = '80';
|
||||
}
|
||||
const returnSmarturl = new Smarturl();
|
||||
Object.assign(returnSmarturl, parsedUrl);
|
||||
return returnSmarturl;
|
||||
}
|
||||
public static createFromParsedUrl(parsedUrlArg: IUrlObject) {
|
||||
const returnSmarturl = new Smarturl();
|
||||
Object.assign(returnSmarturl, parsedUrlArg);
|
||||
return returnSmarturl;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
href: string;
|
||||
origin: string;
|
||||
protocol: string;
|
||||
username: string;
|
||||
password: string;
|
||||
host: string;
|
||||
hostname: string;
|
||||
port: string;
|
||||
path: string;
|
||||
pathname: string;
|
||||
search: string;
|
||||
searchParams: ISearchParams;
|
||||
hash: string;
|
||||
|
||||
constructor() {}
|
||||
|
||||
toString() {
|
||||
return `${this.protocol}//${this.hostname}:${this.port}${this.path}`;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// node native
|
||||
import * as url from 'url';
|
||||
import { default as url } from 'parse-url';
|
||||
|
||||
export { url };
|
||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true,
|
||||
}
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user