@aoeu/util
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

@aoeu/util

This is a small collection of JavaScript utility functions for reuse across projects.

yarn add @aoeu/util

Available functions and their use

These are the utility functions that are available in this package with a brief overview of their functionality and an example of their usage.

isEmpty

Returns true if the given argument evaluates to either undefined, null or an empty string (""), or in the case of an Array, when the given array's length attribute returns 0.

var foo = null

isEmpty(foo) // <- true

foo = undefined

isEmpty(foo) // <- true

foo = "bar"

isEmpty(foo) // <- false

foo = []

isEmpty(foo) // <- true

foo = ["bar"]

isEmpty(foo) // <- false

isNotEmpty

Returns the inverse of the isEmpty function above. Literally returns !isEmpty(arg).

withWindow

Takes a single callback argument and provides the current window instance to the callback if it is available. This function is useful in Server-Side Render (SSR) environments where the browser window object may not always be available, and you wish to perform some functionality when it is available, but safely ignore it when it is not.

withWindow(window => {
  // do something here with the `window` object
  // this function will NOT be executed when the
  // `window` object is not available
})

writeToClipboard

Takes a single argument (content) that will be written to the clipboard in browsers that support the navigator.clipboard interface.

writeToClipboard("this is fun")

Readme

Keywords

none

Package Sidebar

Install

npm i @aoeu/util

Weekly Downloads

16

Version

0.0.2

License

MIT

Unpacked Size

9.25 kB

Total Files

12

Last publish

Collaborators

  • theantichris
  • thomas.jean
  • ryexley