underscore
library
Functions
add (num augend , num addend )
→ num
Adds two numbers.
camelCase (String input )
→ String
Converts a given string to camel case format.
capitalize ([String input = '' ])
→ String
Converts the first character of the given string to uppercase and the remaining
characters to lowercase.
ceil (num number , [int precision = 0 ])
→ num
Computes number
rounded up to precision
.
chunk <T > (List <T > array , [int size = 1 ])
→ List <List <T > >
Creates a new list of chunks of the given array
, each chunk containing
size
number of elements. If the array
cannot be evenly divided into
chunks of size size
, the final chunk will contain the remaining elements.
clamp (num number , num lower , num upper )
→ num
Clamps number
within the inclusive lower
and upper
bounds.
compact <T > (List <T > array )
→ List <T >
Returns a new list with all null, empty, false, or NaN elements removed from the input list.
concat <T > (List <T > array , List values )
→ List <T >
Concatenates a given list array
with one or more dynamic values
.
difference <T > (List <T > array , [List <T > ? values ])
→ List <T >
Returns a new list containing the elements from the original list array
that are not present in the optional values
list.
divide (num dividend , num divisor )
→ num
Divide two numbers.
drop <T > (List <T > array , [int n = 1 ])
→ List <T >
Creates a slice of array
with n
elements dropped from the beginning.
dropRight <T > (List <T > array , [int n = 1 ])
→ List <T >
Creates a slice of array
with n
elements dropped from the end.
endsWith (String string , String target , [int ? position ])
→ bool
Checks if the given string ends with the specified target string.
fill <T > (List <T > array , dynamic value , [int start = 0 , int ? end ])
→ List <T >
Fills elements of a List with a specified value within a given range.
filter (List collection , [Function ? predicate ])
→ List
Returns a new list containing elements of the collection
for which the predicate
function returns true
.
findIndex <T > (List <T > array , [Predicate <T > ? predicate , int fromIndex = 0 ])
→ int
Returns the index of the first element in the list that satisfies the provided
predicate
function. If no such element is found, returns -1.
findLastIndex (List array , [bool predicate (dynamic )?, int fromIndex = -1 ])
→ int
Returns the index of the last element in the array
for which the predicate
function returns true
. If no such element is found, returns -1
.
get (Map <String , dynamic > map , String path , [dynamic defaultValue ])
→ dynamic
Retrieves a value from a nested Map or List structure based on a given
path. If the path does not exist, it returns the provided defaultValue
.
getJsonValue (dynamic json , String path , dynamic defaultValue )
→ Future
Retrieves a value from a nested JSON structure based on a provided path.
groupBy (Iterable collection , [dynamic iteratee ])
→ Map <dynamic , List >
Groups the elements of an Iterable collection based on a specified iteratee
.
indexOf <T > (List <T > array , T value , [int fromIndex = 0 ])
→ int
Gets the index at which the first occurrence of value is found in the array
using SameValueZero for equality comparisons. If fromIndex
is negative,
it's used as the offset from the end of the array.
inRange (num number , [num start = 0 , num ? end ])
→ bool
Checks if number
is between start
and up to, but not including, end
.
isEqual (dynamic value , dynamic other )
→ bool
Performs a deep comparison between two values to determine if they are equivalent.
isInteger (dynamic value )
→ bool
Checks if value
is an integer.
isNullOrBlank (dynamic val )
→ bool
join (List array , dynamic takeVal )
→ String
Joins the elements of an array into a single string using the specified separator.
keys (dynamic object )
→ List <String >
last (List list )
→ dynamic
Gets the last element of a list.
matches (Map <String , dynamic > source )
→ Predicate <Map <String , dynamic > >
Returns a predicate function that checks whether a given map matches the
provided source
map.
matchesProperty <T > (List property )
→ Predicate <T >
Creates a predicate function that checks if a given property of an object
matches a specified value.
parsePath (String path )
→ List
Parses the path string into a list of keys and indices.
property <T > (dynamic path )
→ PropertyAccessor <T >
Creates a property accessor function based on the provided path
.
pull <T > (List <T > array , List <T > values )
→ List <T >
Removes all given values from the array using equality comparisons.
remove <T > (List <T > array , [bool predicate (T )? ])
→ List <T >
Removes all elements from the array
for which the predicate
returns true and returns
a new list containing the removed elements.
removeAt <T > (List <T > list , int index )
→ List <T >
Removes the element at the specified index
from the given List .
reverse <T > (List <T > array )
→ List <T >
Reverses the elements of the given array
in place.
shuffle <T > (List <T > collection )
→ List <T >
Shuffles a list using the Fisher-Yates shuffle algorithm.
size (dynamic collection )
→ int
Returns the size of the given collection
.
slice <T > (List <T > list , [int start = 0 , int ? end ])
→ List <T >
Creates a slice of a list from start up to, but not including, end.
some <T > (Iterable <T > collection , bool predicate (T value , int index , Iterable <T > collection ) )
→ bool
Checks if predicate
returns truthy for any element of collection
.
Iteration is stopped once predicate
returns truthy.
The predicate
is invoked with three arguments: (value, index|key, collection).
sortBy (List <Map <String , dynamic > > collection , List iteratees )
→ List <Map <String , dynamic > >
Sorts a list of maps collection
based on the provided list of iteratees
.
toInteger (dynamic value )
→ int
Converts the given value to an integer.
toNumber (dynamic value )
→ double
Converts the given value to a number.
trim (String str , [String chars = "" ])
→ String
Removes leading and trailing whitespace or specified characters from str
.
uniq <T > (List <T > array )
→ List <T >
Creates a duplicate-free version of an array, using SameValueZero for equality
comparisons, in which only the first occurrence of each element is kept.
The order of result values is determined by the order they occur in the array.
uniqBy <T , V > (List <T > array , V iteratee (T ) )
→ List <T >
Returns a new array with unique elements, where uniqueness is determined
by the result of invoking the provided iteratee
function on each element.
values (dynamic object )
→ List
Returns a list containing all the values of the provided object
's own properties.
words (String string , [RegExp ? pattern ])
→ List <String ? >
Splits the given string
into an array of its words.
zip <T > (List <List <T > > arrays )
→ List <List <T? > >
Creates a list of grouped elements, where each group contains elements
at the same index from the given arrays.
zipObject <K , V > (List <K > keys , List <V > values )
→ Map <K , V >
Creates a new map from the given keys
and values
arrays.
zipWith <R > (List <List > arrays , R iteratee (List ) )
→ List <R >
Combines elements from multiple lists using a provided iteratee
function.
This function is similar to zip
but accepts an iteratee
to specify how grouped
values should be combined. The iteratee
is invoked with the elements of each group: (...group).
Typedefs
PropertyAccessor <T >
= dynamic Function(T object )
A function type for accessing properties of objects of type T
.