@galenjs/factories
v1.7.0
Published
galenjs factories.
Downloads
10
Readme
factories
galenjs factories.
lodash
camelJsonKeys
const { camelJsonKeys } = require('@galenjs/factories/lodash')
camelJsonKeys({
field_one: {
field_two: 'test'
},
field_three: 'test',
field_four: [{
field_five: 'test'
}]
})
snakeJsonKeys
const { snakeJsonKeys } = require('@galenjs/factories/lodash')
snakeJsonKeys({
fieldOne: {
fieldTwo: 'test'
},
fieldThree: 'test',
fieldFour: [{
fieldFive: 'test'
}]
})
sleep
const { sleep } = require('@galenjs/factories/sleep')
await sleep(1000)
validateJsonSchema
const validateSchema = require('@galenjs/factories/validateJsonSchema')
await validateSchema({ field: 1 }, {
type: 'object',
properties: {
field: { type: 'string' }
}
}, {
extendErr: 'test'
})
csv
parseCsv
const { parseCsv } = require('@galenjs/factories/csv')
parseCsv({
data: `id,name
1,Harper Lee
2,JRR Tolkien
3,William Shakespeare`,
endsWithLine: '\n',
delimiter: ','
})
writeCsv
const { writeCsv } = require('@galenjs/factories/csv')
writeCsv({
filePath: 'test.csv',
header: 'id,name',
data: [{ id: 1, name: "Harper Lee" }],
fields: ['id', 'name'],
writeLineLength: 1,
endsWithLine: '\r\n'
})
crypto
hash
const { hash } = require('@galenjs/factories/crypto')
console.log(hash('test'))
encrypted
const { encrypted } = require('@galenjs/factories/crypto')
const tt = 'abc'
const iv = crypto.randomBytes(16).toString('base64')
const key = crypto.randomBytes(16).toString('base64')
encrypted(tt, { key, iv })
decrypted
const { decrypted } = require('@galenjs/factories/crypto')
const iv = crypto.randomBytes(16).toString('base64')
const key = crypto.randomBytes(16).toString('base64')
const decryptedData = decrypted(encryptedData, { key, iv })
customLimit
const CustomLimit = require('@galenjs/factories/customLimit')
const customLimit = new CustomLimit()
const ret = await customLimit.execute(`${Date.now()}/1000`, () => 'helloWorld')
console.log(ret)