UNPKG

repoweaver

Version:

A GitHub App that skillfully weaves multiple templates together to create and update repositories with intelligent merge strategies

1 lines 4.03 kB
{"ast":null,"code":"export function splitStyles(styles, ...filters) {\n if (process.env.NODE_ENV !== 'production' && filters.length === 0) {\n console.error('No filters were passed when calling splitStyles');\n }\n const newStyles = filters.map(() => []);\n const rest = [];\n outer: for (const item of Object.entries(styles)) {\n for (let i = 0; i < filters.length; i++) {\n if (filters[i](item[0])) {\n newStyles[i].push(item);\n continue outer;\n }\n }\n rest.push(item);\n }\n newStyles.unshift(rest);\n return newStyles.map(styles => Object.fromEntries(styles));\n}","map":{"version":3,"names":["splitStyles","styles","filters","process","env","NODE_ENV","length","console","error","newStyles","map","rest","outer","item","Object","entries","i","push","unshift","fromEntries"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/react-native-paper/src/utils/splitStyles.ts"],"sourcesContent":["import type { ViewStyle } from 'react-native';\n\ntype FiltersArray = readonly ((style: keyof ViewStyle) => boolean)[];\n\ntype MappedTuple<Tuple extends FiltersArray> = {\n [Index in keyof Tuple]: ViewStyle;\n} & { length: Tuple['length'] };\n\ntype Style = ViewStyle[keyof ViewStyle];\ntype Entry = [keyof ViewStyle, Style];\n\n/**\n * Utility function to extract styles in separate objects\n *\n * @param styles The style object you want to filter\n * @param filters The filters by which you want to split the styles\n * @returns An array of filtered style objects:\n * - The first style object contains the properties that didn't match any filter\n * - After that there will be a style object for each filter you passed in the same order as the matching filters\n * - A style property will exist in a single style object, the first filter it matched\n */\nexport function splitStyles<Tuple extends FiltersArray>(\n styles: ViewStyle,\n ...filters: Tuple\n) {\n if (process.env.NODE_ENV !== 'production' && filters.length === 0) {\n console.error('No filters were passed when calling splitStyles');\n }\n\n // `Object.entries` will be used to iterate over the styles and `Object.fromEntries` will be called before returning\n // Entries which match the given filters will be temporarily stored in `newStyles`\n const newStyles = filters.map(() => [] as Entry[]);\n\n // Entries which match no filter\n const rest: Entry[] = [];\n\n // Iterate every style property\n outer: for (const item of Object.entries(styles) as Entry[]) {\n // Check each filter\n for (let i = 0; i < filters.length; i++) {\n // Check if filter matches\n if (filters[i](item[0])) {\n newStyles[i].push(item); // Push to temporary filtered entries array\n continue outer; // Skip to checking next style property\n }\n }\n\n // Adds to rest styles if not filtered\n rest.push(item);\n }\n\n // Put unmatched styles in the beginning\n newStyles.unshift(rest);\n\n // Convert arrays of entries into objects\n return newStyles.map((styles) => Object.fromEntries(styles)) as unknown as [\n ViewStyle,\n ...MappedTuple<Tuple>\n ];\n}\n"],"mappings":"AAqBA,OAAO,SAASA,WAAWA,CACzBC,MAAiB,EACjB,GAAGC,OAAc,EACjB;EACA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;IACjEC,OAAO,CAACC,KAAK,CAAC,iDAAiD,CAAC;EAClE;EAIA,MAAMC,SAAS,GAAGP,OAAO,CAACQ,GAAG,CAAC,MAAM,EAAa,CAAC;EAGlD,MAAMC,IAAa,GAAG,EAAE;EAGxBC,KAAK,EAAE,KAAK,MAAMC,IAAI,IAAIC,MAAM,CAACC,OAAO,CAACd,MAAM,CAAC,EAAa;IAE3D,KAAK,IAAIe,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGd,OAAO,CAACI,MAAM,EAAEU,CAAC,EAAE,EAAE;MAEvC,IAAId,OAAO,CAACc,CAAC,CAAC,CAACH,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;QACvBJ,SAAS,CAACO,CAAC,CAAC,CAACC,IAAI,CAACJ,IAAI,CAAC;QACvB,SAASD,KAAK;MAChB;IACF;IAGAD,IAAI,CAACM,IAAI,CAACJ,IAAI,CAAC;EACjB;EAGAJ,SAAS,CAACS,OAAO,CAACP,IAAI,CAAC;EAGvB,OAAOF,SAAS,CAACC,GAAG,CAAET,MAAM,IAAKa,MAAM,CAACK,WAAW,CAAClB,MAAM,CAAC,CAAC;AAI9D","ignoreList":[]},"metadata":{"hasCjsExports":false},"sourceType":"module","externalDependencies":[]}