How to use the tree-kit.path function in tree-kit

To help you get started, we’ve selected a few tree-kit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cronvel / kung-fig / lib / kungFigAsync.js View on Github external
configPath = paths.configDir + paths.configFile ;

		if ( options.baseDir && ! options.baseDir.some( e => configPath.startsWith( e ) ) ) {
			throw new Error( 'Cannot load config file, path denied by baseDir option: ' + configPath_ ) ;
		}
	}

	//console.log( '\n### Trying:' , configPath , "\n" ) ;

	// Search the cache
	if ( options.fileObjectMap.has( configPath ) ) {
		// Found in the cache, exit now!
		required = options.fileObjectMap.get( configPath ) ;
		config = required instanceof kungFig.kfgCommon.KFG ? required.data : required ;

		if ( innerPath ) { config = tree.path.get( config , innerPath ) ; }
		return config ;
	}

	try {
		config = required = await this.requireAsync( configPath , paths.configExt , options ) ;
	}
	catch ( error_ ) {
		if ( error_.metaTagsOnly ) { throw error_ ; }

		error = new Error( 'Cannot load config file: ' + configPath + ' (' + error_ + ')' ) ;
		error.from = error_ ;
		error.badContent = error_.code !== 'MODULE_NOT_FOUND' ;
		error.code = error_.code ;
		throw error ;
	}
github cronvel / http-requester / lib / HttpRequester.js View on Github external
if ( ! streams.output ) {
		this.displayBody( body , incomingMessage ) ;
		this.displayTrailer( incomingMessage ) ;
	}

	term.dim.magenta( '[Received ' + ( body ? utils.byteString( body.length ) + ' ' : '' ) + 'in ' + this.lastResponse.time + 'ms]\n' ) ;

	// Various stuff
	switch ( incomingMessage.status ) {
		case 200 :
		case 201 :
			// Add a new entry to pathCompletion
			pathArray = ( query.hostname + ':' + query.port + query.pathname ).split( '/' ) ;
			if ( pathArray[ pathArray.length - 1 ] === '' ) { pathArray.pop() ; }
			tree.path.define( this.pathCompletion , pathArray , true ) ;
			break ;
		case 404 :
			// Remove the entry from pathCompletion
			pathArray = ( query.hostname + ':' + query.port + query.pathname ).split( '/' ) ;
			if ( pathArray[ pathArray.length - 1 ] === '' ) { pathArray.pop() ; }
			tree.path.delete( this.pathCompletion , pathArray ) ;
			break ;
	}

	// Handle redirections
	if ( incomingMessage.headers && incomingMessage.headers.location ) {
		switch ( incomingMessage.status ) {
			case 301 :
			case 307 :
			case 308 :
				command = { outputFile: command.outputFile , inputFile: command.inputFile } ;
github cronvel / http-requester / lib / shell.js View on Github external
if ( ! streams.output ) {
		this.displayBody( query , body , incomingMessage ) ;
		this.displayTrailer( query , incomingMessage ) ;
	}

	term.dim.magenta( '[Received ' + ( body ? this.byteString( body.length ) + ' ' : '' ) + 'in ' + this.lastResponse.time + 'ms]\n' ) ;

	// Various stuff
	switch ( incomingMessage.status ) {
		case 200 :
		case 201 :
			// Add a new entry to pathCompletion
			pathArray = ( query.hostname + ':' + query.port + query.pathname ).split( '/' ) ;
			if ( pathArray[ pathArray.length - 1 ] === '' ) { pathArray.pop() ; }
			tree.path.define( pathCompletion , pathArray , true ) ;
			break ;
		case 404 :
			// Remove the entry from pathCompletion
			pathArray = ( query.hostname + ':' + query.port + query.pathname ).split( '/' ) ;
			if ( pathArray[ pathArray.length - 1 ] === '' ) { pathArray.pop() ; }
			tree.path.delete( pathCompletion , pathArray ) ;
			break ;
	}

	// Handle redirections
	if ( incomingMessage.headers && incomingMessage.headers.location ) {
		switch ( incomingMessage.status ) {
			case 301 :
			case 307 :
			case 308 :
				command = { shellConfig: query.shellConfig } ;
github cronvel / kung-fig / lib / kungFig.js View on Github external
// Add the config meta to the kungFig WeakMap
		if ( config && typeof config === 'object' ) {
			kungFig.meta.set( config , required.meta ) ;
		}
	}

	// Check if this is a scalar, if so it's also a static
	if ( ! config || typeof config !== 'object' ) {
		isStatic = true ;
		isScalar = true ;
	}

	if ( innerPath ) {
		if ( isScalar ) { config = undefined ; }
		else { config = tree.path.get( config , innerPath ) ; }
	}

	if ( ! isStatic && options.reduce ) {
		config = this.autoReduce( config ) ;
	}

	return config ;
} ;
github cronvel / http-requester / lib / shell.js View on Github external
lastTypedPart = typedPath ;
	typedDir = '' ;
	typedPathArray = typedPath.split( '/' ) ;

	if ( typedPathArray.length > 1 ) {
		lastTypedPart = typedPathArray[ typedPathArray.length - 1 ] ;
		typedDirArray = typedPathArray.slice( 0 , -1 ) ;
		typedDir = typedDirArray.join( '/' ) + '/' ;
		pathArray = pathArray.concat( typedDirArray ) ;

		if ( typedPathArray[ typedPathArray.length - 1 ] === '' ) { typedPathArray.pop() ; }
	}

	prefix += typedDir ;
	node = pathArray.length ? tree.path.get( pathCompletion , pathArray ) : pathCompletion ;

	//console.log( '\n\nnode:' , node , pathArray ) ;

	if ( ! node || typeof node !== 'object' ) { return start ; }

	for ( key in node ) {
		if ( node[ key ] && typeof node[ key ] === 'object' ) { completion.push( key + '/' ) ; }
		else { completion.push( key ) ; }
	}

	completion = termkit.autoComplete( completion , lastTypedPart , true ) ;
	if ( ! Array.isArray( completion ) ) { return prefix + completion ; }

	completion.sort( naturalSort ) ;
	completion.prefix = prefix ;
github cronvel / http-requester / lib / HttpRequester.js View on Github external
lastTypedPart = typedPath ;
	typedDir = '' ;
	typedPathArray = typedPath.split( '/' ) ;

	if ( typedPathArray.length > 1 ) {
		lastTypedPart = typedPathArray[ typedPathArray.length - 1 ] ;
		typedDirArray = typedPathArray.slice( 0 , -1 ) ;
		typedDir = typedDirArray.join( '/' ) + '/' ;
		pathArray = pathArray.concat( typedDirArray ) ;

		if ( typedPathArray[ typedPathArray.length - 1 ] === '' ) { typedPathArray.pop() ; }
	}

	prefix += typedDir ;
	node = pathArray.length ? tree.path.get( this.pathCompletion , pathArray ) : this.pathCompletion ;

	//console.log( '\n\nnode:' , node , pathArray ) ;

	if ( ! node || typeof node !== 'object' ) { return start ; }

	for ( key in node ) {
		if ( node[ key ] && typeof node[ key ] === 'object' ) { completion.push( key + '/' ) ; }
		else { completion.push( key ) ; }
	}

	completion = termkit.autoComplete( completion , lastTypedPart , true ) ;
	if ( ! Array.isArray( completion ) ) { return prefix + completion ; }

	completion.sort( naturalSort ) ;
	completion.prefix = prefix ;
github cronvel / kung-fig / lib / Ref2.js View on Github external
value = value.getValue( ctx ) ;
	}
	
	if ( shouldBeBound && typeof value === 'function' )
	{
		parentPath = lastValue.ref ;
		indexOf = Math.max( parentPath.lastIndexOf( '.' ) , parentPath.lastIndexOf( '[' ) ) ;
		
		if ( indexOf === -1 )
		{
			value = value.bind( ctx ) ;
		}
		else
		{
			parentPath = parentPath.slice( 0 , indexOf ) ;
			value = value.bind( tree.path.get( ctx , parentPath ) ) ;
		}
	}
	
	return value ;
} ;

tree-kit

Tree utilities which provides a full-featured extend and object-cloning facility, and various tools to deal with nested object structures.

MIT
Latest version published 6 months ago

Package Health Score

64 / 100
Full package analysis