UNPKG

p5-analysis

Version:

API to find, create, and analyze p5.js sketch files.

41 lines (40 loc) 1.42 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Category = void 0; const fs_1 = __importDefault(require("fs")); const helpers_1 = require("../helpers"); const Library_1 = require("./Library"); class Category { constructor(options) { this.name = options.name || (0, helpers_1.capitalize)(options.key); this.key = options.key; this.description = options.description; this.details = options.details; } static fromProperties(props) { const cat = new Category(props); Category.all.push(cat); return cat; } static load() { JSON.parse(fs_1.default.readFileSync(`${__dirname}/libraries/categories.json`, 'utf-8')) .map(Category.fromProperties) .forEach(cat => { cat.addFromJsonFile(`${__dirname}/libraries/${cat.key}-libraries.json`); }); } addFromJsonFile(jsonPath) { return Library_1.Library.addFromJsonFile(jsonPath, { categoryKey: this.key }); } static findByKey(key) { return Category.all.find(cat => cat.key === key); } get libraries() { return Library_1.Library.all.filter(lib => lib.categoryKey === this.key); } } exports.Category = Category; Category.all = [];