GU5TAF / textr

Modular typographic framework

Home Page:http://shuvalov-anton.github.io/textr

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

textr

NPM version Build Status Coveralls Status Dependency Status DevDependency Status

Textr is simple framework to compose text transformation functions

Textr is good instrument to create modular tools to make your typography better. It can compose any functions that get text, transform it and return result of processing. For example, check out few: typographic-quotes, typographic-math-symbols, typographic-em-dashes and typographic-ellipses.

Plugins are available on npm, labelled with textr keyword. Either of the plugins has good test coverage, that makes textr transformers easy to support even if one of them will be broken or useless for you. Also you can easily create new one. Don’t be scared.

Idea behind textr

Typography for everybody! At the same time it’s impossible to create one ideal typographic engine. It doesn’t work this way. What we can do with it? We can easily create and maintain small, simple, full-tested and single responsible modules. After this we can compose bunch of these well done modules for every specific situation we need, and everybody will be happy with it’s own ideal text transformer.

Install

npm install --save textr

Usage

var textr    = require('textr');
var ellipses = require('typographic-ellipses');
var spaces   = require('typographic-single-spaces');
var quotes  = require('typographic-quotes');

// Create new text transformer by compose yours
tf = textr({ locale: 'ru'})
  .use(ellipses)
  .use(spaces)
  .use(quotes)
;

// then just send some text to the transformer
tf('Hello  "world"...'); // Hello «world»…

API

textr()

Create new textr transform function (tf).

tf.use(...fn)

Register transform function as tf middleware.

tf.exec(text)

Process given text by the middlewares.

tf(text)

Identical to tf.exec(text). This alias makes tf just regular transform function, that you can register as middleware for textr as well.

var typorgapher = textr().use(typography, tools, here)
var autocorrector = textr().use(autocorrection, things)
var smiles = textr().use(text, to, smiles, goodies)

var tf = textr()
  .use(typographer)
  .use(autocorrector)
  .use(smiles)
;

tf(text); // oh, that's awesome!11

Plugins API

Each plugin will be called with 2 arguments: text and options setted on textr().

function plugin(text, options) {
  console.log(options); // { locale: 'ru' }
  return text;
}

License

MIT © Shuvalov Anton, Vladimir Starkov

About

Modular typographic framework

http://shuvalov-anton.github.io/textr


Languages

Language:JavaScript 100.0%