UNPKG

rollun-ts-utils

Version:
1 lines 1.91 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.copyToClipboardAsync=copyToClipboardAsync;exports["default"]=void 0;function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _typeof(obj){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj}}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj}}return _typeof(obj)}function copyToClipboard(str){var el=document.createElement("textarea");var value;if(_typeof(str)==="object"){value=JSON.stringify(str)}else if(typeof str==="number"){value=str.toString()}else{value=str}el.value=value;document.body.appendChild(el);el.select();document.execCommand("copy");document.body.removeChild(el);return value}function copyToClipboardAsync(_x){return _copyToClipboardAsync.apply(this,arguments)}function _copyToClipboardAsync(){_copyToClipboardAsync=_asyncToGenerator(regeneratorRuntime.mark(function _callee(str){return regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return navigator.clipboard.writeText(str);case 2:case"end":return _context.stop();}}},_callee)}));return _copyToClipboardAsync.apply(this,arguments)}var _default=copyToClipboard;exports["default"]=_default;