New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mapbox-gl-style-spec

Package Overview
Dependencies
Maintainers
6
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mapbox-gl-style-spec - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

index.js

4

package.json
{
"name": "mapbox-gl-style-spec",
"version": "0.0.0",
"version": "0.0.1",
"description": "a specification for mapbox gl styles",
"main": "reference/latest-style-raw.json",
"main": "index.js",
"bin": {},

@@ -7,0 +7,0 @@ "scripts": {

# mapbox-gl-style-spec
[![Build Status](https://magnum.travis-ci.com/mapbox/mapbox-gl-style-spec.svg?token=6EjGQXFuGMFRr7mgpjEj&branch=reference)](https://magnum.travis-ci.com/mapbox/mapbox-gl-style-spec)
[![Build Status](https://travis-ci.org/mapbox/mapbox-gl-style-spec.svg?branch=master)](https://travis-ci.org/mapbox/mapbox-gl-style-spec)

@@ -5,0 +5,0 @@ [Mapbox GL](https://www.mapbox.com/blog/mapbox-gl/) style specification and

@@ -23,2 +23,4 @@ # gl-style-spec

Styles must have a `layers` property as an **array**.
### Buckets

@@ -25,0 +27,0 @@

@@ -1,20 +0,72 @@

var test = require('tap').test,
fs = require('fs');
var test = require('tap').test;
var spec = require('./');
test('reference', function(t) {
var ref, parsed;
for (var v in spec) test(v, function(t) {
for (var k in spec[v]) {
// Exception for version.
if (k === '$version') {
t.equal(typeof spec[v].$version, 'number', '$version (number)');
} else {
validSchema(k, t, spec[v][k], spec[v]);
}
}
t.end();
});
t.doesNotThrow(function() {
ref = fs.readFileSync('./reference/latest-style-raw.json');
}, 'style exists');
function validSchema(k, t, obj, ref) {
var scalar = ['boolean','string','number'];
var types = Object.keys(ref).concat(['boolean','string','number','array','enum','color','*']);
var keys = [
'default',
'doc',
'function',
'length',
'required',
'transition',
'type',
'value',
'values'
];
t.doesNotThrow(function() {
parsed = JSON.parse(ref);
}, 'can be parsed');
// Schema object.
if (Array.isArray(obj.type) || typeof obj.type === 'string') {
// schema must have only known keys
for (var attr in obj)
t.ok(keys.indexOf(attr) !== -1, k + '.' + attr);
t.doesNotThrow(function() {
require('./');
}, 'can be used as a module');
// schema type must be js native, 'color', or present in ref root object.
t.ok(types.indexOf(obj.type) !== -1, k + '.type (' + obj.type + ')');
t.end();
});
// schema type is an enum, it must have 'values' and they must be scalars.
if (obj.type === 'enum') t.ok(Array.isArray(obj.values) && obj.values.every(function(v) {
return scalar.indexOf(typeof v) !== -1;
}), k + '.values [' + obj.values +']');
// schema type is array, it must have 'value' and it must be a type.
if (obj.value !== undefined)
t.ok(types.indexOf(obj.value) !== -1, k + '.value (' + obj.value + ')');
// schema key type checks
if (obj.doc !== undefined)
t.equal('string', typeof obj.doc, k + '.doc (string)');
if (obj.function !== undefined)
t.equal('boolean', typeof obj.function, k + '.function (boolean)');
if (obj.required !== undefined)
t.equal('boolean', typeof obj.required, k + '.required (boolean)');
if (obj.transition !== undefined)
t.equal('boolean', typeof obj.transition, k + '.transition (boolean)');
// Array of schema objects or references.
} else if (Array.isArray(obj)) {
obj.forEach(function(child, j) {
if (typeof child === 'string' && scalar.indexOf(child) !== -1) return;
validSchema(k + '[' + j + ']', t, typeof child === 'string' ? ref[child] : child, ref);
});
// Container object.
} else if (typeof obj === 'object') {
for (var j in obj) validSchema(k + '.' + j, t, obj[j], ref);
// Invalid ref object.
} else {
t.ok(false, 'Invalid: ' + k);
}
}

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