Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mako-utils

makojs15MIT1.0.1

Internal utilities for mako and plugins.

mako, utils, utilities, internal

readme

mako-utils

Internal utilities for mako and plugins.

npm version npm dependencies npm dev dependencies

API

These utilities are used by mako core and plugins internally, but they may be useful to other plugin developers.

relative(to)

Takes the given to absolute path and gives the relative path from pwd.

NOTE: pwd is cached from startup, so this assumes that cwd never changes.

size(input, [raw])

Takes the given input (string/buffer) and returns the actual size in a human-friendly format.

The raw argument can be passed to return the size in a raw Number reflecting the number of bytes.

sizeDiff(a, b)

Takes the given numbers for a and b, computes the delta from a -> b and returns a human-friendly string showing the change.

For example:

console.log(sizeDiff(1000, 1500))
// 1 kB → 1.5 kB (+50%)

console.log(sizeDiff(1000, 250))
// 1 kB → 250 B (-75%)

timer()

Used for timing code with process.hrtime(). A function is returned that will return the time elapsed since the timer was created. (in a human-friendly format)

let timer = utils.timer()

// do stuff...

console.log('finished doing stuff (took %s)', timer())

The returned function has an optional raw argument. When set to true, it will instead return the time elapsed in the raw hrtime array format.

changelog

1.0.0 / 2016-09-19

  • using npm version to make releases
  • adding contributor guidelines
  • cleaning up readme links

0.2.1 / 2016-09-13

  • size: handle falsy values more gracefully

0.2.0 / 2016-09-13

  • add sizeDiff(a, b) fn for showing delta between a and b
  • add size(input, [raw]) for calculating string/buffer byte size

0.1.0 / 2016-08-31

  • return '.' when pwd is identical to relative(to)

0.0.2 / 2016-06-29

  • support pretty-printing elapsed time from timer

0.0.1 / 2016-06-28

:sparkles: