text: 'use strict';
  
  var _unescape = require( './internal/unescape' );
  var _type     = require( './internal/type' );
  
  var baseExec  = require( './base/base-exec' );
  
  var isKey     = require( './is-key' );
  var toKey     = require( './to-key' );
  
  var rProperty = /(^|\.)\s*([_a-z]\w*)\s*|\[\s*((?:-)?(?:\d+|\d*\.\d+)|("|')(([^\\]\\(\\\\)*|[^\4])*)\4)\s*\]/gi;
  
  function stringToPath ( str ) {
    var path = baseExec( rProperty, str );
    var i = path.length - 1;
    var val;
  
    for ( ; i >= 0; --i ) {
      val = path[ i ];
  
      // .name
      if ( val[ 2 ] ) {
        path[ i ] = val[ 2 ];
      // [ "" ] || [ '' ]
      } else if ( typeof val[ 5 ] === 'string' ) {
        path[ i ] = _unescape( val[ 5 ] );
      // [ 0 ]
      } else {
        path[ i ] = val[ 3 ];
      }
    }
  
    return path;
  }
  
  function castPath ( val ) {
    var path;
    var i;
    var l;
  
    if ( isKey( val ) ) {
      return [ toKey( val ) ];
    }
  
    if ( _type( val ) === 'array' ) {
      path = Array( l = val.length );
  
      for ( i = l - 1; i >= 0; --i ) {
        path[ i ] = toKey( val[ i ] );
      }
    } else {
      path = stringToPath( '' + val );
    }
  
    return path;
  }
  
  module.exports = castPath;
  