ts-micro-dict
Functions for representing plain objects as typesafe immutable dictionaries
Getting started
$ npm install ts-micro-dict --save
Usage
// explicitly initialize a Dict with plain object// or infer entry value type with create function console.loginitial // { key: 1 }console.logalt // { key: 1 } // immutability// ERROR - Index signature in type 'Dict<number>' only permits reading:initial = 123// ERROR - Index signature in type 'Dict<number>' only permits reading:delete initial // type safety// ERROR - Type 'number | undefined' is not assignable to type 'number':// OK: // create another Dict by adding an entry to existing Dict console.loganother // { key: 1, test: 123 }console.loginitial // { key: 1 } // create new Dict by removing an entry from existing Dict console.lognewDict // { test: 123 }console.loganother // { key: 1, test: 123 } // converting Dict to readonly array console.logarr // [['key', 1], ['test', 123]] // entries with undefined values will be removed from toArray result console.logDict.toArrayoops // [['key', 1], ['test', 123]] // dict, previously converted to array, can be converted back with fromArrayconsole.logDict.fromArrayDict.toArrayoops // { key: 1, test: 123 } // filterconsole.logDict.filteroops, x > 10 // { test: 123 } // mapconsole.logDict.mapoops, `` // { key: '1', test: '123' }