license /**
 * Simple utility function used to find an item in a set with a predicate
 * function.  Analagous to Array.find(), without requiring converting the set
 * an Array.
 */ export function find < T > ( items , predicate ) { for ( const item of items ) { if ( predicate ( item ) ) { return item ; } } } /**
 * Converts string like `abc-xyz__omg` to `abcXyzOmg`.
 */ export function camelCase ( text ) { return text . replace ( /([a-z0-9])[^a-z0-9]+([a-z])/gi , ( m ) => m [ 0 ] + m [ 2 ] . toUpperCase ( ) ) ; } /**
 * Returns a set of unique/distinct values returned by calling the given
 * function on each item.
 */ export function uniq < T , R > ( items , map ) { const results = new Set ( ) ; for ( const item of items ) { results . add ( map ( item ) ) ; } return results ; } /**
 * Returns a map of arrays of items, with keys generated by the keygen function.
 */ export function partitionMap < K , V > ( items , keygen ) { const map = new Map < K , V [ ] > ( ) ; for ( const item of items ) { const key = keygen ( item ) ; const partition = map . get ( key ) || [ ] ; if ( ! map . has ( key ) ) { map . set ( key , partition ) ; } partition . push ( item ) ; } return map ; } /**
 * Performs an in-place rewrite of a target object's properties from a given
 * replacement node.  This is useful because there are some transformations
 * of ASTs which simply require replacing a node, but it is not always
 * convenient to obtain the specific parent node property to which a node may be
 * attached out of many possible configurations.
 */ export function rewriteObject ( target , replacement ) { for ( const key of Object . getOwnPropertyNames ( target ) ) { if ( ! replacement . hasOwnProperty ( key ) ) { delete target [ key ] ; } } for ( const key of Object . getOwnPropertyNames ( replacement ) ) { target [ key ] = replacement [ key ] ; } }