show-invisibles
Converts invisible characters to a commonly recognizable visible form.
Install
npm install show-invisibles
yarn add show-invisibles
pnpm add show-invisibles
Usage
import { showInvisibles } from 'show-invisibles'
const input = `1 2\n3\t4\r5`
console.log(showInvisibles(input))
// => 1·2⏎3↹4␍5
API
showInvisibles
- Type:
(input: string, options?: Options) => string
Converts invisible characters to a commonly recognizable visible form.
Interface
export interface Options {
/**
* transform mappings
*
* @see {@link DEFAULT_MAPPINGS}
*/
mappings?: Map<string, string>
}
Built-in mappings
export const DEFAULT_MAPPINGS: Required<Options>['mappings'] = new Map([
// Middle Dot, \u00B7
[' ', '·'],
// Return Symbol, \u23ce
['\n', '⏎'],
// Left Arrow To Bar Over Right Arrow To Bar, \u21b9
['\r', '␍'],
// Carriage Return Symbol, \u240D
['\t', '↹'],
])
Credits
- Extracted from prettier/prettier-linter-helpers with a little change. Published as ESM with TypeScript support.