Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 4x 345x 345x 117x 593x 345x 345x 4x 340x 340x 340x 340x 4x | /* eslint-disable no-param-reassign */
export default function configure(sigma) {
/**
* Takes a package name as parameter and checks at each lebel if it exists,
* and if it does not, creates it.
*
* Example:
* ********
* > pkg('a.b.c');
* > a.b.c;
* > // Object {};
* >
* > pkg('a.b.d');
* > a.b;
* > // Object { c: {}, d: {} };
*
* @param {string} pkgName The name of the package to create/find.
* @return {object} The related package.
*/
function getPackageObject(pkgName: string) {
const getPackage = (levels: string[], root: { [key: string]: any }) => {
return levels.reduce((context, objName) => {
if (!context[objName]) {
context[objName] = {};
}
return context[objName];
}, root);
};
const levels = (pkgName || "").split(".");
if (levels[0] === "sigma") {
return getPackage(levels.slice(1), sigma);
}
return getPackage(levels, sigma.packages);
}
sigma.register = (packageName: string, item: any) => {
const parentPath = packageName.substring(0, packageName.lastIndexOf("."));
const itemName = packageName.substring(packageName.lastIndexOf(".") + 1);
const pkg = getPackageObject(parentPath);
pkg[itemName] = pkg[itemName] || item;
};
sigma.register("sigma.utils.pkg", getPackageObject);
}
|