Compare commits
No commits in common. "master" and "v0.0.4" have entirely different histories.
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,20 +1,3 @@
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
||||
.settings/
|
||||
.idea/
|
128
.gitlab-ci.yml
128
.gitlab-ci.yml
@ -1,128 +0,0 @@
|
||||
# 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
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
20
.travis.yml
Normal file
20
.travis.yml
Normal file
@ -0,0 +1,20 @@
|
||||
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:
|
||||
email: false
|
||||
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
11
.vscode/launch.json
vendored
@ -1,11 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
26
.vscode/settings.json
vendored
@ -1,26 +0,0 @@
|
||||
{
|
||||
"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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
Copyright (c) 2020 Lossless GmbH (hello@lossless.com)
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Push.Rocks
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -17,3 +19,4 @@ 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.
|
||||
|
12
README.md
Normal file
12
README.md
Normal file
@ -0,0 +1,12 @@
|
||||
# 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
|
52
changelog.md
52
changelog.md
@ -1,52 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
## 2024-10-03 - 3.1.0 - feat(Smarturl)
|
||||
Enhanced documentation and added method for property setting and chaining in Smarturl
|
||||
|
||||
- Added detailed comments to methods and interfaces for better code understanding.
|
||||
- Introduced a method to set properties in a chainable manner.
|
||||
|
||||
## 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.
|
6
index.js
Normal file
6
index.js
Normal file
@ -0,0 +1,6 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var path = require("path");
|
||||
var openURL = require("open");
|
||||
var smarturl = {};
|
||||
smarturl.open = openURL;
|
||||
module.exports = smarturl;
|
@ -1,31 +0,0 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smarturl",
|
||||
"description": "A library for parsing URLs in a detailed and flexible way.",
|
||||
"npmPackagename": "@push.rocks/smarturl",
|
||||
"license": "MIT",
|
||||
"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"
|
||||
}
|
||||
}
|
73
package.json
73
package.json
@ -1,53 +1,34 @@
|
||||
{
|
||||
"name": "@push.rocks/smarturl",
|
||||
"version": "3.1.0",
|
||||
"private": false,
|
||||
"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",
|
||||
"name": "smarturl",
|
||||
"version": "0.0.4",
|
||||
"description": "offers smart ways to handle URLs",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
"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)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@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"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"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"
|
||||
"url": "https://github.com/pushrocks/smarturl.git"
|
||||
},
|
||||
"keywords": [
|
||||
"json",
|
||||
"jade",
|
||||
"template"
|
||||
],
|
||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pushrocks/smarturl/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/smarturl",
|
||||
"dependencies": {
|
||||
"open": "0.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp": "3.9.0",
|
||||
"gulp-typescript": "2.9.2"
|
||||
}
|
||||
}
|
||||
|
4457
pnpm-lock.yaml
generated
4457
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
|
131
readme.md
131
readme.md
@ -1,131 +0,0 @@
|
||||
# @push.rocks/smarturl
|
||||
a url parsing lib
|
||||
|
||||
## Install
|
||||
|
||||
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:
|
||||
|
||||
```bash
|
||||
npm install @push.rocks/smarturl --save
|
||||
```
|
||||
|
||||
This will add `@push.rocks/smarturl` to your project's dependencies.
|
||||
|
||||
## Usage
|
||||
|
||||
`@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.
|
||||
|
||||
### Basic URL Parsing
|
||||
|
||||
To start parsing URLs, you first need to import `@push.rocks/smarturl` into your TypeScript file:
|
||||
|
||||
```typescript
|
||||
import { Smarturl } from '@push.rocks/smarturl';
|
||||
```
|
||||
|
||||
Now, you can parse a URL string and access its components:
|
||||
|
||||
```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.
|
3
test.js
Normal file
3
test.js
Normal file
@ -0,0 +1,3 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var smarturl = require("./index.js");
|
||||
smarturl.open("https://mojo.io");
|
@ -1,43 +0,0 @@
|
||||
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();
|
@ -1,17 +0,0 @@
|
||||
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();
|
@ -1,8 +0,0 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smarturl',
|
||||
version: '3.1.0',
|
||||
description: 'A library for parsing URLs in a detailed and flexible way.'
|
||||
}
|
2
ts/compile/compile.sh
Normal file
2
ts/compile/compile.sh
Normal file
@ -0,0 +1,2 @@
|
||||
nvm use v0.12.7
|
||||
gulp
|
25
ts/compile/gulpfile.js
Normal file
25
ts/compile/gulpfile.js
Normal file
@ -0,0 +1,25 @@
|
||||
// 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('compileTestTS', function() {
|
||||
var stream = gulp.src('../test.ts')
|
||||
.pipe(gulpTypescript({
|
||||
out: "test.js"
|
||||
}))
|
||||
.pipe(gulp.dest("../../"));
|
||||
return stream;
|
||||
});
|
||||
|
||||
gulp.task('default',['compileTS','compileTestTS'], function() {
|
||||
console.log('Typescript compiled');
|
||||
});
|
2
ts/compile/readme.md
Normal file
2
ts/compile/readme.md
Normal file
@ -0,0 +1,2 @@
|
||||
# How to compile.
|
||||
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.
|
7
ts/index.js
Normal file
7
ts/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var path = require("path");
|
||||
var openURL = require("open");
|
||||
var smarturl = {};
|
||||
smarturl.open = openURL;
|
||||
module.exports = smarturl;
|
||||
//# sourceMappingURL=index.js.map
|
1
ts/index.js.map
Normal file
1
ts/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,IAAI,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9B,IAAI,QAAQ,GAAO,EAAE,CAAC;AACtB,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC;AAIxB,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC"}
|
11
ts/index.ts
11
ts/index.ts
@ -1 +1,10 @@
|
||||
export * from './smarturl.classes.smarturl.js';
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var path = require("path");
|
||||
var openURL = require("open");
|
||||
|
||||
var smarturl:any = {};
|
||||
smarturl.open = openURL;
|
||||
|
||||
|
||||
|
||||
module.exports = smarturl;
|
||||
|
@ -1,179 +0,0 @@
|
||||
// Import necessary plugins (if any are used in the module)
|
||||
import * as plugins from './smarturl.plugins.js';
|
||||
|
||||
// Interface representing the structure of a URL object
|
||||
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;
|
||||
}
|
||||
|
||||
// Interface representing the search parameters as a key-value pair object
|
||||
export interface ISearchParams {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
// Main Smarturl class implementing the IUrlObject interface
|
||||
export class Smarturl implements IUrlObject {
|
||||
// Static method to create a Smarturl instance from a URL string
|
||||
public static createFromUrl(
|
||||
urlArg: string,
|
||||
optionsArg?: {
|
||||
searchParams?: ISearchParams;
|
||||
}
|
||||
): Smarturl {
|
||||
// Parse the URL string using the built-in URL class
|
||||
const parsedUrlInstance = new URL(urlArg);
|
||||
const searchParams: ISearchParams = {};
|
||||
|
||||
// Array to hold key-value pairs of search parameters
|
||||
const searchParamPairs: {
|
||||
key: string;
|
||||
value: string;
|
||||
}[] = [];
|
||||
|
||||
// If the URL has search parameters, parse them into key-value pairs
|
||||
if (parsedUrlInstance.search) {
|
||||
parsedUrlInstance.search
|
||||
.replace('?', '') // Remove the '?' at the beginning
|
||||
.split('&') // Split the query string into individual parameters
|
||||
.map((searchParamPair) => {
|
||||
// Split each parameter into key and value and add to the array
|
||||
searchParamPairs.push({
|
||||
key: searchParamPair.split('=')[0],
|
||||
value: searchParamPair.split('=')[1],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Convert the array of key-value pairs into an object
|
||||
for (const searchParamPair of searchParamPairs) {
|
||||
searchParams[searchParamPair.key] = searchParamPair.value;
|
||||
}
|
||||
|
||||
// Merge any additional search parameters provided in optionsArg
|
||||
if (optionsArg?.searchParams) {
|
||||
for (const key of Object.keys(optionsArg.searchParams)) {
|
||||
searchParams[key] = optionsArg.searchParams[key];
|
||||
}
|
||||
}
|
||||
|
||||
// Reconstruct the path with updated search parameters
|
||||
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]}`;
|
||||
}
|
||||
}
|
||||
|
||||
// Create an IUrlObject containing all parts of the URL
|
||||
const parsedUrl: IUrlObject = {
|
||||
...parsedUrlInstance, // Spread operator to include all properties from parsedUrlInstance
|
||||
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, // Updated path with new search parameters
|
||||
pathname: parsedUrlInstance.pathname,
|
||||
search: parsedUrlInstance.search,
|
||||
searchParams, // The searchParams object we constructed
|
||||
hash: parsedUrlInstance.hash,
|
||||
};
|
||||
|
||||
// Infer default ports if none are specified based on the protocol
|
||||
if (!parsedUrl.port && parsedUrl.protocol === 'https:') {
|
||||
parsedUrl.port = '443';
|
||||
}
|
||||
if (!parsedUrl.port && parsedUrl.protocol === 'http:') {
|
||||
parsedUrl.port = '80';
|
||||
}
|
||||
|
||||
// Create a new Smarturl instance and assign the parsed URL properties
|
||||
const returnSmarturl = new Smarturl();
|
||||
Object.assign(returnSmarturl, parsedUrl); // Copy all properties from parsedUrl to returnSmarturl
|
||||
return returnSmarturl;
|
||||
}
|
||||
|
||||
// Static method to create a Smarturl instance from an existing IUrlObject
|
||||
public static createFromParsedUrl(parsedUrlArg: IUrlObject): Smarturl {
|
||||
const returnSmarturl = new Smarturl();
|
||||
Object.assign(returnSmarturl, parsedUrlArg); // Copy all properties from parsedUrlArg to returnSmarturl
|
||||
return returnSmarturl;
|
||||
}
|
||||
|
||||
// INSTANCE PROPERTIES (matching IUrlObject interface)
|
||||
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 initializes searchParams as an empty object
|
||||
constructor() {
|
||||
this.searchParams = {};
|
||||
}
|
||||
|
||||
// Method to create an independent clone of the current Smarturl instance
|
||||
clone(): Smarturl {
|
||||
const clonedInstance = new Smarturl();
|
||||
Object.assign(clonedInstance, this); // Copy all properties to the new instance
|
||||
clonedInstance.searchParams = { ...this.searchParams }; // Shallow copy of searchParams to prevent shared references
|
||||
return clonedInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Typed method to set a property and return the instance for chaining.
|
||||
* @param prop - The property name to set (must be a key of Smarturl)
|
||||
* @param value - The value to assign to the property
|
||||
* @returns The Smarturl instance for method chaining
|
||||
*/
|
||||
set<K extends keyof this>(prop: K, value: this[K]): this {
|
||||
this[prop] = value; // Set the property to the new value
|
||||
return this; // Return the instance for chaining
|
||||
}
|
||||
|
||||
// Method to convert the Smarturl instance back into a URL string
|
||||
toString(): string {
|
||||
let userpart = ``; // Initialize the user part of the URL (username and password)
|
||||
|
||||
// Construct the user part based on the presence of username and password
|
||||
if (this.username && !this.password) {
|
||||
userpart = `${this.username}@`;
|
||||
}
|
||||
if (this.username && this.password) {
|
||||
userpart = `${this.username}:${this.password}@`;
|
||||
}
|
||||
|
||||
// Construct and return the full URL string
|
||||
return `${this.protocol}//${userpart}${this.hostname}:${this.port}${this.path}`;
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
export {};
|
4
ts/test.js
Normal file
4
ts/test.js
Normal file
@ -0,0 +1,4 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var smarturl = require("./index.js");
|
||||
smarturl.open("https://mojo.io");
|
||||
//# sourceMappingURL=test.js.map
|
1
ts/test.js.map
Normal file
1
ts/test.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,IAAI,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AACrC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC"}
|
3
ts/test.ts
Normal file
3
ts/test.ts
Normal file
@ -0,0 +1,3 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var smarturl = require("./index.js");
|
||||
smarturl.open("https://mojo.io");
|
12
ts/tsd.json
Normal file
12
ts/tsd.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"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
Normal file
2079
ts/typings/node/node.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
ts/typings/tsd.d.ts
vendored
Normal file
1
ts/typings/tsd.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference path="node/node.d.ts" />
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user