Skip to content

Commit

Permalink
update SldUtil docs
Browse files Browse the repository at this point in the history
Co-authored-by: dnlkoch <[email protected]>
  • Loading branch information
Kai Volland and dnlkoch committed Oct 18, 2022
1 parent 2f821d3 commit 34165ac
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Util/SldUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SldVersion } from '../SldStyleParser';
*
* @param elements An array of objects as created by the fast-xml-parser.
* @param tagName The tagname to get.
* @returns An array of object as created by the fast-xml-parser
* @returns An array of objects as created by the fast-xml-parser.
*/
export function getChildren(elements: any[], tagName: string): any[] {
return elements?.filter(obj => Object.keys(obj).includes(tagName));
Expand All @@ -16,18 +16,18 @@ export function getChildren(elements: any[], tagName: string): any[] {
*
* @param elements An array of objects as created by the fast-xml-parser.
* @param tagName The tagname to get.
* @returns An object as created by the fast-xml-parser
* @returns An object as created by the fast-xml-parser.
*/
export function getChild(elements: any[], tagName: string): any {
return elements?.find(obj => Object.keys(obj).includes(tagName));
}

/**
* Get the value of a Css-/SvgParameter
* 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 SvgParamter is used.
* @param sldVersion The sldVersion to distinguish if CssParameter or SvgParameter is used.
* @returns The string value of the searched parameter.
*/
export function getParameterValue(elements: any[], parameter: string, sldVersion: SldVersion): string | undefined {
Expand All @@ -42,11 +42,11 @@ export function getParameterValue(elements: any[], parameter: string, sldVersion
}

/**
* Get the attribute value of an obj
* Get the attribute value of an object.
*
* @param obj The object to check.
* @paramm name The name of the attribute
* @returns
* @param name The name of the attribute
* @returns The value of the requested parameter (if available)
*/
export function getAttribute(obj: any, name: string): any | undefined {
return obj?.[':@']?.[`@_${name}`];
Expand All @@ -56,14 +56,14 @@ export 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
* @returns Whether the passed object is a symbolizer representation or not.
*/
export function isSymbolizer(obj: any): boolean {
return Object.keys(obj).some(key => key.endsWith('Symbolizer'));
}

/**
* Generic get function which tries to get the nested value of given object or array.
* 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.
Expand All @@ -72,9 +72,9 @@ export function isSymbolizer(obj: any): boolean {
* Get an 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 obj A part of the parser result of the fast-xml-parser.
* @param path The path to get the value from.
* @param sldVersion
* @param sldVersion The SLD version to use.
* @returns
*/
export function get(obj: any, path: string, sldVersion?: SldVersion): any | undefined {
Expand Down

0 comments on commit 34165ac

Please sign in to comment.