UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

28 lines (27 loc) 997 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatArrayPath = void 0; const isNumber_js_1 = require("../../../utils/validation/isNumber.js"); const isString_js_1 = require("../../../utils/validation/isString.js"); const charsToEscape = ['[', ']', '.']; const formatArrayPath = (arrayPath) => { let path = ''; let isRoot = true; for (const valuePathPart of arrayPath) { if ((0, isString_js_1.isString)(valuePathPart)) { const shouldBeEscaped = charsToEscape.some(charToEscape => valuePathPart.includes(charToEscape)); if (shouldBeEscaped) { path += `['${valuePathPart}']`; } else { path += `${isRoot ? '' : '.'}${valuePathPart}`; } } if ((0, isNumber_js_1.isNumber)(valuePathPart)) { path += `[${valuePathPart}]`; } isRoot = false; } return path; }; exports.formatArrayPath = formatArrayPath;