Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
ae9e12ba86 | |||
c9b40c8725 | |||
0ab0308eb1 | |||
ff63115b4f | |||
0c49438942 | |||
dfc3944258 | |||
72fb807c59 | |||
a8495baf4c | |||
3a29679e66 | |||
08d5627e7e | |||
25a8b750d8 | |||
5eaa7ea0c3 | |||
d255c598b4 | |||
5bb01a2db9 | |||
44b1e67302 | |||
b1162191c6 | |||
60f1368071 | |||
1c503ec655 | |||
2d52a14ec1 | |||
55894a30f2 | |||
249c50a3c5 | |||
6470b05152 | |||
cfe189b02f | |||
f3e9f49af2 | |||
4b6dc9f5c3 |
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
46
changelog.md
Normal file
46
changelog.md
Normal file
@ -0,0 +1,46 @@
|
||||
# Changelog
|
||||
|
||||
## 2024-10-03 - 3.0.8 - fix(core)
|
||||
Fix code formatting and indentation issues in smarturl.classes.smarturl.ts
|
||||
|
||||
- Improved code readability by fixing indentation and ensuring consistent formatting.
|
||||
|
||||
## 2022-07-27 - 3.0.0 to 3.0.7 - Core Updates
|
||||
Maintenance and enhancement updates across multiple minor versions.
|
||||
|
||||
- **3.0.0**: Core updated with foundational changes.
|
||||
- **3.0.1**: Further core updates with minor fixes.
|
||||
- **3.0.2**: Continued enhancements and core updates.
|
||||
- **3.0.3**: Additional core updates.
|
||||
- **3.0.4**: Continued improvements in core functions.
|
||||
- **3.0.5**: Ongoing core enhancements and updates.
|
||||
- **3.0.6**: Maintenance improvements and stable updates.
|
||||
|
||||
## 2022-07-27 - 2.0.2 to 3.0.0 - Major Transition
|
||||
Introduction of significant changes to the core.
|
||||
|
||||
- **2.0.2**: Introduced breaking changes with a switch to ESM (ECMAScript Modules).
|
||||
|
||||
## 2021-05-02 - 1.0.8 to 2.0.2 - Stability Updates
|
||||
Updates focused on core stability and functionality.
|
||||
|
||||
- **1.0.8**: Breaking core updates were introduced to stabilize the platform.
|
||||
- **2.0.0**: Core was updated for greater efficiency.
|
||||
- **2.0.1**: Minor core improvements and updates.
|
||||
|
||||
## 2021-04-12 - 1.0.3 to 1.0.8 - Core Maintenance
|
||||
Multiple updates for improving the core functionality.
|
||||
|
||||
- Incremental updates from 1.0.3 through 1.0.7 enhancing core stability.
|
||||
|
||||
## 2020-03-27 - 1.0.1 to 1.0.2 - Initial Core Enhancements
|
||||
Early updates focusing on core aspects.
|
||||
|
||||
- Introduction of minor core improvements and fixes.
|
||||
|
||||
## 2015-10-21 - 0.0.1 to 0.0.4 - Project Initialization
|
||||
Initial setup and foundational updates for the project.
|
||||
|
||||
- **0.0.1**: Project initiation and Travis integration.
|
||||
- **0.0.3**: Creation of initial test infrastructure.
|
||||
- **0.0.4**: Basic project setup completed.
|
@ -2,17 +2,30 @@
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smarturl",
|
||||
"shortDescription": "a url parsing lib",
|
||||
"npmPackagename": "@pushrocks/smarturl",
|
||||
"description": "A library for parsing URLs in a detailed and flexible way.",
|
||||
"npmPackagename": "@push.rocks/smarturl",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
"projectDomain": "push.rocks",
|
||||
"keywords": [
|
||||
"URL parsing",
|
||||
"TypeScript",
|
||||
"node.js",
|
||||
"web development",
|
||||
"URL manipulation",
|
||||
"search parameters",
|
||||
"HTTP",
|
||||
"HTTPS"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
11860
package-lock.json
generated
11860
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
39
package.json
39
package.json
@ -1,25 +1,25 @@
|
||||
{
|
||||
"name": "@pushrocks/smarturl",
|
||||
"version": "2.0.1",
|
||||
"name": "@push.rocks/smarturl",
|
||||
"version": "3.0.8",
|
||||
"private": false,
|
||||
"description": "a url parsing lib",
|
||||
"description": "A library for parsing URLs in a detailed and flexible way.",
|
||||
"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.65",
|
||||
"@gitzone/tsrun": "^1.2.39",
|
||||
"@gitzone/tstest": "^1.0.74",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.15.11"
|
||||
},
|
||||
"dependencies": {},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
@ -34,5 +34,20 @@
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
],
|
||||
"keywords": [
|
||||
"URL parsing",
|
||||
"TypeScript",
|
||||
"node.js",
|
||||
"web development",
|
||||
"URL manipulation",
|
||||
"search parameters",
|
||||
"HTTP",
|
||||
"HTTPS"
|
||||
],
|
||||
"homepage": "https://code.foss.global/push.rocks/smarturl",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smarturl.git"
|
||||
}
|
||||
}
|
||||
|
4457
pnpm-lock.yaml
generated
Normal file
4457
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
146
readme.md
146
readme.md
@ -1,39 +1,131 @@
|
||||
# @pushrocks/smarturl
|
||||
# @push.rocks/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/)
|
||||
## Install
|
||||
|
||||
## Status for master
|
||||
To install `@push.rocks/smarturl`, you'll need Node.js and npm on your system. Once you have those set up, run the following command in your terminal:
|
||||
|
||||
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)
|
||||
```bash
|
||||
npm install @push.rocks/smarturl --save
|
||||
```
|
||||
|
||||
This will add `@push.rocks/smarturl` to your project's dependencies.
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class intellisense
|
||||
`@push.rocks/smarturl` is a library designed to simplify the parsing and manipulation of URLs within your TypeScript projects. Below is an overview of how you can leverage this library effectively in various scenarios.
|
||||
|
||||
## Contribution
|
||||
### Basic URL Parsing
|
||||
|
||||
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). :)
|
||||
To start parsing URLs, you first need to import `@push.rocks/smarturl` into your TypeScript file:
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
```typescript
|
||||
import { Smarturl } from '@push.rocks/smarturl';
|
||||
```
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
Now, you can parse a URL string and access its components:
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
```typescript
|
||||
const myUrl = Smarturl.createFromUrl('https://www.example.com:8080/path?query=string#hash');
|
||||
|
||||
console.log(myUrl.href); // https://www.example.com:8080/path?query=string#hash
|
||||
console.log(myUrl.protocol); // https:
|
||||
console.log(myUrl.host); // www.example.com:8080
|
||||
console.log(myUrl.pathname); // /path
|
||||
console.log(myUrl.search); // ?query=string
|
||||
console.log(myUrl.hash); // #hash
|
||||
console.log(myUrl.searchParams); // { query: 'string' }
|
||||
```
|
||||
|
||||
### Modifying Search Parameters
|
||||
|
||||
`@push.rocks/smarturl` makes it easy to modify search parameters of a URL:
|
||||
|
||||
```typescript
|
||||
// Creating a URL with initial search parameters
|
||||
const myUrl = Smarturl.createFromUrl('https://www.example.com', {
|
||||
searchParams: {
|
||||
page: '1',
|
||||
filter: 'none',
|
||||
},
|
||||
});
|
||||
|
||||
// Adding or updating search parameters
|
||||
myUrl.searchParams['filter'] = 'newVal';
|
||||
myUrl.searchParams['newParam'] = 'value';
|
||||
|
||||
console.log(myUrl.toString()); // https://www.example.com:443/?page=1&filter=newVal&newParam=value
|
||||
```
|
||||
|
||||
### Complex URL Creation
|
||||
|
||||
Sometimes you may need to create a URL from parts:
|
||||
|
||||
```typescript
|
||||
let myUrl = new Smarturl();
|
||||
myUrl.protocol = 'https';
|
||||
myUrl.hostname = 'www.example.com';
|
||||
myUrl.port = '3000';
|
||||
myUrl.pathname = '/path/to/resource';
|
||||
myUrl.searchParams = {
|
||||
key: 'value',
|
||||
another: 'parameter'
|
||||
};
|
||||
|
||||
console.log(myUrl.toString()); // Prints the full URL
|
||||
```
|
||||
|
||||
### Handling Username and Password in URL
|
||||
|
||||
You can also include authentication details within the URL:
|
||||
|
||||
```typescript
|
||||
const myUrl = Smarturl.createFromUrl('https://user:password@www.example.com');
|
||||
console.log(myUrl.username); // user
|
||||
console.log(myUrl.password); // password
|
||||
```
|
||||
|
||||
### Working with URL Paths and Hashes
|
||||
|
||||
Manipulating paths and hashes is straightforward:
|
||||
|
||||
```typescript
|
||||
const myUrl = Smarturl.createFromUrl('https://www.example.com/path/to/resource');
|
||||
myUrl.hash = 'section1';
|
||||
|
||||
console.log(myUrl.toString()); // https://www.example.com:443/path/to/resource#section1
|
||||
```
|
||||
|
||||
### URL Encoding and Decoding
|
||||
|
||||
When working with URLs, encoding and decoding of search parameters is handled automatically by the library. This ensures that the URL remains valid and interpretable by browsers and servers.
|
||||
|
||||
```typescript
|
||||
const myUrl = Smarturl.createFromUrl('https://www.example.com');
|
||||
myUrl.searchParams['redirect_uri'] = 'https://www.redirect.com/path';
|
||||
|
||||
console.log(myUrl.toString()); // Automatically encodes the URI
|
||||
```
|
||||
|
||||
In addition to basic parsing and manipulation, `@push.rocks/smarturl` provides methods for deep manipulation of URLs, aiding in scenarios where complex URL operations are needed.
|
||||
|
||||
By understanding and utilizing these features, you can handle most URL-related tasks within your TypeScript applications with ease, ensuring that URLs are constructed, interpreted, and modified in a consistent and error-free manner.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
43
test/test.both.ts
Normal file
43
test/test.both.ts
Normal file
@ -0,0 +1,43 @@
|
||||
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 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();
|
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();
|
25
test/test.ts
25
test/test.ts
@ -1,25 +0,0 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smarturl from '../ts/index';
|
||||
|
||||
let testSmarturl: smarturl.Smarturl;
|
||||
|
||||
tap.test('first test', async () => {
|
||||
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();
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smarturl',
|
||||
version: '3.0.8',
|
||||
description: 'A library for parsing URLs in a detailed and flexible way.'
|
||||
}
|
@ -1 +1 @@
|
||||
export * from './smarturl.classes.smarturl';
|
||||
export * from './smarturl.classes.smarturl.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './smarturl.plugins';
|
||||
import * as plugins from './smarturl.plugins.js';
|
||||
|
||||
export interface IUrlObject {
|
||||
href: string;
|
||||
@ -27,13 +27,29 @@ export class Smarturl implements IUrlObject {
|
||||
searchParams?: ISearchParams;
|
||||
}
|
||||
): Smarturl {
|
||||
const parsedUrlInstance = new plugins.url.URL(urlArg);
|
||||
const parsedUrlInstance = new URL(urlArg);
|
||||
const searchParams: ISearchParams = {};
|
||||
|
||||
// enrichment
|
||||
const searchParamKeys = parsedUrlInstance.searchParams.keys();
|
||||
for (const key of searchParamKeys) {
|
||||
searchParams[key] = parsedUrlInstance.searchParams.get(key);
|
||||
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)) {
|
||||
@ -41,11 +57,11 @@ export class Smarturl implements IUrlObject {
|
||||
}
|
||||
}
|
||||
|
||||
let path = parsedUrlInstance.pathname;
|
||||
let path = parsedUrlInstance.pathname || '';
|
||||
if (Object.keys(searchParams).length > 0) {
|
||||
path += '?';
|
||||
let first = true;
|
||||
for(const key of Object.keys(searchParams)) {
|
||||
for (const key of Object.keys(searchParams)) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
@ -56,6 +72,7 @@ export class Smarturl implements IUrlObject {
|
||||
}
|
||||
|
||||
const parsedUrl: IUrlObject = {
|
||||
...parsedUrlInstance,
|
||||
href: parsedUrlInstance.href,
|
||||
origin: parsedUrlInstance.origin,
|
||||
protocol: parsedUrlInstance.protocol,
|
||||
@ -83,6 +100,7 @@ export class Smarturl implements IUrlObject {
|
||||
Object.assign(returnSmarturl, parsedUrl);
|
||||
return returnSmarturl;
|
||||
}
|
||||
|
||||
public static createFromParsedUrl(parsedUrlArg: IUrlObject) {
|
||||
const returnSmarturl = new Smarturl();
|
||||
Object.assign(returnSmarturl, parsedUrlArg);
|
||||
@ -104,9 +122,26 @@ export class Smarturl implements IUrlObject {
|
||||
searchParams: ISearchParams;
|
||||
hash: string;
|
||||
|
||||
constructor() {}
|
||||
constructor() {
|
||||
this.searchParams = {};
|
||||
}
|
||||
|
||||
clone(): Smarturl {
|
||||
const clonedInstance = new Smarturl();
|
||||
Object.assign(clonedInstance, this);
|
||||
clonedInstance.searchParams = { ...this.searchParams };
|
||||
return clonedInstance;
|
||||
}
|
||||
|
||||
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
|
||||
import * as url from 'url';
|
||||
|
||||
export { url };
|
||||
export {};
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
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