Skip to content

element-io/text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Base class for minimal text nodes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published