Franc

franc

Detect the language of text.

franc is a natural language detection lib that supports 188 languages (1M or more speakers).

Get it: npm install franc

Sample usage:

1
2
3
4
5
var franc = require("franc")

franc("ಮಾನವ ಕುಟುಂಬದ ಸಮಸ್ತ ಸದಸ್ಯರ ಸಹಜ ಗೌರವವನ್ನೂ ಸಮಾನವೂ ಅನನ್ಯಹಾರ್ಯವೂ ಆದ ಹಕ್ಕುಗಳನ್ನು ಅಂಗೀಕರಿಸುವುದು ಪ್ರಪಂಚದಲ್ಲಿ");

// ^ would return "kan" indicating that it's Kannada

GIF FTW!

franc.gif

What-dog

what-dog

What 🐶 is this?

Get the breed of a dog from an image using Microsoft's what-dog.

Get it: npm install --save what-dog

Sample usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
const whatDog = require('what-dog');

((async () => {
    console.log(await whatDog('http://imgur.com/B7a15F5.jpg'))
})());

/*
{
  "isDog": true,
  "breed": "Norfolk Terrier",
  "about": "Spirited, small but sturdy, feisty yet sweet personality"
}
*/

GIF FTW!

what-dog.gif

Signal-exit

signal-exit

Fire an event no matter how a process exits.

signal-exit fires an event no matter how a process exits:

  • reaching the end of execution.
  • explicitly having process.exit(code) called.
  • having process.kill(pid, sig) called.
  • receiving a fatal signal from outside the process

Get it: npm install signal-exit

Sample code:

1
2
3
4
5
var onExit = require('signal-exit')

onExit(function (code, signal) {
  console.log('process exited!', code, signal)
})

GIF FTW!

signal-exit

Scrape-it

scrape-it

scraper for humans.

scrape-it uses cheerio under the hood and makes it easier to scrape websites.

Get it: npm install [-g] scrape-it

Sample usage:

1
2
3
4
5
6
7
const scrapeIt = require("scrape-it")

scrapeIt("https://nmotw.in", {tagLine: ".tagline"})
.then(scraped => console.log(scraped.data))
.catch(console.error)

// ^ {tagLine: "Node Mode Of The Week"}

GIF FTW

scrape-it.gif

Global-cache

global-cache

Use global object as a share singleton.

From the 🐴's mouth -> Sometimes you have to do horrible things, like use the global object to share a singleton. Abstract that away, with this!

global-cache attaches a cache to the global object. It attempts to make it as undiscoverable as possible:

  • uses Symbols if available

  • if not, uses a string key that is not a valid identifier, so as not to show up in dot-notation browser autocomplete

  • makes it non-enumerable if property descriptors are supported

  • keys are required to be strings or symbols.

Get it: npm install global-cache

Sample usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let value = {}, key='key';
const cache = require('global-cache');

[cache.get(key), cache.has(key)]; //[ undefined, false ]

cache.set(key,value); //true

[cache.get(key), cache.has(key)]; //[ {}, true ]

cache.delete(key); // true

[cache.get(key), cache.has(key)]; // [ undefined, false ]

cache
/*
{ clear: [Function: clear],
  delete: [Function: deleteKey],
  get: [Function: get],
  has: [Function: has],
  set: [Function: set],
  setIfMissingThenGet: [Function: setIfMissingThenGet] }
*/

GIT FTW!

global-cache.gif

Dayjs

dayjs

⏰ Fast 2KB immutable date library.

dayjs is a minimalist JavaScript library for modern browsers with a largely Moment.js-compatible API, with:

🕒 Familiar Moment.js API & patterns 💪 Immutable 🔥 Chainable 📦 2kb mini library 👫 All browsers support

Get it: npm install dayjs

Sample usage:

1
2
3
4
5
6
7
const dayjs = require('dayjs');

dayjs()
.startOf('month')
.add(1, 'day')
.set('year', 2018)
.format('YYYY-MM-DD HH:mm:ss');

GIF FTW!

dayjs

Tiny-glob

tiny-glob

Match files and dirs using glob patterns.

tiny-glob is 🔥 extremely fast, 💪 powerful, 📦 tiny util to match files and folders using glob patterns.

Get it: npm install tiny-glob

Sample usage:

1
2
3
4
5
6
const glob = require('tiny-glob');

(async function(){
    let files = await glob('src/*/*.{js,md}');
    // => [ ... ] array of matching files
})();

Benchmark results:

1
2
3
4
5
6
7
8
9
10
11
12
13
glob x 13,405 ops/sec ±1.80% (85 runs sampled)
fast-glob x 25,745 ops/sec ±2.76% (59 runs sampled)
tiny-glob x 102,658 ops/sec ±0.79% (91 runs sampled)
Fastest is tiny-glob
┌───────────┬─────────────────────────┬─────────────┬────────────────┐
│ Name      │ Mean time               │ Ops/sec     │ Diff           │
├───────────┼─────────────────────────┼─────────────┼────────────────┤
│ glob      │ 0.00007459990597268128  │ 13,404.843  │ N/A            │
├───────────┼─────────────────────────┼─────────────┼────────────────┤
│ fast-glob │ 0.000038842529587611705 │ 25,744.976  │ 92.06% faster  │
├───────────┼─────────────────────────┼─────────────┼────────────────┤
│ tiny-glob │ 0.00000974110141018254  │ 102,657.796 │ 298.75% faster │
└───────────┴─────────────────────────┴─────────────┴────────────────┘

GIF FTW!

tiny-glob

A11y

a11y

Easy accessibility audits powered by the Chrome Accessibility Tools

a11y conducts audits using the Chrome Accessibility Tools and PhantomJS and lists out the issues for a given URL.

Get it: npm install [-g] a11y

Sample CLI usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  Runs an accessibility audit against a URL

  Usage
    $ a11y <url>

  Options
    --viewport-size=<size>  Set the viewport size
    --delay                 Set the delay capturing the page
    --verbose               Display more information

  Examples
    $ a11y todomvc.com
    $ a11y http://todomvc.com https://google.com
    $ a11y index.html -=viewport-size=1024x768

Sample API usage:

1
2
3
4
5
6
const a11y = require('a11y');

a11y('nmotw.in', (err, reports) => {
    const audit = reports.audit; // `a11y` Formatted report
    const report = reports.report; // DevTools Accessibility Audit formatted report
});

GIF FTW

a11y.gif

Cryptiles

cryptiles

General purpose crypto utilities.

cryptiles provides util methods for creating cryptographically strong pseudo-random data with the below methods:

  • fixedTimeComparison
  • randomBits
  • randomDigits
  • randomString

Get it: npm install cryptiles

Sample usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const cryptiles = require("cryptiles");
[
cryptiles.fixedTimeComparison('abcd','abcd'),
cryptiles.randomBits(5),
cryptiles.randomDigits(5),
cryptiles.randomString(5)
]

/* ^
[
  true,
  Uint8Array <66>,
  "42115",
  "jsmx9"
]
*/

GIF FTW!

cryptiles

April-fools

april-fools

Randomly fool with an Error on April 1st.

⚠️ This is a foolproof way to lose friends and alienate people. Will likely get you fired!

Few lines of code to have fun on April fools day:

1
2
3
4
5
6
7
8
9
'use strict'

const date = new Date()

if (date.getMonth() === 3 && date.getDate() === 1 && Math.floor(Math.random() * 6) + 1 === 1) {
  const message = require('sentencer').make("Unexpected  with  ")

  throw new Error(message)
}

Related module -> sentencer.

Sample usage:

1
2
3
4
5
6
7
8
9
10
11
require('april-fools'); // That's it! And it would randomly throw an error like below.

Error: Unexpected lunch with a brindle ravioli
    at Object.<anonymous> (/private/tmp/node_modules/april-fools/index.js:8:9)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

GIF FTW

april-fools