lodash APIs
- get
- isEmpty
- cloneDeep
- debounce
- omit
- isEqual
- find
- merge
- map
- filter
- throttle
- sortBy
- set
- isString
- isArray
- pick
- orderBy
- groupBy
- includes
- isObject
- noop
- findIndex
- isFunction
- isNil
- uniqueId
- pickBy
- uniq
- kebabCase
- without
- camelCase
- isNumber
- uniqBy
- isUndefined
- capitalize
- clone
- range
- omitBy
- remove
- forIn
- forEach
- reduce
- flatten
- zipObject
- mapValues
- concat
- trim
- castArray
- difference
- memoize
- keyBy
- assign
- each
- upperFirst
- chain
- sample
- isPlainObject
- has
- mapKeys
- isNull
- last
- isBoolean
- identity
- padStart
- head
- size
- conformsTo
- mergeWith
- transform
- uniqWith
- union
- toString
- reject
- snakeCase
- max
- min
- reverse
- slice
- isInteger
- startsWith
- first
- sumBy
- maxBy
- minBy
- _
- xor
- replace
- take
- endsWith
- toLower
- clamp
- toPairs
- some
- extend
- times
- flattenDeep
- escapeRegExp
- shuffle
- round
- toInteger
- isNaN
- unset
- VERSION
- nth
- flow
- sum
- isFinite
- values
- lowerCase
- deburr
- isEqualWith
- cloneDeepWith
- hasIn
- findLast
- findKey
- differenceBy
- pull
- findLastIndex
- partition
- at
- defer
- intersectionBy
- invert
- delay
- forOwn
- pullAt
- once
- sampleSize
- random
- defaults
- unescape
- keys
- toNumber
- wrap
- inRange
- join
- template
- split
- words
- toSafeInteger
- pullAllBy
- unionWith
- xorBy
- differenceWith
- indexOf
- multiply
- divide
- every
- toPath
- defaultTo
- isObjectLike
- intersection
- startCase
- sortedIndexBy
OtherRelated APIs
lodash#clamp JavaScript Examples
The following examples show how to use
lodash#clamp.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From holo-schedule with MIT License | 6 votes |
normalize = (arrayOfObjects, ...keys) => keys.reduce((accu, key) => {
const filteredValues = accu.map(({ [key]: value }) => value).filter(Boolean)
const minValue = min(...filteredValues)
const maxValue = max(...filteredValues)
return accu.map(object => ({
...object,
[key]: filteredValues.length && minValue !== maxValue
? ((clamp(object[key], minValue, maxValue) - minValue) / (maxValue - minValue))
: 1,
}))
}, arrayOfObjects)
Example #2
Source File: zoomable-canvas.js From ThreatMapper with Apache License 2.0 | 6 votes |
zoomAtPositionByFactor(position, factor) {
// Update the scales by the given factor, respecting the zoom limits.
const { minScale, maxScale } = this.state;
const scaleX = clamp(this.state.scaleX * factor, minScale, maxScale);
const scaleY = clamp(this.state.scaleY * factor, minScale, maxScale);
let state = { ...this.state, scaleX, scaleY };
// Get the position in the coordinates before the transition and use it
// to adjust the translation part of the new transition (respecting the
// translation limits). Adapted from:
// https://github.com/d3/d3-zoom/blob/807f02c7a5fe496fbd08cc3417b62905a8ce95fa/src/zoom.js#L251
const inversePosition = inverseTransform(this.state, position);
state = this.clampedTranslation({
...state,
translateX: position.x - (inversePosition.x * scaleX),
translateY: position.y - (inversePosition.y * scaleY),
});
this.updateState(state);
}