Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
@types/underscore
Advanced tools
@types/underscore provides TypeScript type definitions for the Underscore.js library, which is a utility-belt library for JavaScript that provides a lot of the functional programming support you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
Array Operations
Underscore provides a variety of functions to manipulate arrays, such as map, filter, reduce, and more. In this example, the map function is used to double each number in the array.
const _ = require('underscore');
const numbers = [1, 2, 3, 4, 5];
const doubled = _.map(numbers, (num) => num * 2);
console.log(doubled); // [2, 4, 6, 8, 10]
Object Operations
Underscore offers several functions to work with objects, such as keys, values, extend, and more. This example demonstrates the keys function, which retrieves all the keys of an object.
const _ = require('underscore');
const person = { name: 'John', age: 30, job: 'Developer' };
const keys = _.keys(person);
console.log(keys); // ['name', 'age', 'job']
Utility Functions
Underscore includes various utility functions like identity, constant, noop, and more. The every function checks if all elements in an array pass a given predicate function.
const _ = require('underscore');
const isEven = (num) => num % 2 === 0;
const result = _.every([2, 4, 6], isEven);
console.log(result); // true
Function Operations
Underscore provides functions to manipulate other functions, such as bind, debounce, throttle, and more. The once function ensures a function is only called once.
const _ = require('underscore');
const greet = (name) => `Hello, ${name}!`;
const greetOnce = _.once(greet);
console.log(greetOnce('John')); // 'Hello, John!'
console.log(greetOnce('Jane')); // undefined
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It is similar to Underscore but offers more features and better performance.
Ramda is a practical functional library for JavaScript programmers. It focuses on immutability and side-effect-free functions, providing a more functional approach compared to Underscore.
Lazy.js is a utility library similar to Underscore and Lodash but with a lazy evaluation approach, which can lead to performance improvements in certain scenarios.
npm install --save @types/underscore
This package contains type definitions for Underscore (http://underscorejs.org/).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/underscore
Additional Details
These definitions were written by Boris Yankov https://github.com/borisyankov, Josh Baldwin https://github.com/jbaldwin, Christopher Currens https://github.com/ccurrens, Ard Timmerman https://github.com/confususs, Julian Gonggrijp https://github.com/jgonggrijp, Florian Keller https://github.com/ffflorian, and Regev Brody https://github.com/regevbr.
FAQs
TypeScript definitions for underscore
The npm package @types/underscore receives a total of 603,553 weekly downloads. As such, @types/underscore popularity was classified as popular.
We found that @types/underscore demonstrated a healthy version release cadence and project activity because the last version was released less than 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
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.