one
Version:
One is a React framework for web, iOS, and Android apps.
55 lines (53 loc) • 2.22 kB
JavaScript
function assertSetStringText(text) {
if (typeof text !== "string") {
throw new Error("Clipboard.setString: text must be a string");
}
}
function assertSetStringOptions(options, verb) {
if (options === void 0) return;
if (!options || typeof options !== "object") {
throw new Error(`Clipboard.${verb}: options must be an object`);
}
if (options.inputFormat !== void 0 && options.inputFormat !== "plainText" && options.inputFormat !== "html") {
throw new Error(`Clipboard.${verb}: inputFormat must be 'plainText' or 'html'`);
}
}
function assertGetStringOptions(options, verb) {
if (options === void 0) return;
if (!options || typeof options !== "object") {
throw new Error(`Clipboard.${verb}: options must be an object`);
}
if (options.preferredFormat !== void 0 && options.preferredFormat !== "plainText" && options.preferredFormat !== "html") {
throw new Error(`Clipboard.${verb}: preferredFormat must be 'plainText' or 'html'`);
}
}
function assertSetImage(base64Image) {
if (typeof base64Image !== "string" || base64Image.length === 0) {
throw new Error("Clipboard.setImage: base64Image must be a non-empty string");
}
}
function assertGetImageOptions(options) {
if (!options || typeof options !== "object") {
throw new Error("Clipboard.getImage: options must be an object");
}
if (options.format !== "png" && options.format !== "jpeg") {
throw new Error(`Clipboard.getImage: format must be 'png' or 'jpeg'`);
}
if (options.jpegQuality !== void 0) {
if (typeof options.jpegQuality !== "number" || Number.isNaN(options.jpegQuality) || options.jpegQuality < 0 || options.jpegQuality > 1) {
throw new Error("Clipboard.getImage: jpegQuality must be a number from 0 to 1");
}
}
}
function assertSetUrl(url) {
if (typeof url !== "string" || url.length === 0) {
throw new Error("Clipboard.setUrl: url must be a non-empty string");
}
}
function assertListener(listener) {
if (typeof listener !== "function") {
throw new Error("Clipboard.addListener: listener must be a function");
}
}
export { assertGetImageOptions, assertGetStringOptions, assertListener, assertSetImage, assertSetStringOptions, assertSetStringText, assertSetUrl };
//# sourceMappingURL=validate.native.js.map