VICE / ModuleTests / Azure / node_modules / @azure / data-tables / dist-esm / src / odata.js
odata.js
Raw
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
function escapeQuotesIfString(input, previous) {
    let result = input;
    if (typeof input === "string") {
        result = escapeQuotes(input);
        // check if we need to escape this literal
        if (!previous.trim().endsWith("'")) {
            result = `'${result}'`;
        }
    }
    return result;
}
export function escapeQuotes(input) {
    return input.replace(/'/g, "''");
}
/**
 * Escapes an odata filter expression to avoid errors with quoting string literals.
 */
export function odata(strings, ...values) {
    const results = [];
    for (let i = 0; i < strings.length; i++) {
        results.push(strings[i]);
        if (i < values.length) {
            results.push(escapeQuotesIfString(values[i], strings[i]));
        }
    }
    return results.join("");
}
//# sourceMappingURL=odata.js.map