Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
paliari-js-utils
Advanced tools
yarn add paliari-js-utils
# install dependencies
yarn install
# build with minification
yarn release
# publish
bin/publish
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
}
}
Para alterar a linguagem no browser
import fecha from 'fecha'
import { I18n, Language } from 'paliari-js-utils'
const i18n = new I18n(locales, 'pt_br')
const language = new Language(i18n, fecha)
// Exemplo para Vuejs
import { Language } from 'paliari-js-utils'
export default {
install(vue, i18n, fecha) {
vue.prototype.$language = new Language(i18n, fecha)
vue.language = vue.prototype.$language
}
}
// Your component
export default {
methods:{
changeLanguage(language) {
if (language !== this.$language.current) {
this.$language.current = language
this.$router.push({name: 'changing_language'})
}
}
}
}
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' })
// 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
import { nextId, prevId } from 'paliari-js-utils'
nextId('zdit9URuO2T9VdC0h-2l') //zdit9URuO2T9VdC0h-2m
prevID('zdit9URuO2T9VdC0h-2l') //zdit9URuO2T9VdC0h-2k
/**
* 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
import { transliterate } from 'paliari-js-utils'
var str = transliterate('São José') // sao jose
import { deepKey } from 'paliari-js-utils'
var obj = {a: {a1: a2: 'Content'}}
var value = deepKey(obj, 'a.a1.a2') // Content
import { getClassName } from 'paliari-js-utils'
getClassName({}) // Object
getClassName(function() {}) // Function
getClassName([]) // Array
getClassName(new Date()) // Date
getClassName(/a/) // RegExp
getClassName(1) // Number
getClassName('') // String
getClassName(null) // Null
getClassName(undefined) // Undefined
import { isObject } from 'paliari-js-utils'
isObject({}) // true
isObject({ a: 1 }) // true
isObject([]) // true
isObject(1) // false
isObject(null) // false
import { isHash } from 'paliari-js-utils'
isHash({}) // true
isHash({ a: 1 }) // true
isHash('') // false
isHash([]) // false
isHash(1) // false
isHash(null) // false
import { isDate } from 'paliari-js-utils'
isDate(new Date()) // true
isDate('') // false
isDate(null) // false
isDate(1) // false
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
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' }}
import { deepClone } from 'paliari-js-utils'
var a = {
a: { a1: 'a1' }
}
deepClone(a)
import { sanitize } from 'paliari-js-utils'
var obj = {
a: { a1: 'a1', a2: 'a2' },
b: { b1: 'b1', b2: 'b2' },
c: 1,
d: 1
}
var rules = {
a: { a2: true},
b: true,
c: true }
}
sanitize(obj, rules) // {a: {a2: 'a2'}, b: {b1: 'b1', b2: 'b2'}, c: 1}
import { jsEncode } from 'paliari-js-utils'
jsEncode('Abacaxi') // Mg0W0f1
import { ucfirst } from 'paliari-js-utils'
ucfirst('abc') // Abc
import { prepareKey } from 'paliari-js-utils'
prepareKey('a.b/c-D') // a.b.c_d
import { flattenObject } from 'paliari-js-utils'
const a = { castracoes: {'-41iosdoii': { nome: 'Bilu', ... }} }
// { 'castracoes/-41iosdoii/nome': 'Bilu', ... }
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')
import { convertPlace } from 'i-pet-utils'
// param address_components do google geo
var formatted = convertPlace(address_components)
FAQs
Biblioteca de utilidades para JS
We found that paliari-js-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.