@autoguru/utilities
Advanced tools
Comparing version 1.0.64 to 1.0.65
export { wrapEvent } from './wrapEvent'; | ||
export { bindEvent } from './bindEvent'; |
declare type Handler<EventType> = (event: EventType) => void; | ||
export declare const wrapEvent: <E extends Partial<Event>>(callback: Handler<E>, handler?: Handler<E>) => (event: E) => void; | ||
export declare const wrapEvent: <E extends Partial<Event>>(handler: Handler<E>, consumerHandler?: Handler<E>) => (event: E) => void; | ||
export {}; |
export { default as warning } from 'tiny-warning'; | ||
import invariant from 'tiny-invariant'; | ||
export { default as invariant } from 'tiny-invariant'; | ||
@@ -6,11 +7,18 @@ | ||
const wrapEvent = (callback, handler) => (event) => { | ||
if (handler) { | ||
handler(event); | ||
const wrapEvent = (handler, consumerHandler) => (event) => { | ||
invariant(typeof handler === 'function', 'You must supply a handler method.'); | ||
handler(event); | ||
if (!event.defaultPrevented && typeof consumerHandler !== 'undefined') { | ||
invariant(typeof consumerHandler === 'function', 'You supplied a consumer handler that was supposed to be a function.'); | ||
return consumerHandler(event); | ||
} | ||
if (!event.defaultPrevented) { | ||
return callback(event); | ||
} | ||
}; | ||
export { clamp, wrapEvent }; | ||
const bindEvent = (node, event, callback) => { | ||
node.addEventListener(event, callback); | ||
return () => { | ||
node.removeEventListener(event, callback); | ||
}; | ||
}; | ||
export { bindEvent, clamp, wrapEvent }; |
@@ -8,18 +8,26 @@ 'use strict'; | ||
var tinyWarning = _interopDefault(require('tiny-warning')); | ||
var tinyInvariant = _interopDefault(require('tiny-invariant')); | ||
var invariant = _interopDefault(require('tiny-invariant')); | ||
const clamp = (value, min, max) => Math.min(max, Math.max(value, min)); | ||
const wrapEvent = (callback, handler) => (event) => { | ||
if (handler) { | ||
handler(event); | ||
const wrapEvent = (handler, consumerHandler) => (event) => { | ||
invariant(typeof handler === 'function', 'You must supply a handler method.'); | ||
handler(event); | ||
if (!event.defaultPrevented && typeof consumerHandler !== 'undefined') { | ||
invariant(typeof consumerHandler === 'function', 'You supplied a consumer handler that was supposed to be a function.'); | ||
return consumerHandler(event); | ||
} | ||
if (!event.defaultPrevented) { | ||
return callback(event); | ||
} | ||
}; | ||
const bindEvent = (node, event, callback) => { | ||
node.addEventListener(event, callback); | ||
return () => { | ||
node.removeEventListener(event, callback); | ||
}; | ||
}; | ||
exports.warning = tinyWarning; | ||
exports.invariant = tinyInvariant; | ||
exports.invariant = invariant; | ||
exports.bindEvent = bindEvent; | ||
exports.clamp = clamp; | ||
exports.wrapEvent = wrapEvent; |
{ | ||
"name": "@autoguru/utilities", | ||
"version": "1.0.64", | ||
"version": "1.0.65", | ||
"description": "A collection of smallish things that help AutoGuru write code.", | ||
@@ -24,8 +24,8 @@ "homepage": "https://github.com/autoguru-au/octane/tree/master/packages/utilities#readme", | ||
"devDependencies": { | ||
"@autoguru/eslint-plugin": "^1.0.62", | ||
"@autoguru/eslint-plugin": "^1.0.65", | ||
"@autoguru/jest-preset": "^1.0.64", | ||
"@autoguru/tsconfig": "^1.0.63", | ||
"rollup": "^1.19.4", | ||
"rollup-plugin-typescript2": "^0.22.1", | ||
"typescript": "~3.5.3" | ||
"rollup": "^1.20.3", | ||
"rollup-plugin-typescript2": "^0.24.0", | ||
"typescript": "~3.6.2" | ||
}, | ||
@@ -35,3 +35,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "74ab60bd3318a8b81d9e69805cf2959afd4c17fa" | ||
"gitHead": "76af5f4b3377f49e2d011ad597c4420344121b3d" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6451
12
61
1
54