Comparing version 0.0.2 to 0.1.0
{ | ||
"name": "s3u", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "S3 URL manipulation helper", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
import { S3Url } from '../index'; | ||
const s3 = S3Url.fromUrl('https://s3.amazonaws.com'); | ||
s3.makeUrl() | ||
const url = s3.href |
@@ -56,2 +56,22 @@ 'use strict'; | ||
}); | ||
describe('Generic', () => { | ||
itIsConvertedFine('http://example.com/'); | ||
itIsConvertedFine('https://fra1.example.com/'); | ||
itIsConvertedFine('https://test.fra1.example.com/'); | ||
itIsConvertedFine('https://test.fra1.example.com/'); | ||
itIsConvertedFine('https://fra1.example.com/test/file.txt'); | ||
itIsConvertedFine('https://test.fra1.example.com/file.txt'); | ||
itIsConvertedFine('https://fra1.example.com/test/file.txt'); | ||
itIsConvertedFine('https://test.fra1.example.com/file.txt'); | ||
it('return invalid url when cannot parse', () => { | ||
const s3Url = S3Url.fromUrl('invalid-url'); | ||
expect(s3Url).toMatchObject({ | ||
bucket: '', | ||
isValid: false, | ||
provider: null, | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -58,0 +78,0 @@ |
@@ -8,6 +8,4 @@ 'use strict'; | ||
describe('parseUrl', () => { | ||
const provider = new S3Provider({ domain: 'example.com' }); | ||
it('simple', () => { | ||
expect(parse('https://example.com/test/file.txt')).toMatchObject({ | ||
expectParsed('https://example.com/test/file.txt', { | ||
bucket: 'test', | ||
@@ -21,3 +19,3 @@ bucketPosition: 'pathname', | ||
it('domain root with region', () => { | ||
expect(parse('https://test.example.com/')).toMatchObject({ | ||
expectParsed('https://test.example.com/', { | ||
bucket: '', | ||
@@ -27,3 +25,2 @@ bucketPosition: 'pathname', | ||
region: 'test', | ||
provider, | ||
}); | ||
@@ -33,5 +30,3 @@ }); | ||
it('with region', () => { | ||
expect( | ||
parse('https://eu-west-2.example.com/test/file.txt') | ||
).toMatchObject({ | ||
expectParsed('https://eu-west-2.example.com/test/file.txt', { | ||
bucket: 'test', | ||
@@ -41,3 +36,2 @@ bucketPosition: 'pathname', | ||
region: 'eu-west-2', | ||
provider, | ||
}); | ||
@@ -47,5 +41,3 @@ }); | ||
it('domain based with region', () => { | ||
expect( | ||
parse('https://test.eu-west-2.example.com/file.txt') | ||
).toMatchObject({ | ||
expectParsed('https://test.eu-west-2.example.com/file.txt', { | ||
bucket: 'test', | ||
@@ -55,10 +47,10 @@ bucketPosition: 'hostname', | ||
region: 'eu-west-2', | ||
provider, | ||
}); | ||
}); | ||
function parse(url) { | ||
return provider.parseUrl({ url }); | ||
function expectParsed(url, matchedObject) { | ||
const provider = new S3Provider({ domain: 'example.com' }); | ||
expect(provider.parseUrl({ url })).toMatchObject(matchedObject); | ||
} | ||
}); | ||
}); |
@@ -18,2 +18,3 @@ export class S3Url { | ||
readonly href: string; | ||
readonly isValid: string; | ||
@@ -25,4 +26,3 @@ constructor(attrs: Partial<S3Url> | string); | ||
clone(newAttrs?: Partial<S3Url>): S3Url; | ||
isValid(): boolean; | ||
makeUrl(): string; | ||
setBucket(bucket: string): void; | ||
@@ -29,0 +29,0 @@ setBucketPosition(position: 'hostname' | 'pathname'): void; |
@@ -53,2 +53,6 @@ 'use strict'; | ||
get isValid() { | ||
return Boolean(this.provider && typeof this.provider === 'object'); | ||
} | ||
clone(newAttrs = {}) { | ||
@@ -58,6 +62,2 @@ return new S3Url({ ...this, newAttrs }); | ||
isValid() { | ||
return typeof this.provider === 'object'; | ||
} | ||
setBucket(bucket) { | ||
@@ -64,0 +64,0 @@ this.bucket = bucket; |
24161
687