UNPKG

@salesforce/soql-model

Version:
61 lines 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.splitMultiInputValues = void 0; /* * Copyright (c) 2021, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ function splitMultiInputValues(input) { const values = []; // split at comma; for string input, watch out for commas in quotes let isInString = false; let currentValue = ''; let prev = ''; for (let i = 0; i < input.length; i++) { const ch = input.charAt(i); switch (ch) { case "'": { if (isInString) { const isEscaped = prev === '\\'; currentValue += ch; if (!isEscaped) { isInString = false; } } else { if (currentValue.trim().length === 0) { // quote at start of current value isInString = true; } currentValue += ch; } break; } case ',': { if (isInString) { currentValue += ch; } else { if (currentValue.trim().length > 0) { values.push(currentValue.trim()); } currentValue = ''; } break; } default: { currentValue += ch; break; } } if (i === input.length - 1 && currentValue.trim().length > 0) { values.push(currentValue.trim()); } prev = ch; } return values; } exports.splitMultiInputValues = splitMultiInputValues; //# sourceMappingURL=inputUtils.js.map