It’s a small utility library focused on plain-objects, with runtime checks and strong TS inference in the same API. I love TypeScript but the reason I created this is because there many situations where I have to operate outside the safety of the type system and I got tired of constantly having to hard caste my objects to some other type. Additionally, when creating derived object-types I almost always use merge/spread operations but on rare occasions I wanted to avoid ending up with long lists of unused variables or needing multiple lines of code to build new objects from the properties of another (which you can do with `tspo`'s builder functions).
Here are some examples of those situations:
Using a key for an object when the key is dynamic. TypeScript would give `type string cannot be used to index type ...`
Constructing objects of the same or similar type but with bad values for unit-testing so I can verify validation is working.
Create a new object from just a few properties on a larger object.
Snippet:
import tspo from 'tspo';
const user = { id: 1, name: 'Ada' } as const; const out = tspo.safeIndex(user, someDynamicKey); // 'id' | 'name' What it includes:
Accessors/guards: index, safeIndex, reverseIndex, safeReverseIndex, is, isKey, isValue
Object builders: omit, pick, merge, mergeArray, addEntry, addEntries
Object updaters: append, remove
Utilities: copy, compare, iterate
I’d really appreciate feedback on:
API naming edge case
Additional features