Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mapbox/s3urls

Package Overview
Dependencies
Maintainers
217
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mapbox/s3urls - npm Package Compare versions

Comparing version 1.5.2 to 1.5.3

LICENSE.txt

33

index.js

@@ -1,15 +0,17 @@

var parse = require('url').parse;
'use strict';
var s3urls = module.exports = {
const parse = require('url').parse;
const s3urls = module.exports = {
fromUrl: function(url) {
var uri = parse(url);
const uri = parse(url);
uri.pathname = decodeURIComponent(uri.pathname || '');
var style = (function(uri) {
const style = (function(uri) {
if (uri.protocol === 's3:') return 's3';
if (/^s3[\.-](\w{2}-\w{4,9}-\d\.)?amazonaws\.com/.test(uri.hostname)) return 'bucket-in-path';
if (/\.s3[\.-](\w{2}-\w{4,9}-\d\.)?amazonaws\.com/.test(uri.hostname)) return 'bucket-in-host';
if (/^s3[.-](\w{2}-\w{4,9}-\d\.)?amazonaws\.com/.test(uri.hostname)) return 'bucket-in-path';
if (/\.s3[.-](\w{2}-\w{4,9}-\d\.)?amazonaws\.com/.test(uri.hostname)) return 'bucket-in-host';
})(uri);
var bucket, key;
let bucket, key;
if (style === 's3') {

@@ -24,3 +26,8 @@ bucket = uri.hostname;

if (style === 'bucket-in-host') {
bucket = uri.hostname.split('.')[0];
const match = uri.hostname.replace(/\.s3[.-](\w{2}-\w{4,9}-\d\.)?amazonaws\.com(\.cn)?/, '');
if (match.length) {
bucket = match;
} else {
bucket = uri.hostname.split('.')[0];
}
key = uri.pathname.slice(1);

@@ -37,5 +44,5 @@ }

return {
's3': [ 's3:/', bucket, key ].join('/'),
'bucket-in-path': [ 'https://s3.amazonaws.com', bucket, key ].join('/'),
'bucket-in-host': [ 'https:/', bucket + '.s3.amazonaws.com', key ].join('/')
's3': ['s3:/', bucket, key].join('/'),
'bucket-in-path': ['https://s3.amazonaws.com', bucket, key].join('/'),
'bucket-in-host': ['https:/', bucket + '.s3.amazonaws.com', key].join('/')
};

@@ -45,3 +52,3 @@ },

convert: function(url, to) {
var params = s3urls.fromUrl(url);
const params = s3urls.fromUrl(url);
return s3urls.toUrl(params.Bucket, params.Key)[to];

@@ -53,5 +60,5 @@ },

valid: function(url) {
var params = s3urls.fromUrl(url);
const params = s3urls.fromUrl(url);
return params.Bucket && params.Key;
}
};
{
"name": "@mapbox/s3urls",
"version": "1.5.2",
"version": "1.5.3",
"description": "Create S3 urls from bucket/key or extract bucket/key from them",
"main": "index.js",
"engines": {
"node": ">= 6.10.3"
},
"bin": {

@@ -13,3 +16,4 @@ "s3urls": "bin/s3urls.js"

"scripts": {
"test": "tape test/*.test.js"
"lint": "eslint *.js test/*.js",
"test": "tape test/*.test.js && eslint *.js test/*.js"
},

@@ -26,10 +30,16 @@ "repository": {

"homepage": "https://github.com/mapbox/s3urls",
"eslintConfig": {
"extends": "@mapbox/eslint-config-mapbox"
},
"devDependencies": {
"cross-exec-file": "^1.0.0",
"eslint": "^4.17.0",
"eslint-plugin-node": "^5.2.1",
"tape": "^3.0.3"
},
"dependencies": {
"@mapbox/eslint-config-mapbox": "^1.0.0",
"minimist": "^1.1.0",
"s3signed": "^0.1.0"
}
}
}

@@ -1,8 +0,10 @@

var test = require('tape').test;
var exec = require('cross-exec-file');
var path = require('path');
var cmd = path.resolve(__dirname, '..', 'bin', 's3urls.js');
'use strict';
test('bad command', function(t) {
exec(cmd, ['ham'], function(err, stdout, stderr) {
const test = require('tape').test;
const exec = require('cross-exec-file');
const path = require('path');
const cmd = path.resolve(__dirname, '..', 'bin', 's3urls.js');
test('bad command', (t) => {
exec(cmd, ['ham'], (err, stdout, stderr) => {
t.equal(err.code, 1, 'exit 1');

@@ -14,4 +16,4 @@ t.equal(stderr, 'ERROR: Invalid command\n', 'expected message');

test('toUrl: bad args', function(t) {
exec(cmd, ['to-url'], function(err, stdout, stderr) {
test('toUrl: bad args', (t) => {
exec(cmd, ['to-url'], (err, stdout, stderr) => {
t.equal(err.code, 1, 'exit 1');

@@ -23,4 +25,4 @@ t.equal(stderr, 'ERROR: Must specify bucket and key\n', 'expected message');

test('toUrl: all types', function(t) {
expected = [
test('toUrl: all types', (t) => {
const expected = [
's3://bucket/key',

@@ -31,5 +33,5 @@ 'https://s3.amazonaws.com/bucket/key',

exec(cmd, ['to-url', 'bucket', 'key'], function(err, stdout, stderr) {
exec(cmd, ['to-url', 'bucket', 'key'], (err, stdout) => {
t.ifError(err, 'completed');
stdout.trim().split('\n').forEach(function(url) {
stdout.trim().split('\n').forEach((url) => {
t.ok(expected.indexOf(url) > -1, 'expected url');

@@ -41,6 +43,6 @@ });

test('toUrl: s3 type', function(t) {
expected = 's3://bucket/key';
test('toUrl: s3 type', (t) => {
const expected = 's3://bucket/key';
exec(cmd, ['to-url', 'bucket', 'key', '--type', 's3'], function(err, stdout, stderr) {
exec(cmd, ['to-url', 'bucket', 'key', '--type', 's3'], (err, stdout) => {
t.ifError(err, 'completed');

@@ -52,6 +54,6 @@ t.equal(stdout, expected + '\n', 'expected url');

test('toUrl: bucket-in-path type', function(t) {
expected = 'https://s3.amazonaws.com/bucket/key';
test('toUrl: bucket-in-path type', (t) => {
const expected = 'https://s3.amazonaws.com/bucket/key';
exec(cmd, ['to-url', 'bucket', 'key', '--type', 'bucket-in-path'], function(err, stdout, stderr) {
exec(cmd, ['to-url', 'bucket', 'key', '--type', 'bucket-in-path'], (err, stdout) => {
t.ifError(err, 'completed');

@@ -63,6 +65,6 @@ t.equal(stdout, expected + '\n', 'expected url');

test('toUrl: bucket-in-host type', function(t) {
expected = 'https://bucket.s3.amazonaws.com/key';
test('toUrl: bucket-in-host type', (t) => {
const expected = 'https://bucket.s3.amazonaws.com/key';
exec(cmd, ['to-url', 'bucket', 'key', '--type', 'bucket-in-host'], function(err, stdout, stderr) {
exec(cmd, ['to-url', 'bucket', 'key', '--type', 'bucket-in-host'], (err, stdout) => {
t.ifError(err, 'completed');

@@ -74,4 +76,4 @@ t.equal(stdout, expected + '\n', 'expected url');

test('fromUrl: no url', function(t) {
exec(cmd, ['from-url'], function(err, stdout, stderr) {
test('fromUrl: no url', (t) => {
exec(cmd, ['from-url'], (err, stdout, stderr) => {
t.equal(err.code, 1, 'exit 1');

@@ -83,4 +85,4 @@ t.equal(stderr, 'ERROR: No url given\n', 'expected message');

test('fromUrl: unrecognized url', function(t) {
exec(cmd, ['from-url', 'http://www.google.com'], function(err, stdout, stderr) {
test('fromUrl: unrecognized url', (t) => {
exec(cmd, ['from-url', 'http://www.google.com'], (err, stdout, stderr) => {
t.equal(err.code, 1, 'exit 1');

@@ -92,4 +94,4 @@ t.equal(stderr, 'ERROR: Unrecognizable S3 url\n', 'expected message');

test('fromUrl: success', function(t) {
exec(cmd, ['from-url', 's3://bucket/key'], function(err, stdout, stderr) {
test('fromUrl: success', (t) => {
exec(cmd, ['from-url', 's3://bucket/key'], (err, stdout) => {
t.equal(stdout, JSON.stringify({

@@ -103,4 +105,4 @@ Bucket: 'bucket',

test('convert: no url', function(t) {
exec(cmd, ['convert'], function(err, stdout, stderr) {
test('convert: no url', (t) => {
exec(cmd, ['convert'], (err, stdout, stderr) => {
t.equal(err.code, 1, 'exit 1');

@@ -112,4 +114,4 @@ t.equal(stderr, 'ERROR: No url given\n', 'expected message');

test('convert: unrecognized url', function(t) {
exec(cmd, ['convert', 'http://www.google.com'], function(err, stdout, stderr) {
test('convert: unrecognized url', (t) => {
exec(cmd, ['convert', 'http://www.google.com'], (err, stdout, stderr) => {
t.equal(err.code, 1, 'exit 1');

@@ -121,4 +123,4 @@ t.equal(stderr, 'ERROR: Unrecognizable S3 url\n', 'expected message');

test('convert: default success', function(t) {
exec(cmd, ['convert', 's3://bucket/key'], function(err, stdout, stderr) {
test('convert: default success', (t) => {
exec(cmd, ['convert', 's3://bucket/key'], (err, stdout) => {
t.equal(stdout, 'https://bucket.s3.amazonaws.com/key\n', 'expected result');

@@ -129,4 +131,4 @@ t.end();

test('convert: typed success', function(t) {
exec(cmd, ['convert', 's3://bucket/key', '--type', 'bucket-in-path'], function(err, stdout, stderr) {
test('convert: typed success', (t) => {
exec(cmd, ['convert', 's3://bucket/key', '--type', 'bucket-in-path'], (err, stdout) => {
t.equal(stdout, 'https://s3.amazonaws.com/bucket/key\n', 'expected result');

@@ -133,0 +135,0 @@ t.end();

@@ -1,6 +0,8 @@

var test = require('tape').test;
var s3Urls = require('..');
'use strict';
test('toUrl', function(t) {
var result = s3Urls.toUrl('bucket', 'key');
const test = require('tape').test;
const s3Urls = require('..');
test('toUrl', (t) => {
const result = s3Urls.toUrl('bucket', 'key');
t.equal(result.s3, 's3://bucket/key', 'expected s3 url');

@@ -12,4 +14,4 @@ t.equal(result['bucket-in-path'], 'https://s3.amazonaws.com/bucket/key', 'expected bucket-in-path url');

test('fromUrl: unrecognized url', function(t) {
var result = s3Urls.fromUrl('http://www.google.com');
test('fromUrl: unrecognized url', (t) => {
const result = s3Urls.fromUrl('http://www.google.com');
t.notOk(result.Bucket, 'no bucket');

@@ -20,4 +22,4 @@ t.notOk(result.Key, 'no key');

test('fromUrl: s3 style', function(t) {
var result = s3Urls.fromUrl('s3://bucket/the/whole/key');
test('fromUrl: s3 style', (t) => {
const result = s3Urls.fromUrl('s3://bucket/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -28,4 +30,11 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('fromUrl: s3 bucket only style', function(t) {
var result = s3Urls.fromUrl('s3://bucket');
test('fromUrl: s3 style - dot', (t) => {
const result = s3Urls.fromUrl('s3://results.openaddresses.io/the/whole/key');
t.equal(result.Bucket, 'results.openaddresses.io', 'expected bucket');
t.equal(result.Key, 'the/whole/key', 'expected key');
t.end();
});
test('fromUrl: s3 bucket only style', (t) => {
const result = s3Urls.fromUrl('s3://bucket');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -36,4 +45,4 @@ t.equal(result.Key, '', 'expected key');

test('fromUrl: s3 bucket only style with slash', function(t) {
var result = s3Urls.fromUrl('s3://bucket/');
test('fromUrl: s3 bucket only style with slash', (t) => {
const result = s3Urls.fromUrl('s3://bucket/');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -44,4 +53,4 @@ t.equal(result.Key, '', 'expected key');

test('fromUrl: bucket-in-path style', function(t) {
var result = s3Urls.fromUrl('https://s3.amazonaws.com/bucket/the/whole/key');
test('fromUrl: bucket-in-path style', (t) => {
const result = s3Urls.fromUrl('https://s3.amazonaws.com/bucket/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -52,4 +61,4 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('fromUrl: bucket-in-path style in cn-north-1', function(t) {
var result = s3Urls.fromUrl('https://s3.cn-north-1.amazonaws.com.cn/bucket/the/whole/key');
test('fromUrl: bucket-in-path style in cn-north-1', (t) => {
const result = s3Urls.fromUrl('https://s3.cn-north-1.amazonaws.com.cn/bucket/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -60,4 +69,11 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('fromUrl: bucket-in-path style in ap-southeast-1', function(t) {
var result = s3Urls.fromUrl('https://s3.ap-southeast-1.amazonaws.com/bucket/the/whole/key');
test('fromUrl: bucket-in-path style in cn-north-1 w/ dot bucket', (t) => {
const result = s3Urls.fromUrl('https://s3.cn-north-1.amazonaws.com.cn/results.openaddresses.io/the/whole/key');
t.equal(result.Bucket, 'results.openaddresses.io', 'expected bucket');
t.equal(result.Key, 'the/whole/key', 'expected key');
t.end();
});
test('fromUrl: bucket-in-path style in ap-southeast-1', (t) => {
const result = s3Urls.fromUrl('https://s3.ap-southeast-1.amazonaws.com/bucket/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -68,4 +84,4 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('fromUrl: bucket-in-path dashed in cn-north-1', function(t) {
var result = s3Urls.fromUrl('https://s3-cn-north-1.amazonaws.com.cn/bucket/the/whole/key');
test('fromUrl: bucket-in-path dashed in cn-north-1', (t) => {
const result = s3Urls.fromUrl('https://s3-cn-north-1.amazonaws.com.cn/bucket/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -76,4 +92,4 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('fromUrl: bucket-in-path dashed in ap-southeast-1', function(t) {
var result = s3Urls.fromUrl('https://s3-ap-southeast-1.amazonaws.com/bucket/the/whole/key');
test('fromUrl: bucket-in-path dashed in ap-southeast-1', (t) => {
const result = s3Urls.fromUrl('https://s3-ap-southeast-1.amazonaws.com/bucket/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -84,4 +100,4 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('fromUrl: bucket-in-host style', function(t) {
var result = s3Urls.fromUrl('https://bucket.s3.amazonaws.com/the/whole/key');
test('fromUrl: bucket-in-host style', (t) => {
const result = s3Urls.fromUrl('https://bucket.s3.amazonaws.com/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -92,4 +108,18 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('fromUrl: bucket-in-host style in cn-north-1', function(t) {
var result = s3Urls.fromUrl('https://bucket.s3.cn-north-1.amazonaws.com.cn/the/whole/key');
test('fromUrl: bucket-in-host style in cn-north-1 w/ dot', (t) => {
const result = s3Urls.fromUrl('https://results.openaddresses.io.s3.cn-north-1.amazonaws.com.cn/the/whole/key');
t.equal(result.Bucket, 'results.openaddresses.io', 'expected bucket');
t.equal(result.Key, 'the/whole/key', 'expected key');
t.end();
});
test('fromUrl: bucket-in-host style in cn-north-1 w/ dot & s3', (t) => {
const result = s3Urls.fromUrl('https://results.s3llout-to-the-man.io.s3.amazonaws.com/the/whole/key');
t.equal(result.Bucket, 'results.s3llout-to-the-man.io', 'expected bucket');
t.equal(result.Key, 'the/whole/key', 'expected key');
t.end();
});
test('fromUrl: bucket-in-host style in cn-north-1', (t) => {
const result = s3Urls.fromUrl('https://bucket.s3.cn-north-1.amazonaws.com.cn/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -100,4 +130,4 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('fromUrl: bucket-in-host style in ap-southeast-1', function(t) {
var result = s3Urls.fromUrl('https://bucket.s3.ap-southeast-1.amazonaws.com/the/whole/key');
test('fromUrl: bucket-in-host style in ap-southeast-1', (t) => {
const result = s3Urls.fromUrl('https://bucket.s3.ap-southeast-1.amazonaws.com/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -108,4 +138,4 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('fromUrl: bucket-in-host dashed in cn-north-1', function(t) {
var result = s3Urls.fromUrl('https://bucket.s3-cn-north-1.amazonaws.com.cn/the/whole/key');
test('fromUrl: bucket-in-host dashed in cn-north-1', (t) => {
const result = s3Urls.fromUrl('https://bucket.s3-cn-north-1.amazonaws.com.cn/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -116,4 +146,4 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('fromUrl: bucket-in-host dashed in ap-southeast-1', function(t) {
var result = s3Urls.fromUrl('https://bucket.s3-ap-southeast-1.amazonaws.com/the/whole/key');
test('fromUrl: bucket-in-host dashed in ap-southeast-1', (t) => {
const result = s3Urls.fromUrl('https://bucket.s3-ap-southeast-1.amazonaws.com/the/whole/key');
t.equal(result.Bucket, 'bucket', 'expected bucket');

@@ -124,4 +154,4 @@ t.equal(result.Key, 'the/whole/key', 'expected key');

test('convert: in-path to s3', function(t) {
var result = s3Urls.convert('https://s3.amazonaws.com/bucket/the/whole/key', 's3');
test('convert: in-path to s3', (t) => {
const result = s3Urls.convert('https://s3.amazonaws.com/bucket/the/whole/key', 's3');
t.equal(result, 's3://bucket/the/whole/key');

@@ -131,3 +161,3 @@ t.end();

test('convert: tileset templates', function(t) {
test('convert: tileset templates', (t) => {
t.equal(s3Urls.convert('https://s3.amazonaws.com/bucket/{z}/{x}/{y}', 's3'), 's3://bucket/{z}/{x}/{y}');

@@ -137,3 +167,3 @@ t.end();

test('valid', function(t) {
test('valid', (t) => {
t.notOk(s3Urls.valid('http://www.google.com'), 'not on s3');

@@ -140,0 +170,0 @@ t.ok(s3Urls.valid('https://s3.amazonaws.com/bucket/the/whole/key'), 'bucket in path');

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc