Skip to content

v4.0.0

Latest
Compare
Choose a tag to compare
@blakek blakek released this 03 Dec 16:46

馃殌 聽This release adds several changes to the overall API, greatly updates the TypeScript types (a work-in-progress), updates the build process/output, and more.

馃 Most notable changes:

Partial application is no longer supported with the library as-is. Instead, new create* functions have been introduced to recreate most of that functionality. This should help when overriding expected return types for functions, make some code more easy to understand, and also make maintaining this library a bit simpler. The initial list of added functions includes:

  • createGetter()
  • createHas()
  • createOmit()
  • createPluck()
  • createRemove()
  • createSetter()

The types of most functions has changed a lot. Before, functions like get() would return unknown (or any in some versions). To override required using a type assertion. Now, many return types are retrieved from the object used. It's also easier to explicitly set the return type expected using type arguments:

const user = { username: 'blakek' };

// Before:
const username = get('username', user) as string;

// v4+:
const username = get('username', user); // `string` is inferred from the `user` object
const age = get<number | undefined>('age', user);

getOr() has been removed in favor of adding an optional fallback argument to get(). Similarly, createGetter() also optionally accepts the fallback argument. Note, the order of arguments is different from getOr():

const user =   { username: 'blakek', avatar: '/images/blakek.png' };

// Before:
const avatar = getOr('default.png', 'avatar', user);

// v4+:
const avatar = get('avatar', user, 'default.png');

// also available:
const getAvatar = createGetter('avatar', 'default.png');
const avatar = getAvatar(user);

Full change list: v3.0.0...v4.0.0