Specifications of Javascript/Typescript CLPL Parser
These are the constants available:
The current used CLPL parser version
version // ex. '0.1.0'These are the methods available:
Parse the CLPL data into Pairs
- Arguments
- clplData: string - The CLPL data to parse from
-
Return Pairs
-
Usage
parse(clplData)- Example
const pairs = parse("name = 'Bob'")Read from file and parse it as CLPL data into Pairs
- Arguments
- path: PathOrFileDescriptor - The file path or file descriptor
- callback?: (err: Error | null, pairs?: Pairs) -> void - Callback called on finish
- Usage
from(path, callback?)-
Overloads
-
Example
const pairs = await from("config.clpl")Read from file synchronously and parse it as CLPL data into Pairs
- Arguments
- path: PathOrFileDescriptor - The file path or file descriptor
- Usage
fromSync(path)- Example
const pairs = fromSync("config.clpl")Transform Pairs into an Object or Map
- Arguments
- pairs: Pairs - The pairs to transform from
- object?: boolean - Whether to transform to object instead of a map
- transformer?: (pair: Pair) -> unknown? - Custom transformer function to transform pair into value
-
Return Map<string, unknown> | Record<string, unknown>
-
Usage
transform(pairs, object?, transformer?)-
Overloads
-
Example
const map = transform(pairs, false)Generate Pairs from an object
- Arguments
- obj: Map<string, unknown> | Record<string, unknown> - The object for generating to pairs from
- generator?: (value: unknown) -> Pair - Custom generator function for generating pair from value
- stack?: Set<Map<string, unknown> | Record<string, unknown> | unknown[]> - Set of references to prevent circular references
-
Return Pairs
-
Usage
gen(obj, generator?, stack?)- Example
const pairs = gen({ name: "Bob" })Stringify Pairs into clplData
- Arguments
- pairs: Pairs - The pairs to stringify from
- indent?: number - The number of indentation of the clplData, 0 for no indentation, max 6
-
Return string
-
Usage
stringify(pairs, indent?)- Example
const clplData = stringify(pairs, 2)These are the types reserved in the parser:
Representing a group of Pair's
Map<string, Pair>
Representing a value from key-value pair
{ annotations: Annotations, block: Block }
Representing a group of Annotation's
Map<string, Annotation>
Representing an annotation of a value from key-value pair
{ block: Block }
A super type representing type of a value
Type of blocks:
A block representing none type
{ type: 0 }
A block representing a boolean (yes or no) type
{ type: 1, value: boolean }
A block representing a number type
{ type: 2, value: number }
A block representing a text type
{ type: 3, value: string }
A block representing a list type
{ type: 4, value: Pair[] }
A block representing a pairs type
{ type: 5, value: Pairs }
A block representing a bigint type
{ type: 6, value: bigint }
A super type representing type of an annotation value
Type of annotation blocks:
- None Block
- Boolean Block
- Number Block
- Text Block
- AnnotationList Block
- Annotations Block
- BigInt Block
A block representing a list type for annotations
{ type: 4, value: Annotation[] }
A block representing a pairs type for annotations
{ type: 5, value: Annotations }