Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Utilities for working with functions in JavaScript, with TypeScript.
(Inspired by functools of the same name)
npm install functools --save
identity<T>(arg: T) => T
Always returns the same value that was used as the argument.
identity(42) //=> 42
memoize<T, U>(fn: (x: T) => U, cache?: Cache) => (x: T) => U
Optimize a function to speed up consecutive calls by caching the result of calls with identical input arguments. The cache can be overridden for features such as an LRU cache.
let i = 0
const fn = memoize(() => ++i)
fn('foo') //=> 1
fn('foo') //=> 1
fn('bar') //=> 2
fn('bar') //=> 2
See also: memoize0
for zero-length function arguments.
prop<K>(key: K) => (obj: T) => T[K]
Return a function that fetches key
from its operand.
prop('foo')({ foo: 123 }) //=> 123
invoke<K, A, T>(key: K, ...args: A) => (obj: T) => ReturnType<T[K]>
Return a function that calls the method name on its operand. If additional arguments are given, they will be given to the method as well.
invoke('add', 5, 5)({ add: (a, b) => a + b }) //=> 10
throttle(fn: () => void, ms: number, leading = true) => () => void
Wrap a function to rate-limit the function executions to once every ms
milliseconds.
let i = 0
const fn = throttle(() => ++i, 100)
fn() // i == 1
fn() // i == 1
fn() // i == 1
setTimeout(() => /* i == 2 */, 200)
Tip: Use fn.clear
and fn.flush
for finer execution control.
fn.clear
Unconditionally clears the current timeoutfn.flush
When fn
is pending, executes fn()
and starts a new intervalThis module uses TypeScript and publishes type definitions on NPM.
Apache 2.0
FAQs
Utilities for working with functions in JavaScript, with TypeScript
The npm package functools receives a total of 17 weekly downloads. As such, functools popularity was classified as not popular.
We found that functools demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.