UNPKG

@salesforce/core

Version:

Core libraries to interact with SFDX projects, orgs, and APIs.

59 lines 2.36 kB
"use strict"; /* * Copyright (c) 2020, 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.matchesAccessToken = exports.sfdxAuthUrlRegex = exports.accessTokenRegex = exports.validatePathDoesNotContainInvalidChars = exports.validateSalesforceId = exports.validateEmail = exports.validateApiVersion = void 0; exports.trimTo15 = trimTo15; function trimTo15(id) { if (!id) { return undefined; } if (id.length && id.length > 15) { return id.substring(0, 15); } return id; } /** * Tests whether an API version matches the format `i.0`. * * @param value The API version as a string. */ const validateApiVersion = (value) => value == null || /^[1-9]\d\.0$/.test(value); exports.validateApiVersion = validateApiVersion; /** * Tests whether an email matches the format `me@my.org` * * @param value The email as a string. */ const validateEmail = (value) => /^[^.][^@]*@[^.]+(\.[^.\s]+)+$/.test(value); exports.validateEmail = validateEmail; /** * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers * * @param value The ID as a string. */ const validateSalesforceId = (value) => /[a-zA-Z0-9]{18}|[a-zA-Z0-9]{15}/.test(value) && (value.length === 15 || value.length === 18); exports.validateSalesforceId = validateSalesforceId; /** * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|" * * @param value The path as a string. */ const validatePathDoesNotContainInvalidChars = (value) => // eslint-disable-next-line no-useless-escape !/[\["\?<>\|\]]+/.test(value); exports.validatePathDoesNotContainInvalidChars = validatePathDoesNotContainInvalidChars; exports.accessTokenRegex = /(00D\w{12,15})![.\w]*/; exports.sfdxAuthUrlRegex = /force:\/\/([a-zA-Z0-9._-]+):([a-zA-Z0-9._-]*):([a-zA-Z0-9._-]+={0,2})@([a-zA-Z0-9._-]+)/; /** * Tests whether a given string is an access token * * @param value */ const matchesAccessToken = (value) => exports.accessTokenRegex.test(value); exports.matchesAccessToken = matchesAccessToken; //# sourceMappingURL=sfdc.js.map