npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bda-util

v0.1.2

Published

commonly used tools for bda projects

Downloads

13

Readme

bda-util

commonly used tools for bda projects, current version 0.1.0

Install

npm install bda-util

Test

npm test

Usage

Logger

An easy way to declare winston daily rotate logger based on local timezone

// option could be a string or an object, if option is a string, it is treated as option.filename

const logger = require('bda-util/winston-rotate-local-timezone').getLogger(option)
  • option
    • filename: base file name of the log file

    • datePattern: A string representing the pattern to be used when appending the date to the filename (default 'yyyy-MM-dd'). The meta characters used in this string will dictate the frequency of the file rotation. For example, if your datePattern is simply 'HH' you will end up with 24 log files that are picked up and appended to every day

    • prepend: Defines if the rolling time of the log file should be prepended at the beginning of the filename (default 'false')

    • localTime: A boolean to define whether time stamps should be local (default 'True' means that Local time will be used)

    • logstash: A boolean to define whether logstash format log will be used (default 'false')

    • padLevels: A boolean to define whether padding should be added to log message (default 'false')

    • handleExceptions: A boolean to define whether uncaught exceptions should be handled by logger instance (default env === 'development' ? false : true)

    • level: log level (default env === 'development' ? 'debug' : 'info')

Mailer

Sendmail

Exports a function that allows you to send email with little effort

// option defines basic configuration of the sender MX server, it can be left blank, which results in using default configuration

const sendMail = require('bda-util/mailer').sendmail(option);
const Html = require('bda-util/mailer').template.Html;
const Table = require('bda-util/mailer').template.Table;

let html = new Html();
let table = new Table();
table.setHeader(['name','sex','age','height','weight','intro'])
	.addRow(['mike','male','25','180','60','smart'])
	.addRow(['patrick','male','25','180','60','strong'])
	.addRow(['honor','male','25','180','60','slim'])

html.append(table)
	.append('<br><p>Just do it!</p>');

sendMail({
	from : "[email protected]", // 如果选择默认配置,必须用[email protected]
	to   : "[email protected]",
	cc   : "[email protected]",
	subject: `Test table template`,
	html : html.toString()
}, (err, res) => {
	if(err) {
		console.log('Send mail failed at %s, err %s', new Date(), err);
	} else {
		console.log('Message sent at %s', new Date());
	}
});
  • option
    • logger: Pass a logger instance to sendmail to enable logging
    • host: Host of sender MX server
    • port: Port of sender MX server
    • auth
      • user: Username of a particular user registered on the sender MX server
      • pass: Password of a particular user registered on the sender MX server

Template

Html

const Html = require('bda-util/mailer').template.Html;

// title defines the title of the html, defualt value is 'This is an Auto Generated Email' if left blank

let html = new Html(title);

html.setTitle('I'm the newly set title')

html.append('<p>I'm a paragraph</p>')
    .append('<p>I'm another paragraph</p>')

console.log(html.toString())

methods are listed as below:

  • setTitle(String title): Set title of the html
  • append(Object element): Element could be anything that has a toString method, all elements appended to the html will be rendered in order
  • toString(): Turn the html object into string

Table

const Html = require('bda-util/mailer').template.Table;

let table = new Table();

table.setHeader(['name','sex','age','height','weight','intro'])
    .addRow(['mike','male','25','180','60','smart'])
	.addRow(['patrick','male','25','180','60','strong'])
	.addRow(['honor','male','25','180','60','slim'])

console.log(table.toString())

methods are listed as below:

  • setHeader(List headers): Set headers of the table
  • addRow(List row): The lenth of row should be the same as that of header
  • toString(): Turn the table object into string