geostyler-sld-parser
Version:
GeoStyler Style Parser implementation for SLD
148 lines (147 loc) • 6.27 kB
TypeScript
import { Expression, PropertyType, GeoStylerFunction, GeoStylerNumberFunction } from 'geostyler-style';
import { SldVersion } from '../SldStyleParser';
/**
* Cast to Number if it is not a GeoStylerFunction
*
* @param exp The GeoStylerExpression
* @returns The value cast to a number or the GeoStylerNumberFunction
*/
export declare function numberExpression(exp: Expression<PropertyType>): GeoStylerNumberFunction | number;
/**
* This converts a GeoStylerFunction or a value (toString) into a fast-xml-parser representation.
* @param value A GeoStylerFunction or a value that will ends as a text.
* @returns a a fast-xml-parser representation of the given value.
*/
export declare function geoStylerFunctionOrTextToSld(value: any): any;
/**
* This converts a GeoStylerFunction into a fast-xml-parser representation
* of a sld function.
*
* @param geostylerFunction A GeoStylerFunction
* @returns
*/
export declare function geoStylerFunctionToSldFunction(geostylerFunction: GeoStylerFunction): any;
/**
* This converts an expected number-like sldElement (text, literal, function a or operator resulting
* in a number) into a geostyler number or number Expression.
* @param sldElement an single objects as created by the fast-xml-parser
* @returns The number, number Expression<number> or undefined.
*/
export declare function sldNumberOperatorOrFunctionOrTextToGeostyler(sldElement: any): number | GeoStylerNumberFunction | undefined;
/**
* This converts the fast-xml-parser representation of a sld function into
* a GeoStylerFunction.
*
* @param sldFunction An array of objects as created by the fast-xml-parser
* @returns The GeoStylerFunction
*/
export declare function sldFunctionToGeoStylerFunction(sldFunction: any[]): GeoStylerFunction;
/**
* Get all child objects with a given tag name.
*
* @param elements An array of objects as created by the fast-xml-parser.
* @param tagName The tagName to get.
* @returns An array of objects as created by the fast-xml-parser.
*/
export declare function getChildren(elements: any[], tagName: string): any[];
/**
* Get the value of a parameter from a specific objects in a list of sld elements.
*
* @param elements An array of objects as created by the fast-xml-parser.
* @param paramKey The name of the parameter to find in the elements.
* @param parameter The parameter name to get.
* @returns The string value of the searched parameter.
*/
export declare function getTextValueInSldObject(elements: any[], parameter: string, paramKey: string): any;
/**
* Get the value of a Css-/SvgParameter.
*
* @param elements An array of objects as created by the fast-xml-parser.
* @param parameter The parameter name to get.
* @param sldVersion The sldVersion to distinguish if CssParameter or SvgParameter is used.
* @returns The string value of the searched parameter.
*/
export declare function getParameterValue(elements: any[], parameter: string, sldVersion: SldVersion): any;
/**
* Get the value of a (GeoServer) VendorOption.
*
* @param elements An array of objects as created by the fast-xml-parser.
* @param name The vendorOption name to get.
* @returns The string value of the searched parameter.
*/
export declare function getVendorOptionValue(elements: any[], name: string): any;
/**
* Get the attribute value of an object.
*
* @param obj The object to check.
* @param name The name of the attribute
* @returns The value of the requested parameter (if available)
*/
export declare function getAttribute(obj: any, name: string): any | undefined;
/**
* Determine if a fast-xml-parser object is a symbolizer representation.
*
* @param obj The object to check.
* @returns Whether the passed object is a symbolizer representation or not.
*/
export declare function isSymbolizer(obj: any): boolean;
/**
* Generic get function which tries to get the nested value of the given object or array.
* It contains some SLD specific handling and tries to be smart but keep the syntax easy.
* It always takes the first child of an array if no index was specified in the path argument.
* e.g.
* Get text value: get(sldSymbolizer, 'Graphic.Mark.WellKnownName.#text')
* Get an attribute value: get(sldSymbolizer, 'Graphic.ExternalGraphic.OnlineResource.@xlink:href')
* Get a Css-/SvgParameter value: get(sldSymbolizer, 'Graphic.Mark.Fill.$fill-opacity', '1.1.0')
* Use with an index: get(sldObject, 'StyledLayerDescriptor.NamedLayer[1].UserStyle.Title.#text')
*
* @param obj A part of the parser result of the fast-xml-parser.
* @param path The path to get the value from.
* @param sldVersion The SLD version to use.
* @returns
*/
export declare function get(obj: any, path: string, sldVersion?: SldVersion): any | undefined;
/**
* Returns the keys of an object where the value is equal to the passed in
* value.
*
* @param object The object to get the key from.
* @param value The value to get the matching key from.
* @return The matching keys.
*/
export declare function keysByValue(object: any, value: any): string[];
/** Split base64 string */
export interface Base64ImageObject {
data: string;
extension: string;
}
/**
* Get the data and extension from a base64 string.
* @returns The data and extension or undefined if the string is not a base64 string.
*/
export declare function getBase64Object(base64String: string): Base64ImageObject | undefined;
/**
* Native replacement for lodash-es.
* https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
*
* @param value The value to check.
* @returns Whether the value is a number or not.
*/
export declare function isNumber(value: unknown): value is number;
/**
* Native replacement for lodash-es.
* https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
*
* @param value The value to check.
* @returns Whether the value is a string or not.
*/
export declare function isString(value: unknown): value is string;
/**
* Native replacement for lodash-es.
* https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
*
* @param target The target object.
* @param source The source object.
* @returns The merged object.
*/
export declare function merge<T extends Record<string, any>, S extends Record<string, any>>(target: T, source: S): T & S;