import * as path from 'path' ; import { StructorConfig } from './define' ; export const pipeEvent = ( func ) => { return ( event ) => { return func ( event . target . value , event ) ; } ; } ; export function ensureEndWithSlash ( str ) { if ( str . endsWith ( '/' ) ) { return str ; } return `${ str }/` ; } export function ensureStartWithSlash ( str ) { if ( str . startsWith ( '/' ) ) { return str ; } return `/${ str }` ; } export function ensureStartWithWebpackRelativePoint ( str ) { if ( str . startsWith ( '/' ) ) { throw Error ( `${ str } is an absolute path!` ) ; } if ( ! str . startsWith ( './' ) && ! str . startsWith ( '../' ) ) { return `./${ str }` ; } return str ; } export function safeJsonParse ( text ) { try { return JSON . parse ( text ) ; } catch { return { } ; } } export function matchStructor ( file , target , prefixPath ) { const fileAbsolutePath = path . format ( file ) ; if ( ! target . name && ! target . ext ) { return fileAbsolutePath . startsWith ( path . join ( prefixPath , target . dir ) ) ; } return fileAbsolutePath === path . join ( prefixPath , path . format ( target ) ) ; }