UNPKG

@rnaga/wp-node

Version:

👉 **[View Full Documentation at rnaga.github.io/wp-node →](https://rnaga.github.io/wp-node/)**

53 lines (52 loc) • 2.4 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TaxonomyUtil = void 0; const component_1 = require("../../decorators/component"); const components_1 = require("../components"); const options_1 = require("../options"); const taxonomy_1 = require("../taxonomy"); const config_1 = require("../../config"); let TaxonomyUtil = class TaxonomyUtil { components; config; constructor(components, config) { this.components = components; this.config = config; } async get(key) { return this.components.asyncGet(taxonomy_1.Taxonomy, [key]); } async getDefaultTerm(taxonomy) { const options = this.components.get(options_1.Options); const key = taxonomy == "category" ? "default_category" : `default_term_${taxonomy}`; const result = await options.get(key); return result ? parseInt(result) : 0; } async isHierarchical(taxonomyName) { const taxonomy = await this.get(taxonomyName); return taxonomy.props?.hierarchical ?? false; } async getList(args = { objectType: "post" }) { const taxonomies = []; for (const [taxonomyName, config] of Object.entries(this.config.config.taxonomy.settings)) { if (config.objectType === args.objectType) { taxonomies.push(await this.get(taxonomyName)); } } return taxonomies; } }; exports.TaxonomyUtil = TaxonomyUtil; exports.TaxonomyUtil = TaxonomyUtil = __decorate([ (0, component_1.component)(), __metadata("design:paramtypes", [components_1.Components, config_1.Config]) ], TaxonomyUtil);