- validateEmail
- validateEmailBulk
- tld
- atIndex
- secrets
- Cryptography
- NODE_CIPHER
- AUTH_TAG_BYTE_LEN
- IV_BYTE_LEN
- KEY_BYTE_LEN
- SALT_BYTE_LEN
- get
- invoiceTotals
- currencyParse
- phoneNumberGetInternationalString
- toJSON
- initials
- isTrue
- sleep
- phoneNumberFormatString
- emailGetFromString
- searchObject
- truncate
- dateFormat
- publicKeySetString
- publicKeyGetString
- employmentStatus
- customerTypes
- bankAccountType
- dateFormats
- contactType
- expenseStatus
- salaryFrequency
- leavePolicy
- languages
- taxTypes
- expenseType
- gender
- documentSize
- deliveryNoteStatus
- creditNoteStatus
- invoiceStatus
- estimateStatus
- docTypes
- months
- monthDays
- organizationCategory
- monthNameNumber
- orderStatus
- paymentMethods
- deliveryMethods
- paymentStatus
- paymentTerms
- productTypes
- alphabet
- productUnits
- quoteStatus
- recurringFrequency
- salutations
- weekdays
- timezones
- payoutMethod
- paymentMethod
- transactionStatus
- Country
App dictionary
App countries
This method validates email address
const isValid = await validateEmail({
email: 'user@example.com',
})
Returns boolean {Promise} a boolean value indicating if the email is valid or not
This method validates all supplied email addresses.
-
mailingList
Array array of email objects to be verified
const { data } = await validateEmailBulk(
{
email: 'user1@example.com',
},
{
email: 'user2@example.com',
},
])
Returns Array object consisting of valid and invalid email addresses { valid: [], invalid: [] }
Check if the email contains more than 3 numeric characters. If it does, throw an error.
Validate TLD
-
email
any
remove email modifier
This function creates .env
| .env.development
| .env.development.json
files from aws secret manager
This function also add respective files to .gitignore
{
"scripts": {
"secrets": "node ./node_modules/secrets-manager/dist/index.js --secret aws-secret-name --profile local-aws-profile --privacy be|fe --region eu-west-1",
}
}
The Cryptography class provides methods for encryption, decryption, signing, and verification of data using various cryptographic algorithms.
const cryptography = new Cryptography(['key1', 'key2', 'key3'])
const encryptedData = cryptography.encrypt('Hello, World!')
const decryptedData = cryptography.decrypt(encryptedData)
const signature = cryptography.signature()
const isVerified = cryptography.signatureVerify(signature)
// creates a KrugerGold Token Address
const address = cryptography.address()
const encodedData = cryptography.base64Encode('Hello, World!')
const decodedData = cryptography.base64Decode(encodedData)
const isEncodedOrNot = cryptography.isBase64Encoded(encodedData)
cryptography.get('strong_pw') // returns i=SQ_qa3W[<RxoM
cryptography.random({ length: 20, useLowerCase: true, useUpperCase: true, useNumbers: true, useSpecial: true, useHex: false }) // returns *ajz:74,*ak0
-
options
RandomOptions
cryptography.random({ length: 20, useLowerCase: true, useUpperCase: true, useNumbers: true, useSpecial: true, useHex: false }) // returns *ajz:74,*ak0
// Decent Passwords - Good for nothing really, public accounts and other non-critical things.
cryptography.get('decent_pw') // returns rXjdx36oro
// Strong Passwords - Robust enough to keep your web hosting account secure.
cryptography.get('strong_pw') // returns i=SQ_qa3W[<RxoM
// Fort Knox Passwords - Secure enough for almost anything, like root or administrator passwords.
cryptography.get('ft_knox_pw') // returns P}U%H\OOYAYb;wc"3hgI,3Lz[gd-z]
// Encryption Keys - Can be used for any other 256-bit key requirement.
cryptography.get('ci_key') // returns CeXHpM3nDgzdv0o3AkMCs3OuxzepLGW8
// 160-bit WPA Key
cryptography.get('160_wpa') // returns oHI#gR8z#h7BS>cZ!zH(
// 504-bit WPA Key
cryptography.get('504_wpa') // returns <os[g`s}u06jqt"Ea]t11,HsI[UipHD)%F";:9RhJ@kTU8GknLpMAXtoCzsJjT`
// 64-bit WEP Keys
cryptography.get('64_wep') // returns 8911B
// 128-bit WEP Keys
cryptography.get('128_wep') // returns 9F4E4F933BCCC
// 152-bit WEP Keys
cryptography.get('152_wep') // returns 695E1EE96E483961
// 256-bit WEP Keys
cryptography.get('256_wep') // returns AC7E866246BA6B71BF5D88A6861AB
Returns string
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const salt = cryptography.salt()
console.log(salt)
// Output:
// 5eb63bbbe01eeed093cb22bb8f5acdc3
Returns any The generated salt value as a hexadecimal string.
Returns any The generated IV as a Buffer.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const signature = cryptography.signature()
console.log(signature)
// Output:
// 6a3a4b5c6d7e8f9a
Returns any The generated signature as a string.
-
signature
string The signature to verify.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const signature = '6a3a4b5c6d7e8f9a'
const isValid = cryptography.signatureVerify(signature)
console.log(isValid)
// Output:
// true
- Throws any An error if the signature contains unknown identifiers.
Returns any True if the signature is valid, false otherwise.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const address = cryptography.address()
console.log(address)
// Output:
// kK5HCVlAmmEnnlKh6wVX9TiJ6YGI7FCl
- Throws any An error if an error occurs during address generation.
Returns any The generated address as a string.
-
count
number? The number of keys to generate. Defaults to 12.
Returns any An array of randomly generated keys.
-
data
any The data to encrypt.
const crypto = new Cryptography(['key1', 'key2', 'key3'], 'encryptKey', 'encryptKeySingle')
const data = 'Hello, World!'
const encryptedData = cryptography.encryptSingle(data)
console.log(encryptedData)
// Output:
// 5eb63bbbe01eeed093cb22bb8f5acdc3
Returns any The encrypted data as a base64-encoded string.
-
text
any The text to encrypt.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const text = 'Hello, World!'
const encryptedText = cryptography.encrypt(text)
console.log(encryptedText)
// Output:
// 6a3a4b5c6d7e8f9a:6a3a4b5c6d7e8f9a:6a3a4b5c6d7e8f9a
- Throws any An error if an error occurs during encryption.
Returns any The encrypted text as a string.
-
encryptedText
any The encrypted text to decrypt.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const encryptedText = '6a3a4b5c6d7e8f9a:6a3a4b5c6d7e8f9a:6a3a4b5c6d7e8f9a'
const decryptedText = cryptography.decrypt(encryptedText)
console.log(decryptedText)
// Output:
// Hello, World!
- Throws any An error if an error occurs during decryption.
Returns any The decrypted text as a string.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const password = 'myPassword'
const salt = cryptography.salt()
const hashedPassword = cryptography.password(password, salt)
console.log(hashedPassword)
// Output:
// 5ebe2294ecd0e0f08eab7690d2a6ee69
- Throws any An error if an error occurs during password hashing.
Returns any The hashed password as a hexadecimal string.
-
payload
any The payload to include in the JWT. (optional, default{}
) -
expiry
string The expiry time for the JWT.
const payload = {
sub: '1234567890',
name: 'John Doe',
iat: 1516239022
}
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const expiry = '1h'
const token = cryptography.jwtIssue(payload, expiry)
console.log(token)
// Output:
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
- Throws any An error if an error occurs during JWT issuance.
Returns any The issued JWT as a string.
-
token
string The JWT to verify.
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const payload = cryptography.jwtVerify(token)
console.log(payload)
// Output:
// {
// sub: '1234567890',
// name: 'John Doe',
// iat: 1516239022
// }
- Throws any An error if the JWT is invalid or an error occurs during verification.
Returns any The decoded payload if the JWT is valid.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const privateKey = cryptography.privateKey()
console.log(privateKey)
// Output:
// -----BEGIN PRIVATE KEY-----
// MIHuAgEAMBAGByqGSM49AgEGBSuBBAAjBIHWMIHTAgEBBEIBA4GCAWqjggFMMIIB
// ...
// -----END PRIVATE KEY-----
- Throws any An error if an error occurs during private key generation.
Returns any The generated private key as a PEM-encoded string.
-
privateKey
string The private key to generate the public key from.
const privateKey = `-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDZ1Ck6vJQK0J5T
...
-----END PRIVATE KEY-----`
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const publicKey = cryptography.publicKey(privateKey)
console.log(publicKey)
// Output:
// -----BEGIN PUBLIC KEY-----
// MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2dQpOryUCtCeUz8vZ6zB
// ...
// -----END PUBLIC KEY-----
Returns any The generated public key as a PEM-encoded string.
-
$0
{privateKey: string, publicKey: string}-
$0.privateKey
-
$0.publicKey
-
-
privateKey
The private key used to sign the data. -
publicKey
The public key used to verify the signature.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const privateKey = `-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDZ1Ck6vJQK0J5T
...
-----END PRIVATE KEY-----`
const publicKey = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2dQpOryUCtCeUz8vZ6zB
...
-----END PUBLIC KEY-----`
const isAuthentic = cryptography.publicKeyVerify({ privateKey, publicKey })
console.log(isAuthentic)
// Output:
// true
- Throws any An error if the public key fails to authenticate.
Returns any True if the public key is authentic, false otherwise.
-
string
string The string to check.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const encodedString = 'SGVsbG8sIFdvcmxkIQ=='
const isEncoded = cryptography.isBase64Encoded(encodedString)
console.log(isEncoded)
// Output:
// true
Returns any True if the string is base64 encoded, false otherwise.
-
data
string The data to encode.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const data = 'Hello, World!'
const encodedData = cryptography.base64Encode(data)
console.log(encodedData)
// Output:
// SGVsbG8sIFdvcmxkIQ==
Returns any The base64-encoded string.
-
encodedString
string The base64-encoded string to decode.
const crypto = new Cryptography(['key1', 'key2', 'key3'])
const encodedString = 'SGVsbG8sIFdvcmxkIQ=='
const decodedString = cryptography.base64Decode(encodedString)
console.log(decodedString)
// Output:
// Hello, World!
Returns any The decoded string.
GCM is an authenticated encryption mode that not only provides confidentiality but also provides integrity in a secured way.
128 bit auth tag is recommended for GCM.
NIST recommends 96 bits or 12 bytes IV for GCM to promote interoperability, efficiency, and simplicity of design.
Note: 256 (in ALG name) is key size. NODE size for AES is always 128.
To prevent rainbow table attacks.
-
strength
The strength of the key to generate. decent_pw|strong_pw|ft_knox_pw|ci_key|160_wpa|504_wpa|64_wep|128_wep|152_wep|256_wep
Calculates the invoice totals based on the provided parameters.
-
doc
The invoice totals document. -
docProducts
An array of products in the invoice. -
taxes
An array of taxes applied to the invoice.
const doc = {
number: 10001,
objectId: 'testDocObject',
discountAmount: 0,
discountPercentage: 0,
taxableSubTotal: 438.5,
paid: 0,
adjustment: 0,
shipping: 0,
}
const docProducts = [{ qty: 2, price: 100, tax: 15 }]
const taxes = [
{
name: 'VAT',
category: 'sales',
value: 15,
},
{
name: 'None',
category: 'sales',
value: 0,
},
]
Returns any A Promise that resolves to an object containing the calculated invoice totals.
This method validates email address
-
number
String the number or string instance to parse as a floating currency string
currencyParse('123.43') // return '123.43'
currencyParse('12xs3.3') // return '123.30'
Returns string {String} a boolean value indicating if the email is valid or not
Returns the international format of a phone number.
-
phoneNumberObject
An object containing the phone number and country code.
const phoneNumberObject = {
phoneNumber: '+1234567890',
countryCode: 'US',
}
const internationalPhoneNumber = phoneNumberGetInternationalString(phoneNumberObject);
console.log(internationalPhoneNumber); // Output: +1 234-567-890
Returns any The international format of the phone number as a string.
This function returns a well structured json object
-
object
string a stringified object in string format
toJSON('{"name":"John Doe"}') // returns {"name": "John Doe"}
Returns object {Object} a well structured json object
This method returns initials from a given name string
-
alt
string a name string to get initials from
initials('Zeal Murapa') // returns ZM
Returns string {String} a string of initials
This method is a truthy check for a given value
-
value
any a stringified object in string format
isTrue('') // returns false
Returns boolean {Boolean} a boolean value
This function sleeps for a given time
-
ms
ms a number in milliseconds
await sleep(1000) // sleeps for 1 second
Returns promise {Promise} blocking async promise
This function formats a phone number string to international format
-
numberString
string a phone number string
phoneNumberFormatString('+276925411223') // returns +27 692 541 1223
Returns object {String} a formatted phone number string
This function extracts an email address from a string
-
text
string a string containing an email address
emailGetFromString('This is my email address: john@example.com')
Returns string {String} an email address
This function searches an array of objects for a query string
searchObject('John', [{name: 'John Doe'}, {name: 'Jane Doe'}]) // returns [{name: 'John Doe'}]
Returns object {Array} a well structured json object
This method validates email address
-
str
string a string to truncate
truncate('This is a long string', 10) // returns 'This is a...'
Returns string {String} a truncated string
This method validates email address
-
date
date a date object -
null
@param {"full" | "long" | "short" | "time"} format - The format of the output.
dateFormat(new Date(), 'full') // returns 'Sun, Jan 3rd 2021 20:00:00'
Returns object {Object} a well structured json object
This function returns a public key string with the header and footer
-
key
string a public key string without the header and footer
publicKeySetString('MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA') // returns -----BEGIN PUBLIC KEY----- ...
Returns string {string} a public key string with the header and footer
This function returns a public key string without the header and footer
-
key
string a stringified object in string format
publicKeyGetString('-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA)
Returns string {string} a public key string without the header and footer
A list of employmentStatus
A list of customerTypes
A list of bankAccountType
A list of dateFormats
A list of contactType
A list of expenseStatus
A list of salaryFrequency
A list of leavePolicy
A list of alphabet
A list of taxTypes
A list of expenseType
A list of gender
A list of documentSize
A list of deliveryNoteStatus
A list of creditNoteStatus
A list of invoiceStatus
A list of estimateStatus
A list of docTypes
A list of months
A list of monthDays
A list of organizationCategory
A list of monthNameNumber
A list of orderStatus
A list of paymentMethods
A list of deliveryMethods
A list of paymentStatus
A list of paymentTerms
A list of productTypes
A list of alphabet
A list of productUnits
A list of quoteStatus
A list of recurringFrequency
A list of salutations
A list of weekdays
A list of timezones
A list of payment methods
A list of payment methods
A list of transaction status
This method validates email address
// get country of andorra only
import { country_ad } from 'every-utils';
// get all countries
import { countries } from 'every-utils';
console.log(countries.find((country) => country.tld === country_ad.tld);
{
name: 'Andorra',
capital: 'Andorra la Vella',
population: '84000',
languages: 'ca',
callingCode: '376',
numeric: '020',
timezone: 'UTC+01:00',
region: 'Europe',
tld: 'ad',
currency: {
name: 'Euro',
symbol: '\u20ac',
symbolNative: '\u20ac',
decimalDigits: 2,
rounding: 0,
isoCode: 'EUR',
namePlural: 'euros',
},
countryName: 'Andorra',
countryShortCode: 'AD',
regions: [
{
name: 'Andorra la Vella',
shortCode: '07',
},
{
name: 'Canillo',
shortCode: '02',
},
{
name: 'Encamp',
shortCode: '03',
},
{
name: 'Escaldes-Engordany',
shortCode: '08',
},
{
name: 'La Massana',
shortCode: '04',
},
{
name: 'Ordino',
shortCode: '05',
},
{
name: 'Sant Juli\u00e0 de L\u00f2ria',
shortCode: '06',
},
],
}
Returns object {Country} a country object