Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
1c503ec655 | |||
2d52a14ec1 | |||
55894a30f2 | |||
249c50a3c5 | |||
6470b05152 | |||
cfe189b02f | |||
f3e9f49af2 | |||
4b6dc9f5c3 | |||
b84c8053ff | |||
544f309dc9 | |||
f6e6697244 | |||
ce6622f858 | |||
105b1ca637 | |||
546c7806bc | |||
d446575e60 | |||
31922529ae | |||
fced2e845e | |||
c7169e37a6 | |||
04a62f6176 | |||
ea9b67a328 | |||
dbb62a819a | |||
9381533066 | |||
4d966147c4 | |||
3c609edf0a | |||
0a1bf06048 | |||
a84368fd42 | |||
752553161e |
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,3 +1,20 @@
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
.settings/
|
||||
.idea/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
128
.gitlab-ci.yml
Normal file
128
.gitlab-ci.yml
Normal file
@ -0,0 +1,128 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
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
|
||||
allow_failure: true
|
||||
|
||||
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 --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
19
.travis.yml
19
.travis.yml
@ -1,19 +0,0 @@
|
||||
language: node_js
|
||||
before_install:
|
||||
- nvm install stable
|
||||
- node -v
|
||||
- npm -v
|
||||
- npm install -g gulp
|
||||
- npm install gulp
|
||||
- npm install gulp-typescript
|
||||
deploy:
|
||||
provider: npm
|
||||
email: npm@smart-coordination.com
|
||||
api_key:
|
||||
secure: P0Wz+4tHBh9+DeC92ZFB8U8M8PZSfv2nQpovc6dfVuDjQ62cbozbd8w49Qf3+/TQB6Duz9ZyOIg28c25/FoJ0UhqFuVqzhOS8pn5wv3E3+i2tZSFek2MIlHJLoy2hAOVi2jqhJ504+h/ncEU9J1z71cWiDWo7Bmb5R0J+0QfsHjH8Yz/b6WBgJOsneOxp8Ne+AWr5xq1Welx9Xh9AD99frWfQM3imX0/ticOW2fiUjiebuMNIzbGiE4Z6OAcgJFNU4Ny9n6xz4B0dHGXjmAHgzMdX4P1TEjEwbhXg9hDkobPn/BKJr+ora1sf/hk4AMSaVRiw3XcxrCy77bMMJB0TQYdiMfB+ZDQ4p6orDqbazvLgGE/vlG4mdv0Xp8kHX8gfkN8tGEluOFM2d1uxV+McKnau//ak61usuuk7D5O6uiDhKLE/zfBSw89h9UCC8MFmLQ2UUVdg90lH5MVhy5xDTEuZxvifCNIDGNtIVWQ0PM251ebma2F3RqL0pafTkydfcPb/ZkR6cjKr0fwG/s3HMChYB74MfAsX5GDFw9YY20jrcnVIPWBluRelTes+ajAakjTHPpk7ZkUSH/oJGV2TKDXI08xq3CYq7aULOl46fo2oz94r1tOuUHWynTKijLPqNu/P1IcmCMqRKlpBedNxVdT2enAliE3m6DP7LVsEV4=
|
||||
on:
|
||||
tags: true
|
||||
repo: pushrocks/smarturl
|
||||
notifications:
|
||||
slack:
|
||||
secure: f5Uss0z9RPl/QcA/DroB8loyE93aOYI6bqCkrsiUscmZtlv/TVQtT4dxqGA6uvcG6iTQDBi3Ul88dQxWkRm4IqbhY35/iMaV2dHW4FVYMAh8GQMbsfL2sALCcufxD9blw47awv3iFcwhV1EeyesscjgL0JIjduk96v/7G/6QIO2838M1lzlgtj+kRUkim8qkaEs1je3gRrhMUIjLuAdscMXyUKYFMjWo9ACSjVUl30R/ZNemb18itIja6i92GotreBgcfEMczvy58ovDC7xdJUsY8LjMI01DwY+WPRnI0tAhsuI8moBwwcdM4e3bAjKjucQRjO33O5bMWRZ6QCiYd0DnCEFyCPQLJ4GSy/tkD00n8ijLHAOSV3AH1zNbdK1EAdSPQXDvlI36KJn/2hyQLoitGHVUPr76ujJWP82ypO2tgIp3XQU0dJVCxDuHnwJO2+hjdI+gCPqxNTpjeujHx3UdkTGNRjuuf9dlZ/D08fApjYxy2fxItTqo3QjP/nrqvBXUOPP8yPHpjIT4H2t5Pr4SJjBGI6X4qhKyFj6s9rA/Xu1rL+45zu1C3uC3z+u3T9UwrbzJ/cZM6r6UQvQmUvIfBNaMlg4I/diQCDIPL+Rhop2nylY3IcHmJnk2itn7kOqj1tohCpFEml5pRuSZy4udWywkdtyBAsHWFLF7oiQ=
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
12
README.md
12
README.md
@ -1,12 +0,0 @@
|
||||
# smarturl
|
||||
offers smart ways to handle URLs
|
||||
|
||||
### Buildstatus/Dependencies
|
||||
[](https://travis-ci.org/pushrocks/gulp-bootstrap)
|
||||
[](https://david-dm.org/pushrocks/gulp-bootstrap#info=devDependencies)
|
||||
|
||||
### Usage
|
||||
TODO
|
||||
|
||||
Cheers
|
||||
Phil from Lossless Digital
|
11
index.js
11
index.js
@ -1,11 +0,0 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var path, through;
|
||||
through = require("through2");
|
||||
path = require("path");
|
||||
module.exports = function (jadeTemplate, mojo) {
|
||||
if (mojo === void 0) { mojo = undefined; }
|
||||
return through.obj(function (file, enc, cb) {
|
||||
//run callback function to signal end of plugin process.
|
||||
return cb(null, file);
|
||||
});
|
||||
};
|
@ -1,6 +1,4 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Push.Rocks
|
||||
Copyright (c) 2020 Lossless GmbH (hello@lossless.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -18,5 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
SOFTWARE.
|
18
npmextra.json
Normal file
18
npmextra.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smarturl",
|
||||
"description": "a url parsing lib",
|
||||
"npmPackagename": "@pushrocks/smarturl",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
}
|
||||
}
|
14745
package-lock.json
generated
Normal file
14745
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
62
package.json
62
package.json
@ -1,34 +1,40 @@
|
||||
{
|
||||
"name": "smarturl",
|
||||
"version": "0.0.3",
|
||||
"description": "offers smart ways to handle URLs",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "(cd ts/compile && gulp)",
|
||||
"reinstall": "(rm -r node_modules && npm install)",
|
||||
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
|
||||
"startdev": "(git checkout master && git pull origin master)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pushrocks/smarturl.git"
|
||||
},
|
||||
"keywords": [
|
||||
"json",
|
||||
"jade",
|
||||
"template"
|
||||
],
|
||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
||||
"name": "@pushrocks/smarturl",
|
||||
"version": "3.0.2",
|
||||
"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",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pushrocks/smarturl/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/smarturl",
|
||||
"dependencies": {
|
||||
"open": "0.0.5"
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp": "3.9.0",
|
||||
"gulp-typescript": "2.9.2"
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tstest": "^1.0.72",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.6.1"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"dependencies": {
|
||||
"parse-url": "^6.0.5"
|
||||
}
|
||||
}
|
||||
|
39
readme.md
Normal file
39
readme.md
Normal file
@ -0,0 +1,39 @@
|
||||
# @pushrocks/smarturl
|
||||
a url parsing lib
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smarturl)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smarturl)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smarturl)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smarturl/)
|
||||
|
||||
## Status for master
|
||||
|
||||
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
|
||||
|
||||
Use TypeScript for best in class intellisense
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
39
test/test.ts
Normal file
39
test/test.ts
Normal file
@ -0,0 +1,39 @@
|
||||
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 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.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();
|
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.2',
|
||||
description: 'a url parsing lib'
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
nvm use v0.12.7
|
||||
gulp
|
@ -1,16 +0,0 @@
|
||||
// import gulp
|
||||
var gulp = require("gulp"),
|
||||
gulpTypescript = require("gulp-typescript");
|
||||
|
||||
gulp.task('compileTS', function() {
|
||||
var stream = gulp.src('../index.ts')
|
||||
.pipe(gulpTypescript({
|
||||
out: "index.js"
|
||||
}))
|
||||
.pipe(gulp.dest("../../"));
|
||||
return stream;
|
||||
});
|
||||
|
||||
gulp.task('default',['compileTS'], function() {
|
||||
console.log('Typescript compiled');
|
||||
});
|
@ -1,2 +0,0 @@
|
||||
# How to compile.
|
||||
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.
|
@ -1,6 +0,0 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var path = require("path");
|
||||
var open = require("open");
|
||||
var smarturl = {};
|
||||
module.exports = smarturl;
|
||||
//# sourceMappingURL=index.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE3B,IAAI,QAAQ,GAAO,EAAE,CAAC;AAItB,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC"}
|
10
ts/index.ts
10
ts/index.ts
@ -1,9 +1 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var path = require("path");
|
||||
var open = require("open");
|
||||
|
||||
var smarturl:any = {};
|
||||
|
||||
|
||||
|
||||
module.exports = smarturl;
|
||||
export * from './smarturl.classes.smarturl.js';
|
||||
|
137
ts/smarturl.classes.smarturl.ts
Normal file
137
ts/smarturl.classes.smarturl.ts
Normal file
@ -0,0 +1,137 @@
|
||||
import * as plugins from './smarturl.plugins.js';
|
||||
|
||||
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: {
|
||||
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 = {
|
||||
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() {
|
||||
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}`;
|
||||
}
|
||||
}
|
4
ts/smarturl.plugins.ts
Normal file
4
ts/smarturl.plugins.ts
Normal file
@ -0,0 +1,4 @@
|
||||
// node native
|
||||
import { default as url } from 'parse-url';
|
||||
|
||||
export { url };
|
12
ts/tsd.json
12
ts/tsd.json
@ -1,12 +0,0 @@
|
||||
{
|
||||
"version": "v4",
|
||||
"repo": "borisyankov/DefinitelyTyped",
|
||||
"ref": "master",
|
||||
"path": "typings",
|
||||
"bundle": "typings/tsd.d.ts",
|
||||
"installed": {
|
||||
"node/node.d.ts": {
|
||||
"commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63"
|
||||
}
|
||||
}
|
||||
}
|
2079
ts/typings/node/node.d.ts
vendored
2079
ts/typings/node/node.d.ts
vendored
File diff suppressed because it is too large
Load Diff
1
ts/typings/tsd.d.ts
vendored
1
ts/typings/tsd.d.ts
vendored
@ -1 +0,0 @@
|
||||
/// <reference path="node/node.d.ts" />
|
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,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user