slippy-tile
Advanced tools
Comparing version 1.0.0 to 1.1.0
# Changelog | ||
## 1.1.0 - 2016-10-14 | ||
- Changed default function to `url` | ||
- Added `download` feature | ||
- Fallbacks, request-promise dependency for downloading Tile data Buffer | ||
- Update docs | ||
## 1.0.0 - 2016-10-13 | ||
First Stable release of `slippy-tile`. |
[![Build Status](https://travis-ci.org/DenisCarriere/slippy-tile.svg?branch=master)](https://travis-ci.org/DenisCarriere/slippy-tile) | ||
[![Coverage Status](https://coveralls.io/repos/github/DenisCarriere/slippy-tile/badge.svg?branch=master)](https://coveralls.io/github/DenisCarriere/slippy-tile?branch=master) | ||
[![npm version](https://badge.fury.io/js/slippy-tile.svg)](https://badge.fury.io/js/slippy-tile) | ||
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/DenisCarriere/slippy-tile/master/LICENSE) | ||
# Slippy Tile (ES6 Module) | ||
# Slippy Tile | ||
@@ -18,6 +19,6 @@ Slippy Tile helps parse a Tile scheme URL from a given Tile [x, y, zoom]. | ||
```javascript | ||
import slippyTile, { Tile } from 'slippy-tile' | ||
import * as slippyTile from 'slippy-tile' | ||
const tile: Tile = [10, 15, 8] // x, y, zoom | ||
const url = slippyTile(tile, 'osm') | ||
const tile = [10, 15, 8] // x, y, zoom | ||
const url = slippyTile.url(tile, 'osm') | ||
//= https://b.tile.openstreetmap.org/8/10/15.png | ||
@@ -51,4 +52,3 @@ ``` | ||
const scheme = 'https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png' | ||
const tile: Tile = [10, 15, 8] // x, y, zoom | ||
const url = slippyTile(tile, scheme) | ||
const url = slippyTile.url([10, 15, 8], scheme) | ||
//= https://b.tile.openstreetmap.org/8/10/15.png | ||
@@ -69,13 +69,1 @@ ``` | ||
- `{proj}`: default = EPSG:3857 | ||
## Tests | ||
```bash | ||
$ npm test | ||
``` | ||
## Documentation | ||
```bash | ||
$ npm run docs | ||
``` |
53
index.js
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments)).next()); | ||
}); | ||
}; | ||
const mercator = require('global-mercator'); | ||
exports.providers = require('./providers'); | ||
const rp = require('request-promise'); | ||
const path = require('path'); | ||
exports.providers = require(path.join(__dirname, 'utils', 'providers.json')); | ||
/** | ||
@@ -11,8 +21,6 @@ * Substitutes the given tile information [x,y,zoom] to the URL tile scheme. | ||
* @example | ||
* const tile = [10, 15, 8] | ||
* const scheme = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
* const url = slippyTile(tile, scheme) | ||
* //=url | ||
* const url = slippyTile.url([10, 15, 8], 'osm') | ||
* //='https://c.tile.openstreetmap.org/8/10/15.png' | ||
*/ | ||
function slippyTile(tile, scheme) { | ||
function url(tile, scheme) { | ||
const [x, y, zoom] = tile; | ||
@@ -38,4 +46,21 @@ let url = providerLookup(scheme); | ||
} | ||
exports.slippyTile = slippyTile; | ||
exports.url = url; | ||
/** | ||
* Downloads Tile | ||
* | ||
* @param {Tile} tile Tile [x, y, zoom] | ||
* @param {string} scheme Tile scheme URL or provider unique key | ||
* @returns {Promise<Buffer>} tile buffer | ||
* @example | ||
* const url = slippyTile.url([10, 15, 8], 'osm') | ||
* //='https://c.tile.openstreetmap.org/8/10/15.png' | ||
*/ | ||
function download(tile, scheme) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return rp.get(url(tile, scheme), { encoding: 'binary' }) | ||
.then(data => new Buffer(data, 'binary')); | ||
}); | ||
} | ||
exports.download = download; | ||
/** | ||
* Replaces {switch:a,b,c} with a random sample. | ||
@@ -46,5 +71,5 @@ * | ||
* @example | ||
* url = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
* const url = parseSwitch(url) | ||
* //=url | ||
* const scheme = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
* const url = slippyTile.parseSwitch(scheme) | ||
* //='http://tile-b.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
*/ | ||
@@ -67,4 +92,4 @@ function parseSwitch(url) { | ||
* @example | ||
* const scheme = providerLookup('bing') | ||
* //=scheme | ||
* const scheme = slippyTile.providerLookup('bing') | ||
* //='http://ecn.t{switch:0,1,2,3}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=5250' | ||
*/ | ||
@@ -86,3 +111,3 @@ function providerLookup(provider) { | ||
* const item = sample(['a', 'b', 'c']) | ||
* //=item | ||
* //='a' | ||
*/ | ||
@@ -93,4 +118,2 @@ function sample(collection) { | ||
exports.sample = sample; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = slippyTile; | ||
//# sourceMappingURL=index.js.map |
42
index.ts
import * as mercator from 'global-mercator' | ||
import * as rp from 'request-promise' | ||
import * as path from 'path' | ||
export const providers: Providers = require('./providers') | ||
export const providers: Providers = require(path.join(__dirname, 'utils', 'providers.json')) | ||
@@ -33,8 +35,6 @@ /** | ||
* @example | ||
* const tile = [10, 15, 8] | ||
* const scheme = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
* const url = slippyTile(tile, scheme) | ||
* //=url | ||
* const url = slippyTile.url([10, 15, 8], 'osm') | ||
* //='https://c.tile.openstreetmap.org/8/10/15.png' | ||
*/ | ||
export function slippyTile(tile: Tile, scheme: string) { | ||
export function url(tile: Tile, scheme: string) { | ||
const [x, y, zoom] = tile | ||
@@ -52,3 +52,2 @@ let url = providerLookup(scheme) | ||
url = parseSwitch(url) | ||
return url | ||
@@ -58,2 +57,17 @@ } | ||
/** | ||
* Downloads Tile | ||
* | ||
* @param {Tile} tile Tile [x, y, zoom] | ||
* @param {string} scheme Tile scheme URL or provider unique key | ||
* @returns {Promise<Buffer>} tile buffer | ||
* @example | ||
* const url = slippyTile.url([10, 15, 8], 'osm') | ||
* //='https://c.tile.openstreetmap.org/8/10/15.png' | ||
*/ | ||
export async function download(tile: Tile, scheme: string): Promise<Buffer> { | ||
return rp.get(url(tile, scheme), { encoding : 'binary' }) | ||
.then(data => new Buffer(data, 'binary')) | ||
} | ||
/** | ||
* Replaces {switch:a,b,c} with a random sample. | ||
@@ -64,5 +78,5 @@ * | ||
* @example | ||
* url = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
* const url = parseSwitch(url) | ||
* //=url | ||
* const scheme = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
* const url = slippyTile.parseSwitch(scheme) | ||
* //='http://tile-b.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
*/ | ||
@@ -85,4 +99,4 @@ export function parseSwitch (url: string) { | ||
* @example | ||
* const scheme = providerLookup('bing') | ||
* //=scheme | ||
* const scheme = slippyTile.providerLookup('bing') | ||
* //='http://ecn.t{switch:0,1,2,3}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=5250' | ||
*/ | ||
@@ -104,3 +118,3 @@ export function providerLookup(provider: string) { | ||
* const item = sample(['a', 'b', 'c']) | ||
* //=item | ||
* //='a' | ||
*/ | ||
@@ -110,3 +124,1 @@ export function sample(collection: Array<string | number>): string | number { | ||
} | ||
export default slippyTile |
{ | ||
"name": "slippy-tile", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Helps convert Slippy Map url tile schemas", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"build": "tsc && js-yaml providers.yml", | ||
"test": "tsc && nyc ava && npm run lint", | ||
"test": "tsc && npm run lint && nyc ava", | ||
"docs": "tsc && cat HEADER.md > README.md && documentation build index.js -c documentation.yml -f md >> README.md", | ||
@@ -28,3 +28,5 @@ "lint": "tsc && tslint index.ts test.ts && documentation lint index.js" | ||
"devDependencies": { | ||
"@types/bluebird": "^3.0.35", | ||
"@types/node": "^6.0.45", | ||
"@types/request-promise": "^3.0.32", | ||
"ava": "^0.16.0", | ||
@@ -58,4 +60,8 @@ "coveralls": "^2.11.14", | ||
"dependencies": { | ||
"global-mercator": "^1.2.3" | ||
"@types/request": "^0.0.31", | ||
"bluebird": "^3.4.6", | ||
"global-mercator": "^1.2.3", | ||
"request": "^2.75.0", | ||
"request-promise": "^4.1.1" | ||
} | ||
} |
[![Build Status](https://travis-ci.org/DenisCarriere/slippy-tile.svg?branch=master)](https://travis-ci.org/DenisCarriere/slippy-tile) | ||
[![Coverage Status](https://coveralls.io/repos/github/DenisCarriere/slippy-tile/badge.svg?branch=master)](https://coveralls.io/github/DenisCarriere/slippy-tile?branch=master) | ||
[![npm version](https://badge.fury.io/js/slippy-tile.svg)](https://badge.fury.io/js/slippy-tile) | ||
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/DenisCarriere/slippy-tile/master/LICENSE) | ||
# Slippy Tile (ES6 Module) | ||
# Slippy Tile | ||
@@ -18,6 +19,6 @@ Slippy Tile helps parse a Tile scheme URL from a given Tile [x, y, zoom]. | ||
```javascript | ||
import slippyTile, { Tile } from 'slippy-tile' | ||
import * as slippyTile from 'slippy-tile' | ||
const tile: Tile = [10, 15, 8] // x, y, zoom | ||
const url = slippyTile(tile, 'osm') | ||
const tile = [10, 15, 8] // x, y, zoom | ||
const url = slippyTile.url(tile, 'osm') | ||
//= https://b.tile.openstreetmap.org/8/10/15.png | ||
@@ -51,4 +52,3 @@ ``` | ||
const scheme = 'https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png' | ||
const tile: Tile = [10, 15, 8] // x, y, zoom | ||
const url = slippyTile(tile, scheme) | ||
const url = slippyTile.url([10, 15, 8], scheme) | ||
//= https://b.tile.openstreetmap.org/8/10/15.png | ||
@@ -69,18 +69,24 @@ ``` | ||
- `{proj}`: default = EPSG:3857 | ||
# url | ||
## Tests | ||
Substitutes the given tile information [x,y,zoom] to the URL tile scheme. | ||
```bash | ||
$ npm test | ||
``` | ||
**Parameters** | ||
## Documentation | ||
- `tile` **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** Tile [x, y, zoom] | ||
- `scheme` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Tile scheme URL or provider unique key | ||
```bash | ||
$ npm run docs | ||
**Examples** | ||
```javascript | ||
const url = slippyTile.url([10, 15, 8], 'osm') | ||
//='https://c.tile.openstreetmap.org/8/10/15.png' | ||
``` | ||
# slippyTile | ||
Substitutes the given tile information [x,y,zoom] to the URL tile scheme. | ||
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
# download | ||
Downloads Tile | ||
**Parameters** | ||
@@ -94,9 +100,7 @@ | ||
```javascript | ||
const tile = [10, 15, 8] | ||
const scheme = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
const url = slippyTile(tile, scheme) | ||
//=url | ||
const url = slippyTile.url([10, 15, 8], 'osm') | ||
//='https://c.tile.openstreetmap.org/8/10/15.png' | ||
``` | ||
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** tile buffer | ||
@@ -114,5 +118,5 @@ # parseSwitch | ||
```javascript | ||
url = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
const url = parseSwitch(url) | ||
//=url | ||
const scheme = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
const url = slippyTile.parseSwitch(scheme) | ||
//='http://tile-b.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
``` | ||
@@ -133,4 +137,4 @@ | ||
```javascript | ||
const scheme = providerLookup('bing') | ||
//=scheme | ||
const scheme = slippyTile.providerLookup('bing') | ||
//='http://ecn.t{switch:0,1,2,3}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=5250' | ||
``` | ||
@@ -152,5 +156,5 @@ | ||
const item = sample(['a', 'b', 'c']) | ||
//=item | ||
//='a' | ||
``` | ||
Returns **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))** Single item from the list |
26
test.js
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments)).next()); | ||
}); | ||
}; | ||
const ava_1 = require('ava'); | ||
const index_1 = require('./index'); | ||
ava_1.default('slippy tile', t => { | ||
const slippyTile = require('./index'); | ||
ava_1.default('url', t => { | ||
const scheme = 'https://tile.openstreetmap.org/{zoom}/{x}/{y}.png'; | ||
const tile = [10, 15, 8]; // x, y, zoom | ||
const url = index_1.default(tile, scheme); | ||
const tile = [10, 15, 8]; | ||
const url = slippyTile.url(tile, scheme); | ||
t.deepEqual(url, 'https://tile.openstreetmap.org/8/10/15.png'); | ||
}); | ||
ava_1.default('providers', t => { | ||
const tile = [10, 15, 8]; | ||
const url = slippyTile.url(tile, 'osm'); | ||
t.true(!!url); | ||
}); | ||
ava_1.default('download', (t) => __awaiter(this, void 0, void 0, function* () { | ||
const tile = [10, 15, 8]; | ||
const buffer = yield slippyTile.download(tile, 'osm'); | ||
t.true(!!buffer); | ||
})); | ||
//# sourceMappingURL=test.js.map |
21
test.ts
import test from 'ava' | ||
import slippyTile, { Tile } from './index' | ||
import * as slippyTile from './index' | ||
import { Tile } from './index' | ||
test('slippy tile', t => { | ||
test('url', t => { | ||
const scheme = 'https://tile.openstreetmap.org/{zoom}/{x}/{y}.png' | ||
const tile: Tile = [10, 15, 8] // x, y, zoom | ||
const url = slippyTile(tile, scheme) | ||
const tile: Tile = [10, 15, 8] | ||
const url = slippyTile.url(tile, scheme) | ||
t.deepEqual(url, 'https://tile.openstreetmap.org/8/10/15.png') | ||
}) | ||
test('providers', t => { | ||
const tile: Tile = [10, 15, 8] | ||
const url = slippyTile.url(tile, 'osm') | ||
t.true(!!url) | ||
}) | ||
test('download', async t => { | ||
const tile: Tile = [10, 15, 8] | ||
const buffer = await slippyTile.download(tile, 'osm') | ||
t.true(!!buffer) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
194355
430
154
5
9
1
+ Added@types/request@^0.0.31
+ Addedbluebird@^3.4.6
+ Addedrequest@^2.75.0
+ Addedrequest-promise@^4.1.1
+ Added@types/form-data@2.5.2(transitive)
+ Added@types/node@22.10.7(transitive)
+ Added@types/request@0.0.31(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbluebird@3.7.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.34.0.1(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedrequest-promise@4.2.6(transitive)
+ Addedrequest-promise-core@1.1.4(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstealthy-require@1.1.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)