UNPKG

storybook-react-geekshubs

Version:

Creation and curation of hight quality react components.

1 lines 2.71 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noAccents=exports.parsePercent=exports.roundDecimals=exports.debounce=exports.cacheAsync=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)})}}var cacheAsync=function cacheAsync(fn){var cached={};return _asyncToGenerator(regeneratorRuntime.mark(function _callee(){var _len,args,_key,key,_args=arguments;return regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:for(_len=_args.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=_args[_key]}key=args.join("-");if(!(cached[key]===undefined)){_context.next=6;break}_context.next=5;return fn.apply(void 0,args);case 5:cached[key]=_context.sent;case 6:return _context.abrupt("return",cached[key]);case 7:case"end":return _context.stop();}}},_callee)}))};exports.cacheAsync=cacheAsync;var debounce=function debounce(fn){var delay=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var id;return function(){if(id){clearTimeout(id)}for(var _len2=arguments.length,args=new Array(_len2),_key2=0;_key2<_len2;_key2++){args[_key2]=arguments[_key2]}id=setTimeout.apply(void 0,[fn,delay].concat(args));return id}};exports.debounce=debounce;var roundDecimals=function roundDecimals(value){var decimals=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;if(typeof value!=="number")value=0;return Number(value.toFixed(decimals))};exports.roundDecimals=roundDecimals;var parsePercent=function parsePercent(value){var newValue=value||0;if(newValue<0)newValue=0;if(newValue>1)newValue=1;newValue=roundDecimals(newValue,2);return newValue};exports.parsePercent=parsePercent;var noAccents=function noAccents(texto){var map=[["\\s",""],["[\xE0\xE1\xE2\xE3\xE4\xE5]","a"],["\xE6","ae"],["\xE7","c"],["[\xE8\xE9\xEA\xEB]","e"],["[\xEC\xED\xEE\xEF]","i"],["\xF1","n"],["[\xF2\xF3\xF4\xF5\xF6]","o"],["\u0153","oe"],["[\xF9\xFA\xFB\xFC]","u"],["[\xFD\xFF]","y"],["\\W",""]];var cb=function cb(match){if(match.toUpperCase()===match)return map[i][1].toUpperCase();return map[i][1]};for(var i=0;i<map.length;++i){texto=texto.replace(new RegExp(map[i][0],"gi"),cb)}return texto};exports.noAccents=noAccents;