minimal-text-class

0.0.0 • Public • Published

Text Node

NPM version Build Status Coverage Dependencies

Base class for minimal text nodes.

Installation

$ npm install minimal-text-class --save

Usage

To create a new text node,

var Text = require( 'minimal-text-class' );
 
var text = new Text();

The text instance has the following methods...

text.content( [content] )

This method is a setter/getter. If no content is provided, returns the text content. To set the text content

text.content( 'beep' );

Note: setting new content will replace any existing content.

text.append( content )

This is a convenience method for appending new content to existing content.

// Inconvenient...
text.content( text.content()+'boop' );
 
// Convenient...
text.append( 'boop' );

text.toString()

Serializes the node as a string; i.e., returns the text content.

text.toString();

This method provides a consistent interface with minimal elements.

Examples

var text = new Text();
 
text.content( 'beep' );
 
for ( var i = 0; i < 10; i++ ) {
    text.append( '!' );
}
 
console.log( text.toString() );
// Returns 'beep!!!!!!!!!!'

To run the example code from the top-level application directory,

$ node ./examples/index.js

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ open reports/coverage/lcov-report/index.html

License

MIT license.


Copyright

Copyright © 2014. Athan Reines.

Package Sidebar

Install

npm i minimal-text-class

Weekly Downloads

0

Version

0.0.0

License

none

Last publish

Collaborators

  • kgryte