Time for a fun module this week, it's covfefe. (Hope you are aware of it!)
Get it:npm install covfefe
Sample usage:
1234567
>constcovfefe=require('covfefe');>covfefe('Despite the constant negative press');"Despite the constant negative press covfefe">covfefe.translate('I have good coverage of spray tan');"I have good covfefe of spray tan"
nif is for all the lazy folks trying to debug their node script, it runs the node --inspect on the provided file and open the devtool URL chrome-devtools://.
Make sure you have the chrome-cli installed on your machine,before using this moddule.
Mock Date object that can be used to change when "now" is.
mockdate the names says it all!
This module save the current date context to _date and _getTimezoneOffset = Date.prototype.getTimezoneOffset internally and overwrites them with simpler custom implementation which would useful for unit tests et.al
What is this and why does it matter? [From the horse's mouth]
Protocol Buffers are awesome. Having schemas to deflate and inflate data while maintaining some kind of validation is a great concept.
Compactr's goal is to build on that to better suit Node development and reduce repetition by allowing you to build schemas for your data directly in your scripting language.
For example, if you have a DB schema for a model, you could use that directly as a schema for Compactr.
constCompactr=require('compactr');// Defining a schemaconstuserSchema=Compactr.schema({id:{type:'number'},name:{type:'string'}});// EncodinguserSchema.write({id:123,name:'John'});// Get the schema header bytes (for partial loads)constheader=userSchema.headerBytes();// Get the partial load bytesconstpartial=userSchema.contentBytes();// Get the full header + content bytesconstbuffer=userSchema.bytes();// Decoding (full)constcontent=userSchema.decode(buffer);// Decoding (partial)constcontent=userSchema.decode(header,partial);
A straightforward date and time formatter in 800b.
Get it:npm install --save tinytime
tinytime exports a single function that returns a template object. This object has a single method, render, which
takes a Date and returns a string with the rendered data.
1234
importtinytimefrom'tinytime';consttemplate=tinytime('The time is {h}:{mm}:{ss}{a}.');template.render(newDate());// The time is 11:10:20PM.
varsec=newSecK({secret:'BEGIN RSA',// Text of key used for encrypting/decrypting format:JSON,// optional (defaults to JSON): An object with `stringify` and `parse` methods alg:'aes-256-ctr'//optional (this is default) Algorithm to use for encrypt/decrypt });
A global utility for tracking the current input method (mouse, keyboard or touch).
What Input adds data attributes to the tag based on the type of input being used.
It also exposes a simple API that can be used for scripting interactions.
GET IT:npm install --save what-input
Sample usage:
123456789101112131415
whatInput.ask();// returns `mouse`, `keyboard` or `touch`whatInput.types();// ex. returns ['mouse', 'keyboard']whatInput.ask('loose');// returns `mouse` because mouse movement was detectedmyButton.addEventListener('click',function(){if(whatInput.ask()==='mouse'){// do mousy things}elseif(whatInput.ask()==='keyboard'){// do keyboard things}});
Event mapping:
1234567891011
// mapping of events to input typesconstinputMap={'keyup':'keyboard','mousedown':'mouse','mousemove':'mouse','MSPointerDown':'pointer','MSPointerMove':'pointer','pointerdown':'pointer','pointermove':'pointer','touchstart':'touch'};