Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
b84c8053ff | |||
544f309dc9 | |||
f6e6697244 | |||
ce6622f858 | |||
105b1ca637 | |||
546c7806bc | |||
d446575e60 | |||
31922529ae | |||
fced2e845e | |||
c7169e37a6 | |||
04a62f6176 | |||
ea9b67a328 | |||
dbb62a819a | |||
9381533066 | |||
4d966147c4 |
@ -19,23 +19,35 @@ mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
audit:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
@ -50,9 +62,7 @@ testStable:
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
@ -63,9 +73,7 @@ testBuild:
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
@ -85,6 +93,8 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm"]
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11234
package-lock.json
generated
11234
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smarturl",
|
||||
"version": "1.0.2",
|
||||
"version": "2.0.1",
|
||||
"private": false,
|
||||
"description": "a url parsing lib",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -8,16 +8,15 @@
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"format": "(gitzone format)"
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.11.7",
|
||||
"tslint": "^5.11.0",
|
||||
"@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"
|
||||
},
|
||||
"dependencies": {},
|
||||
@ -32,5 +31,8 @@
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
21
readme.md
21
readme.md
@ -8,13 +8,20 @@ a url parsing lib
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smarturl/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smarturl/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smarturl/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smarturl)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smarturl)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
|
19
test/test.ts
19
test/test.ts
@ -1,8 +1,25 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smarturl from '../ts/index';
|
||||
|
||||
let testSmarturl: smarturl.Smarturl;
|
||||
|
||||
tap.test('first test', async () => {
|
||||
console.log(smarturl.standardExport);
|
||||
testSmarturl = new smarturl.Smarturl();
|
||||
expect(testSmarturl).to.be.instanceOf(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();
|
||||
|
@ -1,3 +1 @@
|
||||
import * as plugins from './smarturl.plugins';
|
||||
|
||||
export let standardExport = 'Hi there! :) This is an exported string';
|
||||
export * from './smarturl.classes.smarturl';
|
||||
|
112
ts/smarturl.classes.smarturl.ts
Normal file
112
ts/smarturl.classes.smarturl.ts
Normal file
@ -0,0 +1,112 @@
|
||||
import * as plugins from './smarturl.plugins';
|
||||
|
||||
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 = new plugins.url.URL(urlArg);
|
||||
const searchParams: ISearchParams = {};
|
||||
|
||||
// enrichment
|
||||
const searchParamKeys = parsedUrlInstance.searchParams.keys();
|
||||
for (const key of searchParamKeys) {
|
||||
searchParams[key] = parsedUrlInstance.searchParams.get(key);
|
||||
}
|
||||
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.origin,
|
||||
protocol: parsedUrlInstance.protocol,
|
||||
username: parsedUrlInstance.username,
|
||||
password: parsedUrlInstance.password,
|
||||
host: parsedUrlInstance.host,
|
||||
hostname: parsedUrlInstance.hostname,
|
||||
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,2 +1,4 @@
|
||||
const removeme = {};
|
||||
export { removeme };
|
||||
// node native
|
||||
import * as url from 'url';
|
||||
|
||||
export { url };
|
||||
|
Reference in New Issue
Block a user