How to use the string-kit.escape 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 / atomic-terminal / front / js / Terminal.js View on Github external
if ( Terminal.osc[ num ] ) { Terminal.osc[ num ].call( this , sequence.slice( index + 1 ) ) ; }
					else { console.error( 'Not implemented: OSC "' + num + '" (sequence: ' + sequence.slice( index + 1 ) + '")' ) ; }
				}
				else
				{
					console.log( "Trouble: NaN!" ) ;
				}
			}

			return sequence.length + 2 + ( chunk[ i ] === 0x07 ? 1 : 2 ) ;	// ESC + ] + sequence + Bell/ST
		}

		sequence += char ;
	}

	console.log( "Trouble: " + string.escape.control( chunk.toString() ) ) ;
	// We should never reach here, except if the buffer was too short
	return null ;
} ;
github cronvel / terminal-kit / lib / Terminal.js View on Github external
break ;
				}
				else if ( this.rKeymapStarter[ i ] && this.rKeymapStarter[ i ][ keymapStartCode ] ) {
					// Then test pattern sequences

					keymapList = this.rKeymapStarter[ i ][ keymapStartCode ] ;

					//console.log( 'for i:' , keymapList ) ;

					for ( j = 0 ; j < keymapList.length ; j ++ ) {
						keymap = keymapList[ j ] ;

						if ( keymap.altEnder ) {
							regexp = '^' +
								string.escape.regExp( keymap.starter ) +
								'([ -~]*)' +	// [ -~] match only all ASCII non-control character
								'(' + string.escape.regExp( keymap.ender ) + '|' + string.escape.regExp( keymap.altEnder ) + ')' ;
						}
						else {
							regexp = '^' +
								string.escape.regExp( keymap.starter ) +
								'([ -~]*)' +	// [ -~] match only all ASCII non-control character
								string.escape.regExp( keymap.ender ) ;
						}

						matches = keymapCode.match( new RegExp( regexp ) , 'g' ) ;

						//console.log( 'for j:' , keymap , regexp , matches ) ;

						if ( matches ) {
							found = true ;
github cronvel / terminal-kit / lib / Terminal.js View on Github external
}
				else if ( this.rKeymapStarter[ i ] && this.rKeymapStarter[ i ][ keymapStartCode ] ) {
					// Then test pattern sequences

					keymapList = this.rKeymapStarter[ i ][ keymapStartCode ] ;

					//console.log( 'for i:' , keymapList ) ;

					for ( j = 0 ; j < keymapList.length ; j ++ ) {
						keymap = keymapList[ j ] ;

						if ( keymap.altEnder ) {
							regexp = '^' +
								string.escape.regExp( keymap.starter ) +
								'([ -~]*)' +	// [ -~] match only all ASCII non-control character
								'(' + string.escape.regExp( keymap.ender ) + '|' + string.escape.regExp( keymap.altEnder ) + ')' ;
						}
						else {
							regexp = '^' +
								string.escape.regExp( keymap.starter ) +
								'([ -~]*)' +	// [ -~] match only all ASCII non-control character
								string.escape.regExp( keymap.ender ) ;
						}

						matches = keymapCode.match( new RegExp( regexp ) , 'g' ) ;

						//console.log( 'for j:' , keymap , regexp , matches ) ;

						if ( matches ) {
							found = true ;

							handlerResult = keymap.handler.call( this , keymap.name , matches[ 1 ] ) ;
github cronvel / kung-fig / lib / kfgStringify.js View on Github external
builtin.RegExp = function regex( v ) {
	var str , delimiter , escDelimiter , fixDelimiterRegex ;

	delimiter = v.delimiter || '/' ;
	escDelimiter = string.escape.regExp( delimiter ) ;
	fixDelimiterRegex = new RegExp( escDelimiter , 'g' ) ;

	str = delimiter + v.source.replace( fixDelimiterRegex , '\\$&' ) ;

	if ( typeof v.substitution === 'string' ) {
		str += delimiter + v.substitution.replace( fixDelimiterRegex , '\\$&' ) ;
	}

	str += delimiter ;

	if ( v.global ) { str += 'g' ; }
	if ( v.ignoreCase ) { str += 'i' ; }
	if ( v.multiline ) { str += 'm' ; }

	return str ;
} ;
github cronvel / kung-fig / lib / kfgParse.js View on Github external
builtin.Regex = builtin.regex = builtin.RegExp = builtin.Regexp = builtin.regexp = v => {
	var delimiter , escDelimiter , partRegex , fixDelimiterRegex , match ;
	//var regex_ ;

	if ( ! v || typeof v !== 'string' ) { throw new SyntaxError( "Bad Regular Expression: not a string or empty string" ) ; }

	delimiter = v[ 0 ] ;
	escDelimiter = string.escape.regExp( delimiter ) ;

	try {
		partRegex = new RegExp(
			"^" + escDelimiter + "((?:\\\\" + escDelimiter + "|[^" + escDelimiter + "])+)" +
			"(?:" + escDelimiter + "((?:\\\\" + escDelimiter + "|[^" + escDelimiter + "])+))?" +
			escDelimiter + "([a-z])*$"
		) ;

		fixDelimiterRegex = new RegExp( "\\\\(" + escDelimiter + ")" , 'g' ) ;

		match = v.match( partRegex ) ;
	}
	catch ( error ) {
		throw new SyntaxError( "Bad Regular Expression: " + v ) ;
	}

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 5 months ago

Package Health Score

61 / 100
Full package analysis