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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 118x 118x 101x 101x 83x 68x 68x 83x 101x 2x 2x 2x 101x 116x 116x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 1x | /**
* Copyright © 2020 2021 2022 7thCode.(http://seventh-code.com/)
* This software is released under the MIT License.
* opensource.org/licenses/mit-license.php
*/
"use strict";
import {AttributeParser, FormulaParser} from './parser';
import {ParserStream} from './stream';
import {BaseHandler, Updater, ValueHandler} from './handler';
export {AttributeParser, FormulaParser, ParserStream, BaseHandler, ValueHandler};
/**
* AttrPath
*/
export class AttrPath {
/**
* traverse
*
* @remarks
* Traverse an object's attributes to get its value.
*
* @param target - Object
* @param path - ObjectPath e.g. ".x.Y.z[1]"
* @param default_value - The value to return if there is no corresponding value in the object path. default is "undefined"
* @returns The value at the position of the path.
*
*/
static traverse(target: any, path: string, default_value: any = undefined): any {
let result = default_value;
if (target) {
const handler: ValueHandler = new ValueHandler(target);
if (new AttributeParser(handler, new ParserStream(path)).parse_path()) {
if (handler.value) {
result = handler.value;
}
}
if (default_value && typeof default_value === 'function') {
default_value(result);
return null;
}
}
return result;
}
static update(target: any, path: string, value: any): boolean {
let result: boolean = false;
if (target) {
const updater: Updater = new Updater(target, value);
if (new AttributeParser(updater, new ParserStream(path)).parse_path()) {
result = (updater.value);
}
}
return result;
}
/**
* is_valid
*
* @remarks
* Is the path grammatically correct?
*
* @param path - ObjectPath e.g. ".x.Y.z[1]"
* @returns true/false
*
*/
static is_valid(path: string): boolean {
return new AttributeParser(null, new ParserStream(path)).parse_path();
}
}
|