Spaces:
Paused
Paused
Download node_modules/@plotly/mapbox-gl/src/style-spec/format.js from Leon4gr45/UserSyncFrontend: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/Leon4gr45/UserSyncFrontend/resolve/main/node_modules/%40plotly/mapbox-gl/src/style-spec/format.js
- Command line
-
hf download hf://spaces/Leon4gr45/UserSyncFrontend/node_modules/@plotly/mapbox-gl/src/style-spec/format.js
-
curl -L -o format.js https://huggingface.co/spaces/Leon4gr45/UserSyncFrontend/resolve/main/node_modules/%40plotly/mapbox-gl/src/style-spec/format.js
1.56 kB
| import reference from './reference/latest.js'; | |
| import stringifyPretty from 'json-stringify-pretty-compact'; | |
| function sortKeysBy(obj, reference) { | |
| const result = {}; | |
| for (const key in reference) { | |
| if (obj[key] !== undefined) { | |
| result[key] = obj[key]; | |
| } | |
| } | |
| for (const key in obj) { | |
| if (result[key] === undefined) { | |
| result[key] = obj[key]; | |
| } | |
| } | |
| return result; | |
| } | |
| /** | |
| * Format a Mapbox GL Style. Returns a stringified style with its keys | |
| * sorted in the same order as the reference style. | |
| * | |
| * The optional `space` argument is passed to | |
| * [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) | |
| * to generate formatted output. | |
| * | |
| * If `space` is unspecified, a default of `2` spaces will be used. | |
| * | |
| * @private | |
| * @param {Object} style a Mapbox GL Style | |
| * @param {number} [space] space argument to pass to `JSON.stringify` | |
| * @returns {string} stringified formatted JSON | |
| * @example | |
| * var fs = require('fs'); | |
| * var format = require('mapbox-gl-style-spec').format; | |
| * var style = fs.readFileSync('./source.json', 'utf8'); | |
| * fs.writeFileSync('./dest.json', format(style)); | |
| * fs.writeFileSync('./dest.min.json', format(style, 0)); | |
| */ | |
| function format(style, space = 2) { | |
| style = sortKeysBy(style, reference.$root); | |
| if (style.layers) { | |
| style.layers = style.layers.map((layer) => sortKeysBy(layer, reference.layer)); | |
| } | |
| return stringifyPretty(style, {indent: space}); | |
| } | |
| export default format; | |