1.1.5 • Published 5 years ago

@coop/utils v1.1.5

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

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)
1.1.5

5 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago