mapbox-gl-style-spec
Advanced tools
Comparing version 0.0.0 to 0.0.1
{ | ||
"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 @@ |
82
test.js
@@ -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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
15307
7
580
1
2