@aghaffar570/testpkg

2.1.0 • Public • Published

testpkg

install size

a test npm package that stores every log and prints it to the console.

install

npm install @aghaffar570/testpkg

usage

const { log, viewLogs, removeLogs } = require('@aghaffar570/testpkg');

log('hello') // '2019-1-29 15:20:08 - hello'
log('goodbye') // '2019-1-29 15:20:08 - goodbye'
log() // '2019-1-29 15:20:08 - NO MSG INPUT'

viewLogs()
// => [ { message: 'hello', time: '2019-1-29 15:25:05' },
//      { message: 'goodbye', time: '2019-1-29 15:25:05' } ]

removeLogs()
// => []

implementation

function logger() {
 const _logs = []
 return {
   log(message) {
     const time = new Date().toLocaleString()
     _logs.push({ message, time })
     console.log(`${time} - ${message}`)
   },
   viewLogs(){
     console.log(_logs)
     return _logs
   },
   removeLogs(){
     console.log(_logs)
     _logs.length = 0
     return _logs
   }
 }
}


module.exports = logger()

Readme

Keywords

Package Sidebar

Install

npm i @aghaffar570/testpkg

Weekly Downloads

3

Version

2.1.0

License

MIT

Unpacked Size

2.96 kB

Total Files

4

Last publish

Collaborators

  • aghaffar570