Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

noncharacters

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

noncharacters

34 non-character code points (labeled <not a character>), that are set aside and guaranteed to never be used for a character. Perfect to use for placeholders or temporary replacements during string transformations.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40K
increased by1.03%
Maintainers
1
Weekly downloads
 
Created
Source

noncharacters NPM version

34 non-character code points (labeled ), that are set aside and guaranteed to never be used for a character. Perfect to use for placeholders or temporary replacements during string transformations.

See the wikipedia article on non-characters. Also, I used regenerate from mathiasbynens to generate the range of characters.

Install with npm

npm i noncharacters --save

Usage

var noncharacters = require('noncharacters');
//=> ['\uFFFF', '\uFFFE', ...]

Example

Let's say you need to transform a string but you need to temporarily replace some characters that might cause issues.

Create your own placeholders:

// arbitrary characters we want to replace, 
// mapped to placeholder non-characters
var placeholders = {
  '{': noncharacters[0],
  '}': noncharacters[1]
};

// the string with characters to replace
var str = 'This is a template: {name}';

// actually replace the characters
Object.keys(placeholders).forEach(function(ch) {
  str = str.replace(ch, placeholders[ch]);
});
//=> This is a template: \uFFFFname\uFFFE

Now you can do whatever you want to str. Then, to change back:

Object.keys(placeholders).forEach(function(ch) {
  str = str.replace(placeholders[ch], ch);
});
//=> This is a template: {name}

Run tests

Install dev dependencies:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb-cli on February 27, 2015.

FAQs

Package last updated on 27 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc