UNPKG

genshin-manager

Version:

<div align="center"> <p> <a href="https://www.npmjs.com/package/genshin-manager"><img src="https://img.shields.io/npm/v/genshin-manager.svg?maxAge=3600" alt="npm version" /></a> <a href="https://www.npmjs.com/package/genshin-manager"><img src="https:

37 lines (36 loc) 952 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JsonParser = void 0; /** * Class of json parser */ class JsonParser { /** * Create a JsonParser * @param jsonString Json string */ constructor(jsonString) { this.json = JSON.parse(jsonString); } /** * Get value from json * @param propertyPath Property path * @returns Value */ get(propertyPath) { const properties = propertyPath ? propertyPath.replace(/\]/g, '').split(/\.|\[/) : []; let value = this.json; for (const property of properties) { if (Array.isArray(value)) value = value[+property]; else if (typeof value === 'object' && value != null) value = value[property]; else return undefined; } return value; } } exports.JsonParser = JsonParser;