Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
105b1ca637 | |||
546c7806bc | |||
d446575e60 | |||
31922529ae | |||
fced2e845e | |||
c7169e37a6 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarturl",
|
"name": "@pushrocks/smarturl",
|
||||||
"version": "1.0.5",
|
"version": "1.0.8",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarturl",
|
"name": "@pushrocks/smarturl",
|
||||||
"version": "1.0.5",
|
"version": "1.0.8",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a url parsing lib",
|
"description": "a url parsing lib",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -8,4 +8,9 @@ tap.test('first test', async () => {
|
|||||||
expect(testSmarturl).to.be.instanceOf(smarturl.Smarturl);
|
expect(testSmarturl).to.be.instanceOf(smarturl.Smarturl);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should parse an URL', async () => {
|
||||||
|
const parsedUrl = testSmarturl.parseUrl('https://lossless.com');
|
||||||
|
console.log(parsedUrl);
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,7 +1,45 @@
|
|||||||
import * as plugins from './smarturl.plugins';
|
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;
|
||||||
|
pathname: string;
|
||||||
|
search: string;
|
||||||
|
searchParams: any;
|
||||||
|
hash: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class Smarturl {
|
export class Smarturl {
|
||||||
public parseUrl(urlArg: string) {
|
public parseUrl(urlArg: string) {
|
||||||
return new plugins.url.URL(urlArg);
|
const parsedUrlInstance = new plugins.url.URL(urlArg);
|
||||||
|
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,
|
||||||
|
pathname: parsedUrlInstance.pathname,
|
||||||
|
search: parsedUrlInstance.search,
|
||||||
|
searchParams: parsedUrlInstance.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';
|
||||||
|
}
|
||||||
|
return parsedUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user