npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mdash-node

v1.0.1

Published

Evgeny Muravjev Typograph for Node.js

Downloads

49

Readme

mdash

NPM

This is Node.js port of the original Russian Typograph (mdash.ru) by Evgeny Muravjev

Getting Started

Install the module with:

npm install mdash-node

Documentation

Currently this is a port from PHP library which fully immitates its behavior excluding debuging and custom builds. So you can check the original documentation on mdash.ru. Optimizations and improvements will follow. All formatting rules can be found on mdash.ru/rules.html (Russian).

Usage

The module can accept rules settings either with new instance or as args to the format method.

var Mdash = require('mdash-node');

var tp = new Mdash("Типографика - это круто!");
var txt = tp.format();  // Типографика — это круто!

Rule settings can be suplied to instance.

var tp = new Mdash("Типографика - это круто!", {'Text.paragraphs': true});
var txt = tp.format();  // <p>Типографика&nbsp;&mdash; это круто!</p>

txt = tp.format("Типографика - это круто!", {
  'Text.paragraphs': false
});  // Типографика&nbsp;&mdash; это круто!

You can also pass a callback to the method format:

Mdash.format("Типографика - это круто!", {'Text.paragraphs': true}, function(err, text) {
  console.log(text);  // <p>Типографика&nbsp;&mdash; это круто!</p>
});

Mdash.format("Типографика - это круто!", function(err, text) {
  console.log(text);  // Типографика&nbsp;&mdash; это круто!
});

Also you can get the list of trets (in order of appliance):

var typo = new Mdash();
var trets = typo.getTretNames();

// [ 'Text',
//   'Space',
//   'Number',
//   'Quote',
//   'Punctmark',
//   'Date',
//   'Symbol',
//   'Nobr',
//   'Dash',
//   'Abbr',
//   'OptAlign',
//   'Etc' ]

Get rules for all tret or specific one:

var typo = new Mdash();
var allRules = typo.getRuleNames();  // Get all rules

var dashRules = typo.getRuleNames('Dash');    // Specify a tret as argument

// { Dash:
//    [ 'mdash_symbol_to_html_mdash',
//      'mdash',
//      'mdash_2',
//      'mdash_3',
//      'iz_za_pod',
//      'to_libo_nibud',
//      'koe_kak',
//      'ka_de_kas' ] }

You can get current settings of the typograph:

var typo = new Mdash();
var settings = typo.getSettings();

// { Quote: { no_bdquotes: false, no_inches: false },
//   OptAlign: { disabled: true },
//   Text: { disabled: true },
//   'Dash.ka_de_kas': { disabled: true },
//   'Date.mdash_month_interval': { disabled: true },
//   'Date.nbsp_and_dash_month_interval': { disabled: true },
//   'Nobr.hyphen_nowrap_in_small_words': { disabled: true },
//   'Nobr.hyphen_nowrap': { disabled: true },
//   'Punctmark.dot_on_end': { disabled: true },
//   'OptAlign.oa_obracket_coma': { disabled: true } }

Module Settings

By default some rules (eg. rules for Optical Alignment) put additional HTML tags in your text with inline styles. If you would like to put styles in separate classes, use this:

Mdash.setLayout(Mdash.LAYOUT_CLASS);

Or you can set styles to go both inline and in class:

Mdash.setLayout(Mdash.LAYOUT_STYLE|Mdash.LAYOUT_CLASS);

And to set class prefix (by default it is 'mdash-'):

Mdash.setLayoutClassPrefix('typo-');

Rules Settings

All settings are usualy just the rule names with tret name as the namespace, so mainly you can enable or disable some of them. Also you can specify some options for the rule or specify some virtual settings for different rules. To disable some rule you can pass the arguments object where key is rulename (with namespace — tret name) and the value is false. For example, we want to disable rule oa_obracket_coma in namespace OptAlign:

{
  'OptAlign.oa_obracket_coma': false
}

Also we can disable all rules in the namespace:

{
  'OptAlign': false
}

In case we need to specify some options inside the rules or to apply some methods inside the different rules, we can use "virtual" rules. It is just a setting which name does not conflict with real rule name and selects specified rules:

{
  'Space.autospace_after': {
    selector: 'Space.autospace_after_*'
  },
  'Etc.unicode': {
    selector: '*',
    dounicode: true,
    disabled: true
  }
}

There is no such rule as Etc.unicode, however if we will pass this as setting to the lib, the option dounicode will be applied to the rules specified in selector (to all rules in this case). Also switching disabled will either enable or disable it.

For example, to turn on convertion of the HTML entities in unicode characters we can put this in settings:

var typo = new Mdash({
  'Etc.unicode': true
});

Or if we would like to disable all rules which puts space after punctuation marks:

var typo = new Mdash({
  'Space.autospace_after': false
});

Which is equal to this settings for the real rules:

var typo = new Mdash({
  'Space.autospace_after_comma': false,
  'Space.autospace_after_pmarks': false,
  'Space.autospace_after_dot': false,
  'Space.autospace_after_hellips': false
});

There are several presets and predefined "virtual" options:

Mdash.prototype.presets = {
  'Quote': {
    no_bdquotes: false,
    no_inches: false
  },
  'OptAlign': {
    disabled: true
  },
  'Text': {
    disabled: true
  },
  'Dash.ka_de_kas': {
    disabled: true
  },
  'Date.mdash_month_interval': {
    disabled: true
  },
  'Date.nbsp_and_dash_month_interval': {
    disabled: true
  },
  'Nobr.hyphen_nowrap_in_small_words': {
    disabled: true
  },
  'Nobr.hyphen_nowrap': {
    disabled: true
  },
  'Punctmark.dot_on_end': {
    disabled: true
  },
  'Space.clear_before_after_punct': {
    selector: 'Space.remove_space_before_punctuationmarks'
  },
  'Space.autospace_after': {
    selector: 'Space.autospace_after_*'
  },
  'Space.bracket_fix': {
    selector: ['Space.nbsp_before_open_quote', 'Punctmark.fix_brackets']
  },
  'Etc.unicode': {
    selector: '*',
    dounicode: true,
    disabled: true
  }
};

.mdash

You can specify global settings by putting simple JSON file .mdash in the root of your project:

{
  "OptAlign.oa_obracket_coma": false,
  "Text.paragraphs": false,
  "Text.breakline": false,
  "Quote": false
}

This settings will override the default, but will be overriden by options you'll pass to instance.

License

This package is licensed under the MIT license.