Skip to content

💻 A collection of utilities for manipulating and editing text, with no dependencies.

License

Notifications You must be signed in to change notification settings

ryngonzalez/Text.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text.js

A collection of utilities for manipulating and editing text, with no dependencies. Text.js provides easy interfaces to some of the most common things you need when managing textareas (and other text inputs). Everything is separated into modules as needed.

$ bower install --save Text.js

Current Modules

###1. Cursor

Usage

textarea = document.getElementById('#myTextarea');
var cursor = new Text.Cursor(textarea);

var position = cursor.position // Returns integer index
cursor.position = 25 // Sets position to index

2. CurrentWord

Usage:

Given a textarea with the following text and cursor (represented by the pipe character |):

hey there guy|s this is my textarea

it is multiline too i guess

textarea = document.getElementById('#myTextarea');
var current = new Text.CurrentWord(textarea);

// Returns the string "guys"
current.get();

// Returns an object with the signature {before: string, after: string}
// => {before: 'guy', after: 's'}
current.parts();

// Returns the indices of the current word
// => {start: 10, end: 14}
current.indices();

// Replaces the current word, and places
// the current cursor position at the end of the
// current word. Returns that new position
current.replace('someString');

3. Resizer

Usage:

Given a textarea, automatically resize it to fit the content.

textarea = document.getElementById('#myTextarea');
var resizer = new Text.Resize(textarea);

// Resize for a given event on the textarea
// Ex. input: when the content of the textarea is changed
resizer.on('input');

// Manually force a resize
resizer.resize();

// Unbind a specific event from causing a resize
resizer.unbind('input');

// Unbind all events, delete the clone,
// and remove references to the elements.
resizer.destroy();

About

💻 A collection of utilities for manipulating and editing text, with no dependencies.

Resources

License

Stars

Watchers

Forks

Packages

No packages published