Socket
Socket
Sign inDemoInstall

@cactuslab/nicetype

Package Overview
Dependencies
3
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cactuslab/nicetype

Transform plain ASCII punctuation into “smart” Unicode equivalents.


Version published
Weekly downloads
3
increased by50%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

Nicetype

Touch up copy by converting plain ASCII punctuation into “smart” Unicode equivalents. Transformations include:

  • Straight to curly quotes.
  • Hyphen-dashes to em and endashes
  • Two, three or more dots to horizontal ellipsis

Please note these transforms are intended for English locales.


Nicetype is an ES6 port of the abandoned jsPrettify library.

While jsPrettify’s rules aren’t the most thorough—this is also its strength as it reduces false positives and possible conflicts with the original input’s style.

Installation

pnpm add @cactuslab/nicetype
npm install --save @cactuslab/nicetype

Usage

import nicetype from 'nicetype'

const exampleString = 'Fish \'n\' Chips';
console.log(nicetype.formatString(exampleString)); // 'Fish ’n’ Chips'

const exampleElement = document.createElement('div');
exampleElement.innerText = exampleString;
nicetype.formatElement(exampleElement, {
  // exclusionAttribute: String,
  // tagNameExclusions: []
}); // HTMLElement or Node of type: TEXT_NODE

API

nicetype.formatString(string)

Returns transformed string

Parameters
  • string: String to transform

nicetype.formatElement(element, options)

Applies transformations to an element and its childrens’ text nodes. If an element has the exclusionAttribute or is of a tagName listed in tagNameExclusions—that branch’s replacement will stop.

Parameters
  • element: An HTMLElement

  • options: Optional Object for customising defaults

    {
      exclusionAttribute: 'data-nicetype-disable',
      tagNameExclusions: ['base', 'command', 'link', 'meta', 'noscript', 'script', 'style', 'title', 'audio', 'br', 'code', 'command', 'datalist', 'embed', 'hr', 'iframe', 'img', 'input', 'kbd', 'keygen', 'map', 'math', 'meter', 'object', 'output', 'picture', 'progress', 'ruby', 'samp', 'script', 'select', 'svg', 'template', 'textarea', 'video', 'wbr', 'area', 'audio', 'canvas', 'embed', 'iframe', 'img', 'math', 'object', 'picture', 'svg', 'video', 'input', 'keygen', 'label', 'meter', 'object', 'output', 'progress', 'select', 'textarea', 'script', 'template']
    }
    

Roadmap

  • Non-breaking space: Short words/widow prevention
  • Expose advanced/opinionated dash options…, or remove entirely?
  • TypeScript

Development/Builds

nvm use
pnpm install

See Also

Keywords

FAQs

Last updated on 23 Jul 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc