gram_value


gram.js API

Globals / gram-value

Package: gram-value

Evaluate data graph AST values, producing Javascript primitive or object values.

How to gram-value

Install:

npm install @gram-data/gram-value

Build an AST using gram-builder:

import { node, edge } from '@gram-data/gram-builder';

const left = node('a');
const right = node('b');
const ast = edge([left, right], 'right');

Next Steps

Index

References

Interfaces

Type aliases

Variables

Functions

References

LiteralValueEvaluator

Re-exports: LiteralValueEvaluator


ValuePluginSettings

Re-exports: ValuePluginSettings


gramValuePlugin

Re-exports: gramValuePlugin


iso8601Duration

Re-exports: iso8601Duration


iso8601LocalTime

Re-exports: iso8601LocalTime


iso8601OrdinalDate

Re-exports: iso8601OrdinalDate


iso8601Repeat

Re-exports: iso8601Repeat


iso8601Time

Re-exports: iso8601Time


iso8601WeekDate

Re-exports: iso8601WeekDate


iso8601WeekOfYear

Re-exports: iso8601WeekOfYear


iso8601Year

Re-exports: iso8601Year


iso8601YearMonth

Re-exports: iso8601YearMonth


iso8601YearMonthDay

Re-exports: iso8601YearMonthDay


valueOf

Re-exports: valueOf


valueOfBoolean

Re-exports: valueOfBoolean


valueOfDate

Re-exports: valueOfDate


valueOfDecimal

Re-exports: valueOfDecimal


valueOfDuration

Re-exports: valueOfDuration


valueOfHexadecimal

Re-exports: valueOfHexadecimal


valueOfInteger

Re-exports: valueOfInteger


valueOfLiteral

Re-exports: valueOfLiteral


valueOfMeasurement

Re-exports: valueOfMeasurement


valueOfOctal

Re-exports: valueOfOctal


valueOfString

Re-exports: valueOfString


valueOfTaggedLiteral

Re-exports: valueOfTaggedLiteral


valueOfTime

Re-exports: valueOfTime

Type aliases

LiteralValueEvaluator

Ƭ LiteralValueEvaluator: (ast: GramLiteral) => any

Defined in packages/gram-value/src/gram-value.ts:52

Type of function used to evaluate text literal values.

Variables

iso8601Duration

Const iso8601Duration: RegExp = /^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+)S)?)?$/

Defined in packages/gram-value/src/gram-value.ts:36


iso8601LocalTime

Const iso8601LocalTime: RegExp = /^(2[0-3]|[01][0-9]):?([0-5][0-9])(:?([0-5]0-9?))?$/

Defined in packages/gram-value/src/gram-value.ts:33


iso8601OrdinalDate

Const iso8601OrdinalDate: RegExp = /^([0-9]{4})-?(36[0-6]|3[0-5][0-9]|[12][0-9]{2}|0[1-9][0-9]|00[1-9])$/

Defined in packages/gram-value/src/gram-value.ts:30


iso8601Repeat

Const iso8601Repeat: RegExp = /^R(\d*)$/

Defined in packages/gram-value/src/gram-value.ts:37


iso8601Time

Const iso8601Time: RegExp = /^(2[0-3]|[01][0-9]):?([0-5][0-9]):?([0-5]0-9?)?(Z|([+-])((?:2[0-3]|[01][0-9]))(?::?([0-5][0-9]))?)?$/

Defined in packages/gram-value/src/gram-value.ts:35


iso8601WeekDate

Const iso8601WeekDate: RegExp = /^([0-9]{4})-?W(5[0-3]|[1-4][0-9]|0[1-9])-?([1-7])$/

Defined in packages/gram-value/src/gram-value.ts:32


iso8601WeekOfYear

Const iso8601WeekOfYear: RegExp = /^([0-9]{4})-?W(5[0-3]|[1-4][0-9]|0[1-9])$/

Defined in packages/gram-value/src/gram-value.ts:31


iso8601Year

Const iso8601Year: RegExp = /^([+-]\d{4,}\b|\d{4})$/

Defined in packages/gram-value/src/gram-value.ts:27


iso8601YearMonth

Const iso8601YearMonth: RegExp = /^([0-9]{4})-(1[0-2]|0[1-9])$/

Defined in packages/gram-value/src/gram-value.ts:28


iso8601YearMonthDay

Const iso8601YearMonthDay: RegExp = /^([0-9]{4})(-?)(1[0-2]|0[1-9])\2(3[01]|0[1-9]|[12][0-9])$/

Defined in packages/gram-value/src/gram-value.ts:29

Functions

gramValuePlugin

ConstgramValuePlugin(settings: ValuePluginSettings): Transformer

Defined in packages/gram-value/src/gram-value-plugin.ts:17

Parameters:

Name Type
settings ValuePluginSettings

Returns: Transformer


valueOf

ConstvalueOf(recordValue: GramRecordValue | GramRecord, literalValueEvaluator?: valueOfLiteral): any

Defined in packages/gram-value/src/gram-value.ts:60

Evaluates data structures and text literal values, returning native objects and primitive values.

see valueOfLiteral for default literal value evaluator

Parameters:

Name Type Default value
recordValue GramRecordValue | GramRecord -
literalValueEvaluator valueOfLiteral valueOfLiteral

Returns: any


valueOfBoolean

ConstvalueOfBoolean(ast: BooleanLiteral): boolean

Defined in packages/gram-value/src/gram-value.ts:127

Parameters:

Name Type
ast BooleanLiteral

Returns: boolean


valueOfDate

ConstvalueOfDate(ast: DateLiteral): Date

Defined in packages/gram-value/src/gram-value.ts:144

Parameters:

Name Type
ast DateLiteral

Returns: Date


valueOfDecimal

ConstvalueOfDecimal(ast: DecimalLiteral): number

Defined in packages/gram-value/src/gram-value.ts:263

Parameters:

Name Type
ast DecimalLiteral

Returns: number


valueOfDuration

ConstvalueOfDuration(ast: DurationLiteral): Date

Defined in packages/gram-value/src/gram-value.ts:223

Evaluates the duration as a total of milliseconds, unreliably estimating milliseconds per year or month. Reliable duration values can only be calculated with precision of days, hours, minutes or seconds.

Parameters:

Name Type Description
ast DurationLiteral  

Returns: Date


valueOfHexadecimal

ConstvalueOfHexadecimal(ast: HexadecimalLiteral): number

Defined in packages/gram-value/src/gram-value.ts:269

Parameters:

Name Type
ast HexadecimalLiteral

Returns: number


valueOfInteger

ConstvalueOfInteger(ast: IntegerLiteral): number

Defined in packages/gram-value/src/gram-value.ts:251

Parameters:

Name Type
ast IntegerLiteral

Returns: number


valueOfLiteral

ConstvalueOfLiteral(ast: GramLiteral): any

Defined in packages/gram-value/src/gram-value.ts:87

Parameters:

Name Type
ast GramLiteral

Returns: any


valueOfMeasurement

ConstvalueOfMeasurement(ast: MeasurementLiteral): number

Defined in packages/gram-value/src/gram-value.ts:257

Parameters:

Name Type
ast MeasurementLiteral

Returns: number


valueOfOctal

ConstvalueOfOctal(ast: OctalLiteral): number

Defined in packages/gram-value/src/gram-value.ts:275

Parameters:

Name Type
ast OctalLiteral

Returns: number


valueOfString

ConstvalueOfString(ast: StringLiteral): string

Defined in packages/gram-value/src/gram-value.ts:130

Parameters:

Name Type
ast StringLiteral

Returns: string


valueOfTaggedLiteral

ConstvalueOfTaggedLiteral(ast: TaggedTextLiteral): string

Defined in packages/gram-value/src/gram-value.ts:137

Parameters:

Name Type
ast TaggedTextLiteral

Returns: string


valueOfTime

ConstvalueOfTime(ast: TimeLiteral): Date

Defined in packages/gram-value/src/gram-value.ts:183

Value of time as number of milliseconds since midnight.

Parameters:

Name Type Description
ast TimeLiteral  

Returns: Date