How to use the string-kit.naturalSort function in string-kit

To help you get started, we’ve selected a few string-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 / http-requester / lib / HttpRequester.js View on Github external
shellCommand.ls = function( command ) {
	var i , j , pathArray , pathNode , keys , key , width = 0 , columns ;

	pathArray = ( this.query.hostname + ':' + this.query.port + this.query.pathname ).split( '/' ) ;
	if ( pathArray[ pathArray.length - 1 ] === '' ) { pathArray.pop() ; }
	pathNode = tree.path.get( this.pathCompletion , pathArray ) ;

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

	keys = Object.keys( pathNode ) ;

	if ( ! keys.length ) { return ; }

	term.italic.dim.blue( "Known resources:\n" ) ;

	keys.sort( naturalSort ) ;

	for ( i = 0 ; i < keys.length ; i ++ ) { width = Math.max( width , keys[ i ].length ) ; }
	width += 2 ;
	columns = Math.floor( term.width / width ) ;

	//console.log( '\ncolumns:' , columns , width , term.width ) ;

	for ( i = 0 ; i < keys.length ; i ++ ) {
		key = keys[ i ] ;

		j = i % columns ;
		term.column( j * width ) ;

		if ( i && ! j ) { term( '\n' ) ; }

		if ( pathNode[ key ] && typeof pathNode[ key ] === 'object' ) { term.magenta.bold( key ).bold( '/' ) ; }
github cronvel / http-requester / lib / HttpRequester.js View on Github external
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 ;

	return completion ;
} ;
github cronvel / http-requester / lib / HttpRequester.js View on Github external
shellCommand.lls = async function( command ) {
	var i , j , files , file , width = 0 , columns ;

	try {
		files = await fsKit.readdirAsync( this.cwd , { slash: true } ) ;
	}
	catch ( error ) {
		term.red( "Can't access directory %s: %s\n" , this.cwd , error ) ;
		return ;
	}

	files.sort( naturalSort ) ;
	term.italic.dim.blue( "Local %s:\n" , this.cwd ) ;

	for ( i = 0 ; i < files.length ; i ++ ) { width = Math.max( width , files[ i ].length ) ; }
	width += 2 ;
	columns = Math.floor( term.width / width ) ;

	//console.log( '\ncolumns:' , columns , width , term.width ) ;

	for ( i = 0 ; i < files.length ; i ++ ) {
		file = files[ i ] ;

		j = i % columns ;
		term.column( j * width ) ;

		if ( i && ! j ) { term( '\n' ) ; }

string-kit

A string manipulation toolbox, featuring a string formatter (inspired by sprintf), a variable inspector (output featuring ANSI colors and HTML) and various escape functions (shell argument, regexp, html, etc).

MIT
Latest version published 7 months ago

Package Health Score

60 / 100
Full package analysis