diff --git a/Readme.md b/Readme.md index d59ac2f..d4ff1d3 100644 --- a/Readme.md +++ b/Readme.md @@ -2,33 +2,35 @@ [![Build Status][build-image]][build-url] [![Dependency Status][deps-image]][deps-url] -# map-style +# @mapwhit/style-loader -Module to process and cache map style +Module to process and cache map style. ## Install ```sh -$ npm install --save map-style +$ npm install --save @mapwhit/style-loader ``` ## Usage +Load map style JSON and convert to an object that handles loading of all artifacts (sprites, sources, tiles, etc.) defined in the style. + ```js -var mapStyle = require('map-style'); +import { styleLoader } from '../lib/style-loader.js'; -mapStyle('Rainbow'); +const style = await styleLoader('https://example.com/style.json', 'network-only'); ``` ## License MIT © [Natalia Kowalczyk](https://melitele.me) -[npm-image]: https://img.shields.io/npm/v/@mapwhit/map-style -[npm-url]: https://npmjs.org/package/@mapwhit/map-style +[npm-image]: https://img.shields.io/npm/v/@mapwhit/style-loader +[npm-url]: https://npmjs.org/package/@mapwhit/style-loader -[build-url]: https://github.com/mapwhit/map-style/actions/workflows/check.yaml -[build-image]: https://img.shields.io/github/actions/workflow/status/mapwhit/map-style/check.yaml?branch=main +[build-url]: https://github.com/mapwhit/style-loader/actions/workflows/check.yaml +[build-image]: https://img.shields.io/github/actions/workflow/status/mapwhit/style-loader/check.yaml?branch=main -[deps-image]: https://img.shields.io/librariesio/release/npm/@mapwhit/map-style -[deps-url]: https://libraries.io/npm/@mapwhit%2Fmap-style +[deps-image]: https://img.shields.io/librariesio/release/npm/@mapwhit/style-loader +[deps-url]: https://libraries.io/npm/@mapwhit%2Fstyle-loader diff --git a/lib/map-style.js b/lib/style-loader.js similarity index 97% rename from lib/map-style.js rename to lib/style-loader.js index 67f56e1..64002f7 100644 --- a/lib/map-style.js +++ b/lib/style-loader.js @@ -5,7 +5,7 @@ import loader from './loader.js'; import { init as initSources, reset as resetSources } from './sources.js'; import { loadSprite, selectSprite } from './sprite.js'; -export async function mapStyle(url, cacheStrategy, options = {}) { +export async function styleLoader(url, cacheStrategy, options = {}) { const load = loader(cacheStrategy, options.cacheStore); const style = await load( { diff --git a/package.json b/package.json index e40f730..cf060b7 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "@mapwhit/map-style", + "name": "@mapwhit/style-loader", "version": "2.0.1", "type": "module", - "exports": "./lib/map-style.js", + "exports": "./lib/style-loader.js", "description": "Module to process and cache map style", "author": { "name": "Natalia Kowalczyk", @@ -11,11 +11,11 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/mapwhit/map-style.git" + "url": "git+https://github.com/mapwhit/style-loader.git" }, "license": "MIT", "keywords": [ - "map-style" + "style-loader" ], "dependencies": { "@mapwhit/style-expressions": "^1.2.0", diff --git a/test/map-style.js b/test/style-loader.js similarity index 75% rename from test/map-style.js rename to test/style-loader.js index 6c82d87..958ba85 100644 --- a/test/map-style.js +++ b/test/style-loader.js @@ -2,10 +2,10 @@ import assert from 'node:assert/strict'; import test from 'node:test'; import { MockAgent, setGlobalDispatcher } from 'undici'; import { initCacheStore } from '../lib/loader.js'; -import { mapStyle } from '../lib/map-style.js'; +import { styleLoader } from '../lib/style-loader.js'; import styleJson from './fixtures/style.json' with { type: 'json' }; -test('map-style', async () => { +test('style-loader', async () => { const agent = new MockAgent(); setGlobalDispatcher(agent); agent @@ -16,12 +16,12 @@ test('map-style', async () => { }) .reply(200, styleJson); - const style = await mapStyle('https://example.com/style.json', 'network-only'); + const style = await styleLoader('https://example.com/style.json', 'network-only'); assert.ok(style); assert.equal(Object.keys(style.sources).length, 3); }); -test('map-style with caching', (_, done) => { +test('style-loader with caching', (_, done) => { initCacheStore({ update: (_, style, type) => { setTimeout(() => { @@ -42,7 +42,7 @@ test('map-style with caching', (_, done) => { }) .reply(200, styleJson); - mapStyle('https://example.com/style.json', 'network-first-then-cache').then(style => { + styleLoader('https://example.com/style.json', 'network-first-then-cache').then(style => { assert.ok(style); }); });