Skip to content

Commit

Permalink
📝 Rewrite the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Sep 28, 2022
1 parent 172a36f commit b1d2f5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/kbn-tinymath/src/functions/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*/

/**
* Returns the default provided value when the first value if null. If at least one array of numbers is passed into the function, the function will be applied index-wise to each element.
* @param {(number|number[])} a a number or an array of numbers
* @param {(number)} b a number to use as fallback value.
* @return {(number|number[])} The `a` value if not null, `b` otherwise. Returns an array where each element is default to `b` when null, or kept the original value if `a` is an array.
* Returns the default provided value when the first value if null. If at least one array is passed into the function, the function will be applied index-wise to each element.
* @param {(any|any[])} a array of any values
* @param {(any)} b a value to use as fallback.
* @return {(any|any[])} The `a` value if not null, `b` otherwise. Returns an array where each element is default to `b` when null, or kept the original value if `a` is an array.
*
* @example
* defaults(null, 1) // returns 1
Expand Down
8 changes: 8 additions & 0 deletions packages/kbn-tinymath/test/functions/defaults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ describe('Defaults', () => {
it('arrays with null, number', () => {
expect(defaults([null, 20, 30, null], 10)).toEqual([10, 20, 30, 10]);
});

it('empty array, number', () => {
expect(defaults([], 10)).toEqual([]);
});

it('skips number validation', () => {
expect(defaults).toHaveProperty('skipNumberValidation', true);
});
});

0 comments on commit b1d2f5f

Please sign in to comment.