npm package for shared functionality
install: npm i --save parcellab/parcellab-utilities
const logToConsole = require('parcellab-utilities').logToConsole
const logger = require('parcellab-utilities').Logger.for('yourScriptName')
or
import { logToConsole, Logger } from 'parcellab-utilities'
const logger = Logger.for('yourScriptName')
with environment variables and/or with manipulating the Logger object in js
LOG_LEVEL=DEBUG || Logger.settings.level = 'debug'
LOG_HOST=127.128.129.130 || Logger.settings.host = '127.128.129.130'
LOG_PORT=12345 || Logger.settings.port = '12345'
LOG_COLOR=1 || Logger.settings.color = true
LOG_LOCAL=1 || Logger.settings.saveLocal = true
LOG_EXTRA=1 || Logger.settings.verboseLocal = true
LOG_PRETTY=1 || Logger.settings.prettyPrint = true
LOG_TIMESTAMP=1 || Logger.settings.timestampLocal = true
PRODUCTION=0 || Logger.settings.developer_mode = true
- javascript settings overrule env var settings.
- env vars set in shell will overrule vars in
.env
file parsed by npm moduledotenv
// syntax: logger.level(message, [ extra, [ sender]])
logger.trace('>>', { data: [1,0,1,1,0], msgLong: 'a bit has shifted!' })
logger.debug('invoking some procedure', obj )
logger.info('this message is really informative')
logger.warn('something is smoking', null, 'smokeAlertSender') // custom sender
logger.error('grab your towels and panic: ', err)
logger.critical('hello slack! you should really do something about this NOW', err, 'importantFkt')
or
logToConsole(level, sender, message, extra)
const resolveCountryToISO3 = require('parcellab-utilities').resolveCountryToISO3
or
import { resolveCountryToISO3 } from 'parcellab-utilities'
resolveCountryToISO3('Spain')
// returns 'ESP'
it takes strings or anything, don't expect miracles. The underlying lib countryjs
recognizes some translations - English or German country names should be a pretty safe bet
❗️Never edit the files in /lib
! They are generated from /src
.
Make use of npm test
to see if things still pretend to be alright.
When you have commited changes to the repository here is what needs to be done to make an updated package available (it's easy to forget at least one step:)
npm run build
git commit -a -m 'generated new build'
npm version patch
ornpm version minor
ornpm version major
git push --follow-tags
or you can simply run npm run publish
which does these things