@coop/utils

1.1.5 • Public • Published

DEPRECATED - Coop Utils

Misc utility functions to use in Coop projects

Part of Coop Trolley

Installation

npm install @coop/utils --save
import utils from '@coop/utils'

Sort Alphabetically

Sort arrays alphabetically.

Usage

utils.sortAlphabetically(array, key, asc = true)

Example

const arr = [ { name: 'foo' }, { name: 'bar' }  ]

const result = utils.sortAlphabetically(arr, 'name')

console.log(result)

// [ { name: 'bar' }, { name: 'foo' }  ]

Emit Event

Cross browser compliant eventEmitter.

Usage

utils.emitEvent(eventName, value = null)

Example

utils.emitEvent('trigger-something')

Debounce

Debounce script to avoid firing tasks to often

Example

const fn = utils.debounce(() => {
	// Do stuff
}, 200);

window.addEventListener('resize', fn);

Source

Dom Helpers

Misc dom helpers to use instead of jQuery

Usage

// Get parsed JSON data stored as data attribute on element
getParsedDomDataFromId(id, dataAttribute)

// Get unparsed data from attribute on element
getDomDataFromId(id, dataAttribute)

// Get each of element
forEachSelector('.class-name', element => {
	// Do stuff with element
})

// Fires when dom is ready
domReady(myFunc)

// Remove class from element
removeClass(targetElement, classToRemove, optionalIndex)

// Returns parsed data from multiple data attributes of element. Will parse JSON if formatted.
getAllDataFromElement(targetElement)

Readme

Keywords

none

Package Sidebar

Install

npm i @coop/utils

Weekly Downloads

2

Version

1.1.5

License

ISC

Unpacked Size

14.4 kB

Total Files

8

Last publish

Collaborators

  • theiscoop