HexagonJS
Edit Page
Filter
A utility for filtering data using various methods such as 'exact' and 'contains'
Examples
stringArray = [
  'Steve 34',
  'Kate 56',
  'Dave 12',
  'Steve 12',
  'Bob 78',
  'Alejandro 90'
]
hx.filter.contains(stringArray, 've') // returns ['Dave 12', 'Steve 12', 'Steve 34'];
hx.filter.startsWith(stringArray, 's') // returns ['Steve 12', 'Steve 34'];
hx.filter.exact(stringArray, 'Bob') // returns [];
hx.filter.exact(stringArray, 'Bob 78') // returns ['Bob 78'];
hx.filter.fuzzy(stringArray, 'e1') // returns ['Dave 12', 'Steve 12'];
Api
Objects
hx.filterdeprecated
Deprecated
The filter object has been replaced by specific filter methods directly on the hx object.
An object containing different methods for filtering arrays.
Functions
containsarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that contain a search term.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filter.contains(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filter.contains(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
exactarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that match a search term exactly.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filter.exact(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filter.exact(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
excludesarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that are don't contain a search term.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filter.excludes(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filter.excludes(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
fuzzyarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that contain the letters in a search term in the same order but not necessarily directly after each other.
array = ['Bob Stevenson', 'Steve Stevenson', 'Dave Peters']
hx.filter.fuzzy(array, 'ss') // returns ['Steve Stevenson', 'Bob Stevenson'] as the match in Steve Stevenson is stronger.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filter.fuzzy(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filter.fuzzy(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
greaterarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that are greater than or equal to a search term.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filter.greater(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filter.greater(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
lessarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that are less than or equal to a search term.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filter.less(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filter.less(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
numberTypesArray[String]
A function that returns the filter types that can be used when filtering numbers:
[
  'exact',
  'greater',
  'less'
]
Returns
The array of number filter types
regexarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values using a regular expression.
Arguments
arrayArray
The array to filter
termString
The regular expression to filter with. It must be a regular expression string or object:
/bob/ //RegEx string
new RegExp('bob') // RegEx Object
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filter.regex(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filter.regex(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
startsWitharrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that start with a search term.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filter.startsWith(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filter.startsWith(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
stringTypesArray[String]
A function that returns the filter types that can be used when filtering strings:
[
  'contains',
  'exact'
  'excludes',
  'startsWith'
  'regex',
  'fuzzy'
]
Returns
The array of string filter types
A function that returns all the filter types:
[
  'contains',
  'exact'
  'greater',
  'less',
  'excludes',
  'startsWith'
  'regex',
  'fuzzy'
]
Returns
The array of all filter types
Functions
filterContainsarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that contain a search term.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filterContains(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filterContains(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
filterExactarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that match a search term exactly.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filterExact(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filterExact(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
filterExcludesarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that are don't contain a search term.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filterExcludes(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filterExcludes(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
filterFuzzyarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that contain the letters in a search term in the same order but not necessarily directly after each other.
array = ['Bob Stevenson', 'Steve Stevenson', 'Dave Peters']
hx.filterFuzzy(array, 'ss') // returns ['Steve Stevenson', 'Bob Stevenson'] as the match in Steve Stevenson is stronger.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filterFuzzy(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filterFuzzy(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
filterGreaterarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that are greater than or equal to a search term.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filterGreater(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filterGreater(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
filterLessarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that are less than or equal to a search term.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filterLess(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filterLess(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
filterNumberTypesArray[String]
A function that returns the filter types that can be used when filtering numbers:
[
  'exact',
  'greater',
  'less'
]
Returns
The array of number filter types
filterRegexarrayArraytermStringoptionsObjectArray
A function that allows filtering of array values using a regular expression.
Arguments
arrayArray
The array to filter
termString
The regular expression to filter with. It must be a regular expression string or object:
/bob/ //RegEx string
new RegExp('bob') // RegEx Object
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filterRegex(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filterRegex(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
filterStartsWitharrayArraytermStringoptionsObjectArray
A function that allows filtering of array values that start with a search term.
Arguments
arrayArray
The array to filter
termString
The term to filter on
options
The options to use when filtering
Properties
caseSensitiveBoolean
Whether the filtering should be case sensitive.
Default: false
searchValuesitemAnyArray
A function used to return values to allow searching on properties within objects or nested arrays. To search object properties, each property must be returned in an array:
array = [
  {
    name: 'Bob',
    age: 12
  }
  ...
];
getValues = function(item){
  return [item.name, item.age] // would return ['Bob', 12] for the selected array
};
hx.filterStartsWith(array, 'bob', {searchValues: getValues});
Nested arrays can also be searched by returning the item itself as the array:
array = [
  ['Bob', 12]
  ...
];
getValues = function(item){
  return item;
};
hx.filterStartsWith(array, 'bob', {searchValues: getValues});
Arguments
itemAny
The item from the array passed into hx.filter
Returns
an array of values that should be searched when filtering/sorting
Whether to sort the results.
Default: true
Returns
The filtered/sorted array
filterStringTypesArray[String]
A function that returns the filter types that can be used when filtering strings:
[
  'contains',
  'exact'
  'excludes',
  'startsWith'
  'regex',
  'fuzzy'
]
Returns
The array of string filter types
filterTypesArray[String]
A function that returns all the filter types:
[
  'contains',
  'exact'
  'greater',
  'less',
  'excludes',
  'startsWith'
  'regex',
  'fuzzy'
]
Returns
The array of all filter types