import Entry from "../core/Entry" ; import Group from "../core/Group" ; import { objectValues } from "./polyfill" ; import { GroupID } from "../types" ; export enum EntryURLType { Any = "any" , General = "general" , Icon = "icon" , Login = "login" } const URL_PROP = /(^|[a-zA-Z0-9_-]|\b)(ur[li]|UR[LI]|Ur[li])(\b|$|[_-])/ ; const URL_PROP_ICON = /icon[\s_-]*ur[li]/i ; export function getEntryPath ( entry ) { let lastParent = null ; const path = [ ] ; do { lastParent = lastParent ? lastParent . getParentGroup ( ) : entry . getGroup ( ) ; if ( lastParent ) { path . unshift ( lastParent . id ) ; } } while ( lastParent ) ; return path ; } param properties param preference export function getEntryURLs ( properties , preference = EntryURLType . Any ) { const urlRef = Object . keys ( properties ) . filter ( key => URL_PROP . test ( key ) ) . reduce ( ( output , nextKey ) => Object . assign ( output , { [ nextKey ] : properties [ nextKey ] } ) , { } ) ; if ( preference === EntryURLType . General || preference === EntryURLType . Login ) { return Object . keys ( urlRef ) . sort ( ( a , b ) => { if ( preference === EntryURLType . General ) { const general = /^ur[li]$/i ; const aVal = general . test ( a ) ? 1 : 0 ; const bVal = general . test ( b ) ? 1 : 0 ; return bVal - aVal ; } else if ( preference === EntryURLType . Login ) { const login = /login/i ; const aVal = login . test ( a ) ? 1 : 0 ; const bVal = login . test ( b ) ? 1 : 0 ; return bVal - aVal ; } return 0 ; } ) . map ( key => urlRef [ key ] ) ; } else if ( preference === EntryURLType . Icon ) { const iconProp = Object . keys ( urlRef ) . find ( key => URL_PROP_ICON . test ( key ) ) ; return iconProp ? [ urlRef [ iconProp ] ] : [ ] ; } return objectValues ( urlRef ) ; }