Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

paliari-js-utils

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paliari-js-utils

Biblioteca de utilidades para JS

  • 0.1.1
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-40%
Maintainers
2
Weekly downloads
 
Created
Source

paliari-js-utils

Biblioteca de utilidades para JS

Installation

yarn add paliari-js-utils

Development

# install dependencies
yarn install

# build with minification
yarn release

# publish
bin/publish

i18n

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:

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

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.

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

// 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)

import { nextId, prevId } from 'paliari-js-utils'

nextId('zdit9URuO2T9VdC0h-2l') //zdit9URuO2T9VdC0h-2m
prevID('zdit9URuO2T9VdC0h-2l') //zdit9URuO2T9VdC0h-2k

starRating

/**
 * Calcula media das notas.
 *
 * @param notas Object
 * @param precision Integer quantidade de casas decimais
 *
 * @returns Number
 */
import { starRating } from 'paliari-js-utils'

/**
 * Onde as keys sao as notas possiveis
 * e os values a quantidade de vezes que se repete.
 */
var notas = {
  1: 23,
  2: 0,
  3: 223,
  4: 343,
  5: 312
}
var precision = 2

var rate = starRating(notas, precision) // 4.02

Transliterate

import { transliterate } from 'paliari-js-utils'

var str = transliterate('São José') // sao jose

deepKey

import { deepKey } from 'paliari-js-utils'

var obj = {a: {a1: a2: 'Content'}}
var value = deepKey(obj, 'a.a1.a2') // Content

isObject

import { isObject } from 'paliari-js-utils'

isObject({}) // true
isObject({ a: 1 }) // true
isObject([]) // true
isObject(1) // false
isObject(null) // false

isHash

import { isHash } from 'paliari-js-utils'

isHash({}) // true
isHash({ a: 1 }) // true
isHash('') // false
isHash([]) // false
isHash(1) // false
isHash(null) // false

isDate

import { isDate } from 'paliari-js-utils'

isDate(new Date()) // true
isDate('') // false
isDate(null) // false
isDate(1) // false

isRegExp

import { isRegExp } from 'paliari-js-utils'

isRegExp(new RegExp()) // true
isRegExp(/[0-9]/) // true
isRegExp(/[0-9]/g) // true
isRegExp(/ab1/g) // true
isRegExp('[0-9]') // false

deepMerge

import { deepMerge } from 'paliari-js-utils'

var a = {
  a: { a1: 'a1' }
}
var b = {
  a: { a2: 'a2' },
  b: { b1: 'a' }
}
deepMerge(a, b) // {  a: { a1: 'a1', a2: 'a2' },b: { b1: 'a' }}

deepClone

import { deepClone } from 'paliari-js-utils'

var a = {
  a: { a1: 'a1' }
}
deepClone(a)

jsEncode

import { jsEncode } from 'paliari-js-utils'

jsEncode('Abacaxi') // Mg0W0f1

ucfirst

import { ucfirst } from 'paliari-js-utils'

ucfirst('abc') // Abc

prepareKey

import { prepareKey } from 'paliari-js-utils'

prepareKey('a.b/c-D') // a.b.c_d

flattenObject

import { flattenObject } from 'paliari-js-utils'

const a = { castracoes: {'-41iosdoii': { nome: 'Bilu', ... }} }

// { 'castracoes/-41iosdoii/nome': 'Bilu', ... }

Facade for google Maps

Extrair ID da cidade

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

import { convertPlace } from 'i-pet-utils'

// param address_components do google geo
var formatted = convertPlace(address_components)

FAQs

Package last updated on 28 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc