UNPKG

@aws-lambda-powertools/jmespath

Version:

A type safe and modern jmespath module to parse and extract data from JSON documents using JMESPath

97 lines (96 loc) 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WHITESPACE = exports.VALID_NUMBER = exports.VALID_IDENTIFIER = exports.START_IDENTIFIER = exports.SIMPLE_TOKENS = exports.BINDING_POWER = void 0; /** * The binding powers for the various tokens in the JMESPath grammar. * * The binding powers are used to determine the order of operations for * the parser. The higher the binding power, the more tightly the token * binds to its arguments. */ const BINDING_POWER = { eof: 0, unquoted_identifier: 0, quoted_identifier: 0, literal: 0, rbracket: 0, rparen: 0, comma: 0, rbrace: 0, number: 0, current: 0, expref: 0, colon: 0, pipe: 1, or: 2, and: 3, eq: 5, gt: 5, lt: 5, gte: 5, lte: 5, ne: 5, flatten: 9, // Everything above stops a projection. star: 20, filter: 21, dot: 40, not: 45, lbrace: 50, lbracket: 55, lparen: 60, }; exports.BINDING_POWER = BINDING_POWER; /** * The set of ASCII lowercase letters allowed in JMESPath identifiers. */ const ASCII_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz'; /** * The set of ASCII uppercase letters allowed in JMESPath identifiers. */ const ASCII_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; /** * The set of ASCII letters allowed in JMESPath identifiers. */ const ASCII_LETTERS = ASCII_LOWERCASE + ASCII_UPPERCASE; /** * The set of ASCII digits allowed in JMESPath identifiers. */ const DIGITS = '0123456789'; /** * The set of ASCII letters and digits allowed in JMESPath identifiers. */ const START_IDENTIFIER = new Set(`${ASCII_LETTERS}_`); exports.START_IDENTIFIER = START_IDENTIFIER; /** * The set of ASCII letters and digits allowed in JMESPath identifiers. */ const VALID_IDENTIFIER = new Set(`${ASCII_LETTERS}${DIGITS}_`); exports.VALID_IDENTIFIER = VALID_IDENTIFIER; /** * The set of ASCII digits allowed in JMESPath identifiers. */ const VALID_NUMBER = new Set(DIGITS); exports.VALID_NUMBER = VALID_NUMBER; /** * The set of ASCII whitespace characters allowed in JMESPath identifiers. */ const WHITESPACE = new Set(' \t\n\r'); exports.WHITESPACE = WHITESPACE; /** * The set of simple tokens in the JMESPath grammar. */ const SIMPLE_TOKENS = new Map([ ['.', 'dot'], ['*', 'star'], [':', 'colon'], [']', 'rbracket'], [',', 'comma'], [':', 'colon'], ['@', 'current'], ['(', 'lparen'], [')', 'rparen'], ['{', 'lbrace'], ['}', 'rbrace'], ]); exports.SIMPLE_TOKENS = SIMPLE_TOKENS;