import * as _ from 'lodash' ; /**
 * Takes a predicate function and returns a negated version.
 */ export function not ( predicate ) { return ( ... args ) => ! predicate ( ... args ) ; } /**
 * Returns a predicate function which returns true if the item is found in the set,
 * as determined by a === equality check on the given compareBy property.
 */ export function foundIn < T > ( set , compareBy ) { return ( item ) => set . some ( t => t [ compareBy ] === item [ compareBy ] ) ; } /**
 * Indentity function which asserts to the type system that a promise which can resolve to T or undefined
 * does in fact resolve to T.
 * Used when performing a "find" operation on an entity which we are sure exists, as in the case that we
 * just successfully created or updated it.
 */ export function assertFound < T > ( promise ) { return promise as Promise < T > ; } /**
 * Compare ID values for equality, taking into account the fact that they may not be of matching types
 * (string or number).
 */ /**
 * Returns the AssetType based on the mime type.
 */ /**
 * A simple normalization for email addresses. Lowercases the whole address,
 * even though technically the local part (before the '@') is case-sensitive
 * per the spec. In practice, however, it seems safe to treat emails as
 * case-insensitive to allow for users who might vary the usage of
 * upper/lower case. See more discussion here: https://ux.stackexchange.com/a/16849
 */ export function normalizeEmailAddress ( input ) { return input . trim ( ) . toLowerCase ( ) ; } export interface IFilterConfig { filterKey ? : any ; cleanMeta ? : boolean ; } param list param config export function formatAllMeta ( list , config ? ) { const items = [ ] ; for ( const item of ( config && config . filterKey ? _ . map ( list , config . filterKey ) : list ) ) { item . meta = { } ; if ( _ . has ( item , 'metas' ) && item . metas . length > 0 ) { _formatMeta ( item , config && config . cleanMeta ) ; } items . push ( item ) ; } return items ; } param item param config export function formatOneMeta ( item , config ? ) { item = config && config . filterKey ? _ . get ( item , config . filterKey ) : item ; item . meta = { } ; if ( _ . has ( item , 'metas' ) && item . metas . length > 0 ) { _formatMeta ( item , config && config . cleanMeta ) ; } return item ; } function _formatMeta ( item , clean ? ) { for ( const meta of item . metas ) { if ( meta . key . includes ( '_capabilities' ) ) { item = Object . assign ( item , meta . value ) ; } if ( meta . key . includes ( '_wechat' ) ) { const wechat = meta . value ; item = Object . assign ( item , { avatarUrl : wechat . avatarUrl , } ) ; } if ( meta . key . includes ( '_liked_posts' ) ) { item . liked = meta . value ; } item . meta [ meta . key ] = meta . value ; } Reflect . deleteProperty ( item , 'metas' ) ; clean && Reflect . deleteProperty ( item , 'meta' ) ; }