paliari-js-utils
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -1,1 +0,1 @@ | ||
module.exports=function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)r.d(e,o,function(n){return t[n]}.bind(null,o));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p="/",r(r.s=1)}([function(t,n,r){"use strict";r.r(n);var e=function(t,n){var r=!0,e=!1,o=void 0;try{for(var u,i=String(n).split(".")[Symbol.iterator]();!(r=(u=i.next()).done);r=!0){var f=u.value;if(!t)return t;t=t[f]}}catch(t){e=!0,o=t}finally{try{r||null==i.return||i.return()}finally{if(e)throw o}}return t};function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var u=function(t){return null!==t&&"object"===o(t)},i={"à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ő":"o","ù":"u","ú":"u","û":"u","ü":"u","ű":"u","ý":"y","ÿ":"y"},f=function(t){return t.toLocaleLowerCase().replace(/[^a-z0-9\s_-]/g,function(t){return i[t]||t})},c=function(t){return"[object Date]"===Object.prototype.toString.call(t)},a=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},l=function(t){return t?t.charAt(0).toUpperCase()+t.substr(1):t},p=function(t){return u(t)?function t(n){if(c(n))return new Date(n);if(a(n))return n;var r=Array.isArray(n)?[]:{};for(var e in n)r[e]=u(n[e])?t(n[e]):n[e];return r}(t):t};function d(t,n,r){return n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}var s=function t(n){for(var r=arguments.length,e=new Array(r>1?r-1:0),o=1;o<r;o++)e[o-1]=arguments[o];if(!e.length)return n;var i=e.shift();if(u(n)&&u(i))for(var f in i)u(i[f])?(n[f]||Object.assign(n,d({},f,{})),t(n[f],i[f])):Object.assign(n,d({},f,i[f]));return t.apply(void 0,[n].concat(e))},y=function(t){return function t(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/",e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];return Object.getOwnPropertyNames(n).reduce(function(e,i){return o.push(i),u(n[i])?t(n[i],r,e,o):e[o.join(r)]=n[i],o.pop(),e},e)}(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/")},b="aiCOVlB8Ws3ZSMyJ64dwtqAI5TDG1ejgcFH2YfXErxbRKhzo90pvUPNnL7umkQ",v={};b.split("").sort().forEach(function(t,n){v[b.charAt(n)]=t});var g=function(t){if(!t)return t;var n="";return t.split("").forEach(function(t){n+=v[t]||t}),n},j=[100,200,500,750],h=function(t){return j.find(function(n){if(t<=n)return n})},m=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=0,e=0;for(k in t)e+=Number(k)*t[k],r+=t[k];var o=Math.pow(10,n);return r?Math.round(e/r*o)/o:0};r.d(n,"deepKey",function(){return e}),r.d(n,"isObject",function(){return u}),r.d(n,"transliterate",function(){return f}),r.d(n,"isDate",function(){return c}),r.d(n,"isRegExp",function(){return a}),r.d(n,"ucfirst",function(){return l}),r.d(n,"deepClone",function(){return p}),r.d(n,"deepMerge",function(){return s}),r.d(n,"flattenObject",function(){return y}),r.d(n,"jsEncode",function(){return g}),r.d(n,"thumbRange",function(){return h}),r.d(n,"starRating",function(){return m})},function(t,n,r){t.exports=r(0)}]); | ||
module.exports=function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)r.d(e,o,function(n){return t[n]}.bind(null,o));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p="/",r(r.s=1)}([function(t,n,r){"use strict";r.r(n);var e=function(t,n){var r=!0,e=!1,o=void 0;try{for(var i,u=String(n).split(".")[Symbol.iterator]();!(r=(i=u.next()).done);r=!0){var a=i.value;if(!t)return t;t=t[a]}}catch(t){e=!0,o=t}finally{try{r||null==u.return||u.return()}finally{if(e)throw o}}return t};function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=function(t){return null!==t&&"object"===o(t)},u={"à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ő":"o","ù":"u","ú":"u","û":"u","ü":"u","ű":"u","ý":"y","ÿ":"y"},a=function(t){return t.toLocaleLowerCase().replace(/[^a-z0-9\s_-]/g,function(t){return u[t]||t})},c=function(t){return"[object Date]"===Object.prototype.toString.call(t)},f=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},l=function(t){return t?t.charAt(0).toUpperCase()+t.substr(1):t},d=function(t){return i(t)?function t(n){if(c(n))return new Date(n);if(f(n))return n;var r=Array.isArray(n)?[]:{};for(var e in n)r[e]=i(n[e])?t(n[e]):n[e];return r}(t):t};function s(t,n,r){return n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}var p=function t(n){for(var r=arguments.length,e=new Array(r>1?r-1:0),o=1;o<r;o++)e[o-1]=arguments[o];if(!e.length)return n;var u=e.shift();if(i(n)&&i(u))for(var a in u)i(u[a])?(n[a]||Object.assign(n,s({},a,{})),t(n[a],u[a])):Object.assign(n,s({},a,u[a]));return t.apply(void 0,[n].concat(e))},v=function(t){return function t(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/",e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];return Object.getOwnPropertyNames(n).reduce(function(e,u){return o.push(u),i(n[u])?t(n[u],r,e,o):e[o.join(r)]=n[u],o.pop(),e},e)}(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/")},y="aiCOVlB8Ws3ZSMyJ64dwtqAI5TDG1ejgcFH2YfXErxbRKhzo90pvUPNnL7umkQ",h={};y.split("").sort().forEach(function(t,n){h[y.charAt(n)]=t});var g=function(t){if(!t)return t;var n="";return t.split("").forEach(function(t){n+=h[t]||t}),n},b=[100,200,500,750],m=function(t){return b.find(function(n){if(t<=n)return n})},w=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=0,e=0;for(k in t)e+=Number(k)*t[k],r+=t[k];var o=Math.pow(10,n);return r?Math.round(e/r*o)/o:0},_=function(t){return t.replace(/-/g,"_").replace(/\//g,".").toLocaleLowerCase()},j=function(t,n){return"".concat(a(t),"_").concat(a(n)).replace(/ /g,"_")},O=function(t){return j(function(t){var n=!0,r=!1,e=void 0;try{for(var o,i=t[Symbol.iterator]();!(n=(o=i.next()).done);n=!0){var u=o.value;if(u.types.indexOf("administrative_area_level_1")>-1)return u.short_name}}catch(t){r=!0,e=t}finally{try{n||null==i.return||i.return()}finally{if(r)throw e}}}(t),function(t){var n=!0,r=!1,e=void 0;try{for(var o,i=t[Symbol.iterator]();!(n=(o=i.next()).done);n=!0){var u=o.value;if(u.types.indexOf("administrative_area_level_2")>-1)return u.long_name}}catch(t){r=!0,e=t}finally{try{n||null==i.return||i.return()}finally{if(r)throw e}}}(t))},x=function(t){if(!t.address_components)throw{code:"convert_place_no_address_componentes"};var n={};return n.geometry={viewport:{northeast:{lat:t.geometry.viewport.f.f,lng:t.geometry.viewport.b.f},southwest:{lat:t.geometry.viewport.f.b,lng:t.geometry.viewport.b.b}},location:{lat:t.geometry.location.lat(),lng:t.geometry.location.lng()}},n.formatted_address=t.formatted_address,n.place_id=t.place_id,n.cidade_id=O(t.address_components),n},S=function(){return function(t){return"desc"===t?9999999999999-Date.now():Date.now()}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"desc").toString()+Math.random().toString().substr(2,7)},A="zyxwvutsrqponmlkjihgfedcba_ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210-",E=0,M=[],L=function(){var t=Date.now(),n=t===E;E=t;for(var r=new Array(8),e=7;e>=0;e--)r[e]=A.charAt(t%64),t=Math.floor(t/64);if(0!==t)throw new Error("We should have converted the entire timestamp.");var o=r.join("");if(n){for(e=11;e>=0&&63===M[e];e--)M[e]=0;M[e]++}else for(e=0;e<12;e++)M[e]=Math.floor(64*Math.random());for(e=0;e<12;e++)o+=A.charAt(M[e]);if(20!=o.length)throw new Error("Length should be 20.");return o},C=function(t){for(var n=0,r=0;r<8;r++){var e=A.indexOf(t.charAt(r));if(-1===e)throw new Error("Invalid id!");n=64*n+e}return n},P=function t(n,r){var e=n.split(""),o=e.pop(),i=r[r.indexOf(o)+1];return i?e.join("")+i:t(e.join(""),r)+r[0]},D=function(t){return P(t,A.split(""))},R=function(t){return P(t,A.split("").sort())};var T=function t(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};for(var e in function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),n)"function"==typeof n[e]?this[e]=null===r[e]?null:n[e](r[e]):this[e]=r[e]||n[e]};function I(t,n){for(var r=0;r<n.length;r++){var e=n[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}var N="pt_br",G=function(){function t(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:N;!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.locales=n,this.locale=r}return function(t,n,r){n&&I(t.prototype,n),r&&I(t,r)}(t,[{key:"t",value:function(t,n){return function(t,n){if(!t||!n)return t;for(var r in n)t=t.replace(new RegExp("%{"+r+"}","g"),n[r]);return t}((void 0)(this.current,t),n)}},{key:"setLocale",value:function(t){if(this.getAvailableLocales().includes(t))return this.locale=t,this;throw new Error("Locale not found!")}},{key:"getLocale",value:function(){return this.locale}},{key:"getAvailableLocales",value:function(){return Object.keys(this.locales)}},{key:"current",get:function(){return this.locales[this.locale]}}]),t}();r.d(n,"deepKey",function(){return e}),r.d(n,"isObject",function(){return i}),r.d(n,"transliterate",function(){return a}),r.d(n,"isDate",function(){return c}),r.d(n,"isRegExp",function(){return f}),r.d(n,"ucfirst",function(){return l}),r.d(n,"deepClone",function(){return d}),r.d(n,"deepMerge",function(){return p}),r.d(n,"flattenObject",function(){return v}),r.d(n,"jsEncode",function(){return g}),r.d(n,"thumbRange",function(){return m}),r.d(n,"starRating",function(){return w}),r.d(n,"prepareKey",function(){return _}),r.d(n,"convertPlace",function(){return x}),r.d(n,"idCidade",function(){return j}),r.d(n,"idCidadeAddressComponent",function(){return O}),r.d(n,"idGeneratorDesc",function(){return L}),r.d(n,"idGeneratorNumeric",function(){return S}),r.d(n,"idDescTimestamp",function(){return C}),r.d(n,"prevId",function(){return D}),r.d(n,"nextId",function(){return R}),r.d(n,"BaseModel",function(){return T}),r.d(n,"I18n",function(){return G})},function(t,n,r){t.exports=r(0)}]); |
{ | ||
"name": "paliari-js-utils", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Biblioteca de utilidades para JS", | ||
@@ -5,0 +5,0 @@ "main": "dist/paliari-js-utils.js", |
165
README.md
@@ -11,3 +11,3 @@ # paliari-js-utils | ||
## Build Setup | ||
## Development | ||
@@ -25,2 +25,134 @@ ```bash | ||
## i18n | ||
```js | ||
import { I18n } from 'paliari-js-utils' | ||
// config locale | ||
const locales = { | ||
pt_br: {enums: {...}, db: {...}} | ||
} | ||
const i18n = new I18n(locales, 'pt_br') | ||
// change locale | ||
i18n.setLocale('en') | ||
// Get locale | ||
i18n.getLocale() // 'en' | ||
// Obtem os locais disponives | ||
i18n.getAvailableLocales() //['en', 'pt_br', ...] | ||
// usage | ||
i18n.t('db.attributes.animal.nome') | ||
i18n.t('enums.castracao.status.solicitado') | ||
// com replaces | ||
i18n.t('error.messasges.long_chars', {max: '15'}) | ||
``` | ||
Exemplo de estrutura dos locales: | ||
```yaml | ||
pt_br: | ||
buttons: | ||
save: 'Salvar' | ||
#... | ||
db: | ||
attributes: | ||
pessoa: | ||
id: ID | ||
cpf_cnpj: 'CPF/CNPJ' | ||
#... | ||
enums: | ||
castracao: | ||
status: | ||
solicitado: Solicitado | ||
#... | ||
errors: | ||
permission_denied: 'Permissão negada' | ||
auth: | ||
invalid_cpf_cnpj: 'O CPF/CNPJ é inválido' | ||
#... | ||
messages: | ||
sign_out_confirm: 'Tem certeza que deseja sair?' | ||
could_not_load_record: 'Não foi possível carregar o registro' | ||
#... | ||
#... | ||
``` | ||
Exemplo de config para Vuejs | ||
```js | ||
import { I18n } from 'paliari-js-utils' | ||
const i18n = new I18n(locales, 'pt_br') | ||
export default { | ||
install(vue) { | ||
vue.prototype.$i18n = i18n | ||
vue.i18n = vue.prototype.$i18n | ||
} | ||
} | ||
``` | ||
## BaseModel | ||
Extendendo um model. | ||
```js | ||
import { BaseModel, idGeneratorDesc } from 'paliari-js-utils' | ||
const attrs = { | ||
id: idGeneratorDesc(), | ||
cidade_id: '', | ||
animal: {}, | ||
dono: {}, | ||
clinica: {}, | ||
status: '', | ||
solicitado_em: Date.now(), | ||
aprovado_em: null | ||
} | ||
class Castracao extends BaseModel { | ||
constructor(obj) { | ||
super(attrs, obj) | ||
} | ||
} | ||
export default Castracao | ||
// instanciando um model | ||
var castracao = new Castracao({ status: 'solicitado' }) | ||
``` | ||
## ID generator key for Firebase | ||
```js | ||
// gera id alfanumerico baseado no timestamp ordenado decrescente | ||
import { idGeneratorDesc } from 'paliari-js-utils' | ||
var id = idGeneratorDesc() // zdja0I19bKcIxA73QjIA | ||
// extrai o timestamp do ID desc | ||
import { idDescTimestamp } from 'paliari-js-utils' | ||
var timestamp = idDescTimestamp('zdja0I19bKcIxA73QjIA') // 1529444224885 | ||
// gera ID numerico | ||
import { idGeneratorNumeric } from 'paliari-js-utils' | ||
// default desc | ||
var id = idGeneratorNumeric() // 84704117442938738166 | ||
var id = idGeneratorNumeric('desc') // 84704117442938738166 | ||
// asc | ||
var id = idGeneratorNumeric('asc') // 15295883565621743713 | ||
``` | ||
## Consultar próximo ID (Usado na paginação) | ||
```js | ||
import { nextId, prevId } from 'paliari-js-utils' | ||
nextId('zdit9URuO2T9VdC0h-2l') //zdit9URuO2T9VdC0h-2m | ||
prevID('zdit9URuO2T9VdC0h-2l') //zdit9URuO2T9VdC0h-2k | ||
``` | ||
### starRating | ||
@@ -150,2 +282,10 @@ | ||
### prepareKey | ||
```js | ||
import { prepareKey } from 'paliari-js-utils' | ||
prepareKey('a.b/c-D') // a.b.c_d | ||
``` | ||
### flattenObject | ||
@@ -160,1 +300,24 @@ | ||
``` | ||
## Facade for google Maps | ||
### Extrair ID da cidade | ||
```js | ||
import { idCidadeAddressComponent, idCidade } from 'i-pet-utils' | ||
// param address_components do google geo | ||
var cidade_id = idCidadeAddressComponent(geo_address_components) | ||
// uf, nome | ||
var cidade_id = idCidade(uf, 'nome da cidade') | ||
``` | ||
## Converter address_component para string formatada | ||
```js | ||
import { convertPlace } from 'i-pet-utils' | ||
// param address_components do google geo | ||
var formatted = convertPlace(address_components) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14986
320