webext-schema
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -277,61 +277,2 @@ /** | ||
/** | ||
* arrange schema to fit specific application | ||
* @param {Object} opt - options | ||
* @param {string} opt.name - app name | ||
* @returns {*} - arranged schema | ||
*/ | ||
arrange(opt = {}) { | ||
const {name} = opt; | ||
if (!isString(name)) { | ||
throw new TypeError(`Expected String but got ${getType(name)}.`); | ||
} | ||
const schemas = this._parseSchemaContent(); | ||
let schema; | ||
if (name === "sinon-chrome") { | ||
const items = Object.entries(schemas); | ||
const arr = []; | ||
for (const [key, item] of items) { | ||
const subItems = Object.values(item); | ||
for (const subItem of subItems) { | ||
const schemaItems = Object.entries(subItem); | ||
for (const [schemaKey, schemaKeyValue] of schemaItems) { | ||
if (schemaKey === "namespace") { | ||
const camelizedKey = camelize(key.replace(/\.json$/, "")); | ||
const camelizedSchemaKey = camelize(schemaKeyValue); | ||
if (camelizedKey === camelizedSchemaKey || | ||
camelizedSchemaKey.startsWith(camelizedKey) || | ||
camelizedKey.startsWith(camelizedSchemaKey)) { | ||
arr.push(subItem); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
schema = []; | ||
for (const item of arr) { | ||
const {events, functions, namespace, types} = item; | ||
if (events || functions) { | ||
if (namespace === "menus") { | ||
if (types) { | ||
const menusChild = this.get("menus_child.json"); | ||
const [{functions: menusChildFunctions}] = menusChild; | ||
const contextMenus = Object.assign({}, item); | ||
contextMenus.namespace = "contextMenus"; | ||
contextMenus.permissions = "contextMenus"; | ||
for (const func of menusChildFunctions) { | ||
functions.push(func); | ||
} | ||
schema.push(contextMenus); | ||
schema.push(item); | ||
} | ||
} else { | ||
schema.push(item); | ||
} | ||
} | ||
} | ||
} | ||
return schema || null; | ||
} | ||
/** | ||
* get schema | ||
@@ -338,0 +279,0 @@ * @param {string} name - API name or file name |
@@ -35,6 +35,5 @@ { | ||
"mocha": "^7.0.1", | ||
"nyc": "^15.0.0", | ||
"sinon-chrome": "^3.0.1" | ||
"nyc": "^15.0.0" | ||
}, | ||
"version": "1.0.2" | ||
"version": "1.1.0" | ||
} |
@@ -55,19 +55,2 @@ [![Build Status](https://travis-ci.org/asamuzaK/webext-schema.svg?branch=master)](https://travis-ci.org/asamuzaK/webext-schema) | ||
### schema.arrange(<var>opt</var>) | ||
* @param {Object} opt - options | ||
* @param {string} opt.name - application name | ||
* @returns {*} - arranged schema | ||
Get the arranged schema for the specific application. | ||
Supported applications: | ||
* [sinon-chrome](https://www.npmjs.com/package/sinon-chrome) | ||
``` | ||
const schema = new Schema().arrange({name: "sinon-chrome"}); | ||
// [{namespace: "alarms", functions: [{...}], ...}]; | ||
``` | ||
### schema.get(<var>name</var>) | ||
@@ -74,0 +57,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
2403570
67812
129