12 Commits

Author SHA1 Message Date
1c503ec655 3.0.2 2022-07-28 15:10:34 +02:00
2d52a14ec1 fix(core): update 2022-07-28 15:10:34 +02:00
55894a30f2 3.0.1 2022-07-27 01:06:17 +02:00
249c50a3c5 fix(core): update 2022-07-27 01:06:16 +02:00
6470b05152 3.0.0 2022-07-27 00:40:46 +02:00
cfe189b02f BREAKING CHANGE(core): switch to esm 2022-07-27 00:40:46 +02:00
f3e9f49af2 2.0.2 2022-07-27 00:40:18 +02:00
4b6dc9f5c3 fix(core): update 2022-07-27 00:40:18 +02:00
b84c8053ff 2.0.1 2021-05-02 16:33:50 +00:00
544f309dc9 fix(core): update 2021-05-02 16:33:50 +00:00
f6e6697244 2.0.0 2021-05-02 16:32:25 +00:00
ce6622f858 BREAKING CHANGE(core): update 2021-05-02 16:32:24 +00:00
12 changed files with 11954 additions and 8978 deletions

View File

@ -12,20 +12,12 @@ stages:
- release - release
- metadata - metadata
before_script:
- npm install -g @shipzone/npmci
# ==================== # ====================
# security stage # security stage
# ==================== # ====================
mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
@ -36,6 +28,7 @@ auditProductionDependencies:
- npmci command npm audit --audit-level=high --only=prod --production - npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- docker - docker
allow_failure: true
auditDevDependencies: auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
@ -96,10 +89,9 @@ codequality:
only: only:
- tags - tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g typescript
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless - lossless
- docker - docker
@ -119,11 +111,10 @@ trigger:
pages: pages:
stage: metadata stage: metadata
script: script:
- npmci node install lts - npmci node install stable
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command npm run buildDocs
tags: tags:
- lossless - lossless
- docker - docker

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "current file", "command": "npm test",
"type": "node", "name": "Run npm test",
"request": "launch", "request": "launch",
"args": [ "type": "node-terminal"
"${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"
} }
] ]
} }

View File

@ -5,7 +5,7 @@
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",
"gitrepo": "smarturl", "gitrepo": "smarturl",
"shortDescription": "a url parsing lib", "description": "a url parsing lib",
"npmPackagename": "@pushrocks/smarturl", "npmPackagename": "@pushrocks/smarturl",
"license": "MIT", "license": "MIT",
"projectDomain": "push.rocks" "projectDomain": "push.rocks"

20659
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,24 @@
{ {
"name": "@pushrocks/smarturl", "name": "@pushrocks/smarturl",
"version": "1.0.8", "version": "3.0.2",
"private": false, "private": false,
"description": "a url parsing lib", "description": "a url parsing lib",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "(tstest test/ --web)",
"build": "(tsbuild --web)" "build": "(tsbuild --web)",
"buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.63",
"@gitzone/tstest": "^1.0.52", "@gitzone/tstest": "^1.0.72",
"@pushrocks/tapbundle": "^3.2.14", "@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^14.14.37", "@types/node": "^18.6.1"
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0"
}, },
"dependencies": {},
"files": [ "files": [
"ts/**/*", "ts/**/*",
"ts_web/**/*", "ts_web/**/*",
@ -34,5 +33,8 @@
], ],
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
] ],
"dependencies": {
"parse-url": "^6.0.5"
}
} }

View File

@ -1,16 +1,39 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as smarturl from '../ts/index'; import * as smarturl from '../ts/index.js';
let testSmarturl: smarturl.Smarturl; let testSmarturl: smarturl.Smarturl;
tap.test('first test', async () => { tap.test('first test', async () => {
testSmarturl = new smarturl.Smarturl(); testSmarturl = new smarturl.Smarturl();
expect(testSmarturl).to.be.instanceOf(smarturl.Smarturl); expect(testSmarturl).toBeInstanceOf(smarturl.Smarturl);
}); });
tap.test('should parse an URL', async () => { tap.test('should parse an URL', async () => {
const parsedUrl = testSmarturl.parseUrl('https://lossless.com'); 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);
console.log(parsedUrl.toString());
});
tap.test('should parse an URL', async () => {
const testUrl = 'https://lossless.com:3000/';
// 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(); tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smarturl',
version: '3.0.2',
description: 'a url parsing lib'
}

View File

@ -1 +1 @@
export * from './smarturl.classes.smarturl'; export * from './smarturl.classes.smarturl.js';

View File

@ -1,6 +1,6 @@
import * as plugins from './smarturl.plugins'; import * as plugins from './smarturl.plugins.js';
export interface IUrlObject{ export interface IUrlObject {
href: string; href: string;
origin: string; origin: string;
protocol: string; protocol: string;
@ -9,29 +9,84 @@ export interface IUrlObject{
host: string; host: string;
hostname: string; hostname: string;
port: string; port: string;
path: string;
pathname: string; pathname: string;
search: string; search: string;
searchParams: any; searchParams: ISearchParams;
hash: string; hash: string;
} }
export class Smarturl { export interface ISearchParams {
public parseUrl(urlArg: string) { [key: string]: string;
const parsedUrlInstance = new plugins.url.URL(urlArg); }
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: {
key: string;
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) {
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 = { const parsedUrl: IUrlObject = {
href: parsedUrlInstance.href, href: parsedUrlInstance.href,
origin: parsedUrlInstance.origin, origin: `${parsedUrlInstance.protocol}://${parsedUrlInstance.resource}`,
protocol: parsedUrlInstance.protocol, protocol: parsedUrlInstance.protocol,
username: parsedUrlInstance.username, username: parsedUrlInstance.user.split(':')[0],
password: parsedUrlInstance.password, password: parsedUrlInstance.user.split(':')[1] || '',
host: parsedUrlInstance.host, host: `${parsedUrlInstance.resource}:${parsedUrlInstance.port}`,
hostname: parsedUrlInstance.hostname, hostname: parsedUrlInstance.resource,
port: parsedUrlInstance.port, port: parsedUrlInstance.port,
path,
pathname: parsedUrlInstance.pathname, pathname: parsedUrlInstance.pathname,
search: parsedUrlInstance.search, search: parsedUrlInstance.search,
searchParams: parsedUrlInstance.searchParams, searchParams,
hash: parsedUrlInstance.hash, hash: parsedUrlInstance.hash,
}; };
if (!parsedUrl.port && parsedUrl.protocol === 'https:') { if (!parsedUrl.port && parsedUrl.protocol === 'https:') {
// console.log(`inferring port 443 for "https:"`); // console.log(`inferring port 443 for "https:"`);
parsedUrl.port = '443'; parsedUrl.port = '443';
@ -40,6 +95,43 @@ export class Smarturl {
// console.log(`inferring port 80 for "http:"`); // console.log(`inferring port 80 for "http:"`);
parsedUrl.port = '80'; parsedUrl.port = '80';
} }
return parsedUrl; 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() {
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}`;
} }
} }

View File

@ -1,4 +1,4 @@
// node native // node native
import * as url from 'url'; import { default as url } from 'parse-url';
export { url }; export { url };

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true,
}
}

View File

@ -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"
}