Socket
Socket
Sign inDemoInstall

@springernature/global-javascript

Package Overview
Dependencies
Maintainers
12
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@springernature/global-javascript - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

__tests__/unit/util/debounce.spec.js

5

HISTORY.md
# History
## 2.2.0 (2020-07-10)
* FEATURE: getCookie util
* FEATURE: throttle util
* FEATURE: debounce util
## 2.1.0 (2020-06-17)

@@ -4,0 +9,0 @@ * FEATURE: createEvent, custom namespaced events

2

package.json
{
"name": "@springernature/global-javascript",
"version": "2.1.0",
"version": "2.2.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Globally shared Javascript helpers",

@@ -20,2 +20,5 @@ # Global Javascript

- [createEvent](#createevent)
- [getCookie](#getcookie)
- [getCookie](#debounce)
- [getCookie](#throttle)

@@ -68,2 +71,38 @@

#### getCookie
Retrieves a cookie by name from `document.cookie`.
```javascript
const myCookie = getCookie('name-of-cookie');
```
#### debounce
Allows sequential calls to a function to be grouped together so that the function will only be called once.
The call will be made once the timeframe has passed after the last call.
The `debounce` function accepts two arguments, `func,` and an options object that accepts `wait` and `immediate`.
`func` is the function to debounce; `wait` is the time (in ms) that should pass after the last function call; `immediate` allows the function to be called once _before_ the timer begins.
`debounce` returns a function and will use `requestAnimationFrame` if no wait time is passed in.
`immediate` defaults to `false`.
Common use cases are when you want to execute a handler only at the end of a series of events, for example when making asynchronous requests in response to a users input.
```javascript
const input = document.querySelector('input.autocomplete');
input.addEventListener('input', debounce(myHandler, {wait: 200, immediate: true}));
```
#### throttle
Allows a function to be called once within a set timeframe. Additional function calls within the timeframe will be ignored.
The `throttle` function accepts two arguments, `func`, which is the function to throttle, and `wait`, which is the duration of the throttle (in ms).
`throttle` returns a function with a default `wait` time of 100.
Common use cases are when you want to consistently execute a handler but at a decreased ratio to the browsers default 1:1, for example scroll and resize event handlers.
```javascript
document.addEventListener('scroll', throttle(myHandler, 200));
```
### Dom

@@ -70,0 +109,0 @@ Dom helpers are used to help achieve JavaScript tasks that involve getting information from, or manipulating the DOM.

// Util
import {makeArray} from './util/make-array';
import {createEvent} from './util/create-event';
import {debounce} from './util/debounce';
import {throttle} from './util/throttle';
import {getCookie} from './util/get-cookie';

@@ -8,2 +11,2 @@ // Dom

export {makeArray, createEvent, getDataOptions};
export {makeArray, createEvent, debounce, throttle, getCookie, getDataOptions};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc