UNPKG

@esri/solution-common

Version:

Provides general helper functions for @esri/solution.js.

115 lines 4.29 kB
"use strict"; /** @license * Copyright 2020 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Provides connectors to third-party helper functions. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.validateHTML = exports.sanitizeURLProtocol = exports.sanitizeJSON = exports.sanitizeHTML = exports.createZip = exports.Sanitizer = void 0; const tslib_1 = require("tslib"); const jszip_1 = tslib_1.__importDefault(require("jszip")); const generalHelpers_1 = require("./generalHelpers"); const arcgis_html_sanitizer_1 = require("@esri/arcgis-html-sanitizer"); var arcgis_html_sanitizer_2 = require("@esri/arcgis-html-sanitizer"); Object.defineProperty(exports, "Sanitizer", { enumerable: true, get: function () { return arcgis_html_sanitizer_2.Sanitizer; } }); //#region JSZip ----------------------------------------------------------------------------------------------------- // /** * Creates a zip File from a collection of Files. * * @param zipFilename Name to use for zip File * @param files List of files to add to zip File * @param folder Folder to contain the files * @returns Promise resolving to a zip File */ function createZip(zipFilename, files, folder) { return new Promise((resolve, reject) => { const zip = new jszip_1.default(); let container = zip; if (folder) { container = zip.folder(folder); } // Add the files files.forEach((file) => container.file(file.name, file, { binary: true })); // Create the ZIP zip .generateAsync({ type: "blob" }) .then((content) => resolve((0, generalHelpers_1.blobToFile)(content, zipFilename, "application/zip")), reject); }); } exports.createZip = createZip; /** * Sanitizes html. * * @param HTML Text to sanitize * @param sanitizer Instance of Sanitizer class * @returns Sanitized version of `html` * @see https://github.com/esri/arcgis-html-sanitizer#basic-usage */ function sanitizeHTML(html, sanitizer) { if (!sanitizer) { sanitizer = new arcgis_html_sanitizer_1.Sanitizer(); } return sanitizer.sanitize(html); } exports.sanitizeHTML = sanitizeHTML; /** * Sanitizes JSON. * * @param json JSON to sanitize * @param sanitizer Instance of Sanitizer class * @returns Sanitized version of `json` * @see https://github.com/esri/arcgis-html-sanitizer#sanitize-json */ function sanitizeJSON(json, sanitizer) { if (!sanitizer) { sanitizer = new arcgis_html_sanitizer_1.Sanitizer(); } return sanitizer.sanitize(json); } exports.sanitizeJSON = sanitizeJSON; /** * Sanitizes the protocol in a URL. * * @param url URL to sanitize * @param sanitizer Instance of Sanitizer class * @returns Sanitized version of `url` * @see https://github.com/esri/arcgis-html-sanitizer#sanitize-urls */ function sanitizeURLProtocol(url, sanitizer) { if (!sanitizer) { sanitizer = new arcgis_html_sanitizer_1.Sanitizer(); } return sanitizer.sanitizeUrl(url); } exports.sanitizeURLProtocol = sanitizeURLProtocol; /** * Checks if a string contains invalid HTML. * * @param html HTML to check * @param sanitizer Instance of Sanitizer class * @returns An object containing a flag indicating if `html` is valid (i.e., contains no invalid HTML) * as well as the sanitized version of `html` * @see https://github.com/esri/arcgis-html-sanitizer#basic-usage */ function validateHTML(html, sanitizer) { if (!sanitizer) { sanitizer = new arcgis_html_sanitizer_1.Sanitizer(); } return sanitizer.validate(html); } exports.validateHTML = validateHTML; //#endregion ---------------------------------------------------------------------------------------------------------// //# sourceMappingURL=libConnectors.js.map