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

slippy-tile

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slippy-tile - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.nyc_output/033cf587d439d4d47a6094285b3d6c9a.json

7

CHANGELOG.md
# 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`.

24

HEADER.md
[![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
```
"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
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)&lt;[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
"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
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

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