Members
# constant filter
filter values in an array
Example
import { filter } from "@nextml/lodestar";
const nonZero = (x) => x !== 0
filter(notZero, [1, 0, 1, 1, 0, 2, 3])
// => [1, 1, 1, 2, 3]
TODO: add more examples...
# constant key
get value of key in object
Example
import { Pick } from "@nextml/lodestar";
Pick.key("foo", { foo: 123 });
// => 123
# constant map
array mapping function
Example
import { map } from "@nextml/lodestar";
map((x) => x + 1, [0, 1, 2])
// => [1, 2, 3]
TODO: add more examples...
# constant match
Takes an object with one (1) key value pair { key: value }
and matches with functions mapped in the conditions
argument.
Example
import { match } from "@nextml/lodestar";
const apiResult = { ok: { name: "foo" } }
match({
ok: success,
error: popup,
})(apiResult)
// => success({ name: "foo" })
# constant Pick
Pick module. Fetch values from objects and arrays. See
"first", "last", "key".
Example
import { Pick } from "@nextml/lodestar";
# constant reduce
reduces array of values
Example
import { reduce } from "@nextml/lodestar";
const add = (x, y) => x + y;
reduce(add, 0, [1, 2, 3]);
// => 6
TODO: add more examples...
# constant trace
Log a value and return the same value
Examples
import { trace } from "@nextml/lodestar";
const sum = trace("foo"); // > "foo"
// => "foo"
import { trace } from "@nextml/lodestar";
fetch("/")
.then(response => response.json())
.then(trace) // log request body
.then(handleData)
# constant updateIn
Update a nested structure by providing a "path"
represented by an array of keys/indices.
Methods
# camelCaseToSnakeCase(x) → {string}
Convert camelCase strings to snake_case.
Parameters:
Name | Type | Description |
---|---|---|
x |
string
|
string to convert |
converted string
string
Example
import { camelCaseToSnakeCase } from "@nextml/lodestar";
camelCaseToSnakeCase("helloWorld"); // => "hello_world"
# capitalize(x) → {string}
Convert the first letter of a string to uppercase and the
rest to lowercase.
Parameters:
Name | Type | Description |
---|---|---|
x |
string
|
string to capitalize |
capitalized string
string
Example
import { capitalize } from "@nextml/lodestar";
capitalize("foo"); // => "Foo"
capitalize("FOO"); // => "Foo"
capitalize("foo bar"); // => "Foo bar"
# compose(…fns) → {function}
Function composition left to right (sequential reading
order).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fns |
function
|
<repeatable> |
functions to compose |
composed function
function
Example
import { compose } from "@nextml/lodestar";
compose(addOne, multiplyByTwo)(2); // => 6
# composeAsync(…fns) → {function}
Asynchronous function composition left to right
(sequential reading order).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fns |
function
|
<repeatable> |
functions to compose, including asynchronous |
composed asynchronous function
function
Example
import { composeAsync } from "@nextml/lodestar";
composeAsync(fetch, doSomething)(url); // => 6
# curry(fn) → {function}
Curry a function to enable partial application.
Parameters:
Name | Type | Description |
---|---|---|
fn |
function
|
the function to curry |
curried function
function
Example
Importing
import { curry } from "@nextml/lodestar";
curry((a, b, c) => a + b + c)(2, 3)(5) // => 10
curry((a, b, c) => a + b + c)(2)(3, 5) // => 10
curry((a, b, c) => a + b + c)(2)(3)(5) // => 10
curry((a, b, c) => a + b + c)(2, 3, 5) // => 10
# defer(fn, …args) → {function}
Defer function execution.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
function
|
the function to defer | |
args |
any
|
<repeatable> |
input arguments for the deferred function `fn` |
constructed function
function
Example
import { defer } from "@nextml/lodestar";
const add = (a, b) => a + b;
const addLater = defer(add, 2, 3);
addLater(); // => 5
# first(xs) → {any}
get first element in array
Parameters:
Name | Type | Description |
---|---|---|
xs |
array
|
array to pick element from |
first element in xs
any
Example
import { Pick } from "@nextml/lodestar";
Pick.first([0, 1, 2])
// => 0
# identity(x) → {any}
Return input value.
Parameters:
Name | Type | Description |
---|---|---|
x |
any
|
any input value |
input value
any
Example
import { identity } from "@nextml/lodestar";
identity(1); // => 1
identity("hello"); // => "hello"
# isDefined(…args) → {boolean}
Check if input arguments have a defined value e.g. is not
null or undefined
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
*
|
<repeatable> |
checked values |
if all input values are defined
boolean
Example
import { isDefined } from "@nextml/lodestar";
isDefined(1); // => true
isDefined("foo", () => {}); // => true
isDefined(undefined); // => false
isDefined(null); // => false
isDefined("foo", null); // => false
# isError(x) → {boolean}
Check if input is instance of any built-in error type.
Parameters:
Name | Type | Description |
---|---|---|
x |
any
|
checked value |
if checked value is error
boolean
Example
import { isError } from '@nextml/lodestar';
isError(new Error('foo')); // true
isError(new TypeError('bar')); // true
isError(1); // false
isError('foo'); // false
isError(false); // false
# isUnitType(x) → {boolean}
Check if input is bottom value.
Parameters:
Name | Type | Description |
---|---|---|
x |
any
|
any input value |
if bottom value
boolean
Example
import { isUnitType } from "@nextml/lodestar";
isUnitType(undefined); // => true
isUnitType(null); // => true
isUnitType(1); // => false
isUnitType("foo"); // => false
# last(xs) → {any}
get last element in array
Parameters:
Name | Type | Description |
---|---|---|
xs |
array
|
array to pick element from |
last element in xs
any
Example
import { Pick } from "@nextml/lodestar";
Pick.last([0, 1, 2])
// => 2
# noop(…_) → {undefined}
Function that ignores the function call
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
_ |
*
|
<repeatable> |
Any input arguments will be ignored |
Returns undefined
undefined
Example
import { noop } from "@nextml/lodestar";
noop("foo") // => undefined
# sideEffect(x) → {any}
Take input, run effect, and return the same input.
Parameters:
Name | Type | Description |
---|---|---|
x |
any
|
any value |
x
any
Example
import { sideEffect } from "@nextml/lodestar";
const logAndReturnName = sideEffect((name) => {
console.log('Hello my name is', name))
};
# snakeCaseToCamelCase(x) → {string}
Convert snake_case strings to camelCase.
Parameters:
Name | Type | Description |
---|---|---|
x |
string
|
string to convert |
converted string
string
Example
import { snakeCaseToCamelCase } from "@nextml/lodestar";
snakeCaseToCamelCase("hello_world"); // => "helloWorld"
# typeOf(x) → {string}
Check input type of defined value.
Parameters:
Name | Type | Description |
---|---|---|
x |
any
|
any non unit type value |
name of type
string
Example
import { typeOf } from "@nextml/lodestar";
typeOf(1); // => "number"
typeOf("hello"); // => "string"
typeOf(false); // => "boolean"
typeOf(() => {}); // => "function"
typeOf([]); // => "array"
typeOf({}); // => "object"
# withEventTargetValue(fn) → {function}
Use event target value point free in event handlers.
Parameters:
Name | Type | Description |
---|---|---|
fn |
function
|
arbitrary function that takes event target value |
that takes javascript event as parameter
function
Example
import { withEventTargetValue } from "@nextml/lodestar";
const SomeComponent = () => {
const [inputValue, setInputValue] = useState('');
return (<input onChange={withEventTargetValue(setInputValue)} />);
}