1- import _ from 'lodash '
1+ import dlv from 'dlv '
22import didYouMean from 'didyoumean'
33import transformThemeValue from '../util/transformThemeValue'
44import parseValue from 'postcss-value-parser'
55import buildMediaQuery from '../util/buildMediaQuery'
6+ import { toPath } from '../util/toPath'
7+
8+ function isObject ( input ) {
9+ return typeof input === 'object' && input !== null
10+ }
611
712function findClosestExistingPath ( theme , path ) {
8- const parts = _ . toPath ( path )
13+ let parts = toPath ( path )
914 do {
1015 parts . pop ( )
1116
12- if ( _ . hasIn ( theme , parts ) ) break
17+ if ( dlv ( theme , parts ) !== undefined ) break
1318 } while ( parts . length )
1419
1520 return parts . length ? parts : undefined
@@ -32,20 +37,22 @@ function listKeys(obj) {
3237}
3338
3439function validatePath ( config , path , defaultValue ) {
35- const pathString = Array . isArray ( path ) ? pathToString ( path ) : _ . trim ( path , `'"` )
36- const pathSegments = Array . isArray ( path ) ? path : _ . toPath ( pathString )
37- const value = _ . get ( config . theme , pathString , defaultValue )
40+ const pathString = Array . isArray ( path )
41+ ? pathToString ( path )
42+ : path . replace ( / ^ [ ' " ] + / g, '' ) . replace ( / [ ' " ] + $ / g, '' )
43+ const pathSegments = Array . isArray ( path ) ? path : toPath ( pathString )
44+ const value = dlv ( config . theme , pathString , defaultValue )
3845
39- if ( typeof value === ' undefined' ) {
46+ if ( value === undefined ) {
4047 let error = `'${ pathString } ' does not exist in your theme config.`
4148 const parentSegments = pathSegments . slice ( 0 , - 1 )
42- const parentValue = _ . get ( config . theme , parentSegments )
49+ const parentValue = dlv ( config . theme , parentSegments )
4350
44- if ( _ . isObject ( parentValue ) ) {
51+ if ( isObject ( parentValue ) ) {
4552 const validKeys = Object . keys ( parentValue ) . filter (
4653 ( key ) => validatePath ( config , [ ...parentSegments , key ] ) . isValid
4754 )
48- const suggestion = didYouMean ( _ . last ( pathSegments ) , validKeys )
55+ const suggestion = didYouMean ( pathSegments [ pathSegments . length - 1 ] , validKeys )
4956 if ( suggestion ) {
5057 error += ` Did you mean '${ pathToString ( [ ...parentSegments , suggestion ] ) } '?`
5158 } else if ( validKeys . length > 0 ) {
@@ -56,8 +63,8 @@ function validatePath(config, path, defaultValue) {
5663 } else {
5764 const closestPath = findClosestExistingPath ( config . theme , pathString )
5865 if ( closestPath ) {
59- const closestValue = _ . get ( config . theme , closestPath )
60- if ( _ . isObject ( closestValue ) ) {
66+ const closestValue = dlv ( config . theme , closestPath )
67+ if ( isObject ( closestValue ) ) {
6168 error += ` '${ pathToString ( closestPath ) } ' has the following keys: ${ listKeys (
6269 closestValue
6370 ) } `
@@ -87,7 +94,7 @@ function validatePath(config, path, defaultValue) {
8794 ) {
8895 let error = `'${ pathString } ' was found but does not resolve to a string.`
8996
90- if ( _ . isObject ( value ) ) {
97+ if ( isObject ( value ) ) {
9198 let validKeys = Object . keys ( value ) . filter (
9299 ( key ) => validatePath ( config , [ ...pathSegments , key ] ) . isValid
93100 )
@@ -165,7 +172,7 @@ export default function ({ tailwindConfig: config }) {
165172 return value
166173 } ,
167174 screen : ( node , screen ) => {
168- screen = _ . trim ( screen , `'"` )
175+ screen = screen . replace ( / ^ [ ' " ] + / g , '' ) . replace ( / [ ' " ] + $ / g , '' )
169176
170177 if ( config . theme . screens [ screen ] === undefined ) {
171178 throw node . error ( `The '${ screen } ' screen does not exist in your theme.` )
0 commit comments