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

adenovo-utils

v0.0.7

Published

util methods for adenovo

Downloads

23

Readme

Adenovo utils

Util methods for Adenovo, maybe you can find what utils you want here.

Pid

中華民國身分證字號檢查與產生器, 基於wiki

const {checkPid, genPid} = require('adenovo-utils').pid;

const somePid = genPid(); //'B169298328'
const errorResult = checkPid('dsds'); // { result: false, msg: '身分證字號長度不正確' }

const okResult = checkPid('B169298328'); // { result: true }

Basic log

const {debugLog} = require('adenovo-utils').log;

debugLog('for debug usage');  // [debug] for debug usage

For ELK duration logs:

const {durationLog, startLog, endLog} = require('adenovo-utils').log;

const event = {foo: 'bar', hello: 'world'}; // your event object

durationLog('test')(event); // Lambda Event End: {"foo":"bar","hello":"world"}

startLog(event); // Lambda Event Start: {"foo":"bar","hello":"world"}

endLog(event); // Lambda Event End: {"foo":"bar","hello":"world"}

For ELK action logs (basic)

const {actionLog} = require('adenovo-utils').log;

const event = {foo: 'bar', hello: 'world'};
const payload = {group: 'mygroup', method: 'paySomething', data: event}; // optional: memberId

actionLog('handler')('debug')(payload); // DEV,debug,handler,mygroup,paySomething,{"foo":"bar","hello":"world"}

For ELK action logs (more specific)

Includes:

  • handlerLog(logLevel: string)(payload: object)
  • handlerLogDebug(payload)
  • handlerLogInfo
  • handlerLogWarning
  • handlerLogError
  • modelLog(logLevel: string)(payload: object)
  • modelLogDebug(payload)
  • modelLogInfo
  • modelLogWarning
  • modelLogError

For example:

const {handlerLog, modelLog, handlerLogDebug, modelLogWarning} = require('adenovo-utils').log;

const event = {foo: 'bar'};
const payload = {group: 'mygroup', method: 'paySomething', data: event};

handlerLog('hello')(payload); // DEV,hello,handler,mygroup,paySomething,{"foo":"bar"}
modelLog('world')(payload); // DEV,world,model,mygroup,paySomething,{"foo":"bar"}
handlerLogDebug(payload); // DEV,debug,handler,mygroup,paySomething,{"foo":"bar"}
modelLogWarning(payload); // DEV,warning,model,mygroup,paySomething,{"foo":"bar"}

ELK action log payload wrapping

const {handlerLogInfo, getLogPayload} = require('adenovo-utils').log;

const FUNC_TITLE = 'xxxxPayment';
const logFuncPayload = getLogPayload(FUNC_TITLE);

// ...

const methodName = 'xxxPaymentCallback';
const logPayload = logFuncPayload(methodName);

// ...

const orderInfo = {foo: 'bar'};
const member_id = 1234;
handlerLogInfo(logPayload(orderInfo)(memberId));

Functional utils

const {pipe, pipeAsync, compose, composeAsync} = require('adenovo-utils').functional;

const fn1 = a => a + 2;
const fn2 = a => a * 3;

const resp1 = pipe(fn1, fn2)(3); //  3 -> fn1 -> fn2 , result: 15

const resp2 = compose(fn1, fn2)(3); // 3 -> fn2 -> fn1, result: 11

pipeAsync and composeAsync are async pipe/compose version, you can chain your async functions !

Object utils

removeEmpty will remove the null and undefined entries from an object (will not remove empty string value).

const {isEmpty, removeEmpty} = require('adenovo-utils').obj;

const obj1 = {};
const obj2 = {a: 1, b:2};

const result1 = isEmpty(obj1); // true
const result2 = isEmpty(obj2); // false

const obj3 =  {a:1, b: undefined, c: null, d: 1, e: ''};
const result3 = removeEmpty(a); // { a: 1, d: 1, e: '' }

a {key: key} translator:

const {keyMirror} = require('adenovo-utils').obj;

const arr1 = ['a', 'b'];
keyMirror(arr1);  //{ a: 'a', b: 'b'}

const arr2 = [1, 2];
keyMirror(arr2);  //{ '1': 1, '2': 1}