import gitPath from "git-config-path" ; import { sync as parseGitConfig } from "parse-git-config" ; import os from "os" ; import path from "path" ; import { cfg } from "." ; /**
 * Test if a string is a valid npm package name.
 * Sort of a port of is-valid-npm-name but without the dependencies
 */ export function isNpmPackageName ( str ) { return ! ( ( ! str || str . trim ( ) !== str || str . length > 214 || [ "." , "_" ] . includes ( str [ 0 ] ) || str !== str . toLowerCase ( ) || ( str . startsWith ( "@" ) && ! ( ( str . indexOf ( "@" ) !== str . lastIndexOf ( "@" ) || ! str . includes ( "/" ) || str . indexOf ( "/" ) !== str . lastIndexOf ( "/" ) || isNpmPackageName ( str . split ( "/" ) [ 0 ] . slice ( 1 ) ) || isNpmPackageName ( str . split ( "/" ) [ 1 ] ) ) ) ) || encodeURIComponent ( str ) !== str ) ) ; } export function isAcceptedYear ( str ) { const split = str . split ( "-" ) ; return ( /^\d{4}$/ . test ( str ) || ( split . length === 2 && split . every ( x => /^\d{4}$/ . test ( x ) ) ) || ( /, ?/ . test ( str ) && str . split ( "," ) . map ( x => x . trim ( ) ) . every ( isAcceptedYear ) ) ) ; } /** Resolve a path, including the expansion of `~/` paths */ const expandPath = ( path_ ) => path . resolve ( path_ . replace ( /^~(?=$|\/|\\)/ , os . homedir ( ) ) ) ; export const convertProject = ( str ) => ( { path : expandPath ( str ) , name : path . basename ( expandPath ( str ) ) } ) ; export const nonEmpty = ( name ) => ( val ) => { if ( val === "" ) throw new TypeError ( `${ name } cannot be empty` ) ; else return val ; } ; const gitConfig = ( ) => parseGitConfig ( { cwd : "/" , path : gitPath ( "global" ) } ) ; export const getUserName = ( ) : string => cfg . get ( "name" ) || gitConfig ( ) . user ?. name || process . env . USER ; export const getUserEmail = ( ) : string => cfg . get ( "email" ) || gitConfig ( ) . user ?. email ;