UNPKG

@aws-lambda-powertools/jmespath

Version:

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

87 lines 4.43 kB
/** * Check if a value is truthy. * * In JavaScript, zero is falsy while all other non-zero numbers are truthy. * In JMESPath however, zero is truthy as well as all other non-zero numbers. For * this reason we wrap the original isTruthy function from the commons package * and add a check for numbers. * * @param value The value to check */ declare const isTruthy: (value: unknown) => boolean; /** * Given a start, stop, and step value, the sub elements in an array are extracted as follows: * * The first element in the extracted array is the index denoted by start. * * The last element in the extracted array is the index denoted by end - 1. * * The step value determines how many indices to skip after each element is selected from the array. An array of 1 (the default step) will not skip any indices. A step value of 2 will skip every other index while extracting elements from an array. A step value of -1 will extract values in reverse order from the array. * * Slice expressions adhere to the following rules: * * If a negative start position is given, it is calculated as the total length of the array plus the given start position. * * If no start position is given, it is assumed to be 0 if the given step is greater than 0 or the end of the array if the given step is less than 0. * * If a negative stop position is given, it is calculated as the total length of the array plus the given stop position. * * If no stop position is given, it is assumed to be the length of the array if the given step is greater than 0 or 0 if the given step is less than 0. * * If the given step is omitted, it it assumed to be 1. * * If the given step is 0, an invalid-value error MUST be raised (thrown before calling the function) * * If the element being sliced is not an array, the result is null (returned before calling the function) * * If the element being sliced is an array and yields no results, the result MUST be an empty array. * * @param array The array to slice * @param start The start index * @param end The end index * @param step The step value */ declare const sliceArray: <T>({ array, start, end, step, }: { array: T[]; start?: number; end?: number; step: number; }) => T[] | null; /** * Checks if the number of arguments passed to a function matches the expected arity. * If the number of arguments does not match the expected arity, an ArityError is thrown. * * If the function is variadic, then the number of arguments passed to the function must be * greater than or equal to the expected arity. If the number of arguments passed to the function * is less than the expected arity, a `VariadicArityError` is thrown. * * @param args The arguments passed to the function * @param argumentsSpecs The expected types for each argument * @param decoratedFuncName The name of the function being called * @param variadic Whether the function is variadic */ declare const arityCheck: (args: unknown[], argumentsSpecs: Array<Array<string>>, variadic?: boolean) => void; /** * Type checks the arguments passed to a function against the expected types. * * Type checking at runtime involves checking the top level type, * and in the case of arrays, potentially checking the types of * the elements in the array. * * If the list of types includes 'any', then the type check is a * no-op. * * If the list of types includes more than one type, then the * argument is checked against each type in the list. If the * argument matches any of the types, then the type check * passes. If the argument does not match any of the types, then * a JMESPathTypeError is thrown. * * @param args The arguments passed to the function * @param argumentsSpecs The expected types for each argument */ declare const typeCheck: (args: unknown[], argumentsSpecs: Array<Array<string>>) => void; /** * Type checks an argument against a list of types. * * If the list of types includes more than one type, then the * argument is checked against each type in the list. If the * argument matches any of the types, then the type check * passes. If the argument does not match any of the types, then * a JMESPathTypeError is thrown. * * @param arg * @param argumentSpec */ declare const typeCheckArgument: (arg: unknown, argumentSpec: Array<string>) => void; export { isTruthy, arityCheck, sliceArray, typeCheck, typeCheckArgument }; //# sourceMappingURL=utils.d.ts.map