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

textstack

v0.1.2

Published

A simple undo history script for DOM text fields

Downloads

5

Readme

TextStack

License Bower Version NPM Version Development Dependencies Travis Build Coverage Status

The undo functionality for various text input fields on many browsers is very unpredictable. TextStack is a simple undo history script for DOM text input fields. It also comes with an easy to use API which allows developers to safely modify the undo stack at their own discretion. This library is lightweight and has no dependencies. Currently, I've test its compatibility with a few edge and legacy versions of Chrome, IE, and Firefox, as well as generic WebKit via PhantomJS. TextStack should also work fine in Safari 6+, but I haven't explicitly tested it there yet.

This project has a few goals:

  • Keep it simple - do this one thing, and do it well
  • No feature creep
  • No dependencies
  • Small and lightweight
  • Optional jQuery integration
  • Desktop browser compatibility: Chrome, Chrome Canary, Firefox ESR, Firefox Developer Edition, IE9+, Safari 6+

Overview

TextStack is easy: just pass the DOM element you wish to use TextStack on as the first argument when initializing. You'll need to save the variable somewhere - if you are using jQuery, it might be wise to save it on the jQuery element itself. An optional second parameter contains an object of options.

//Make sure to load the TextStack js file before running this code!

//Create a textarea
var myTextArea = document.createElement('textarea');
document.body.appendChild(myTextArea);

//Add TextStack
var myTextStack = new TextStack(myTextArea, {
  idleDelay: 2000
});

//Insert some text into the textarea, then add a snapshot to the undo stack
myTextArea.value = 'test';
myTextStack.snapshot();

Todo List

  • Expand browser support
  • Optional jQuery integration as a plugin; would only fire if jQuery is detected, and would continue to work standalone
  • Better handling of undo/redo operations where the keys are held down
  • Keep track of selection areas and where the cursor is in each snapshot, and maybe take snapshots for certain selection events

API


####new TextStack(input, [opts]) Create a new instance of TextStack

| Param | Type | Description | | ----- | ---- | ----------- | | input | HTMLElement | A DOM text input element (textarea, input type="text", etc) | | [opts] | Object | A list of options | | [opts.idleDelay=1000] | number | Number of milleseconds for which user must be inactive before we save a snapshot | | [opts.omitWhitespace=false] | boolean | When diffing between two snapshots, whitespace will be omitted before comparing | | [opts.maxInterval=5000] | number | If no snapshot has occurred in this number of milleseconds, override the idleDelay and try to make one no matter what | | [opts.maxUndoStackSize=100] | number | Greatest number of snapshots that can be stored at a given time | | [opts.redoKeys] | Array.<number> | Array of keyCodes for keys that, when pressed together, fire a redo action (Default: Ctrl + Y) | | [opts.undoKeys] | Array.<number> | Array of keyCodes for keys that, when pressed together, fire an undo action (Default: Ctrl + Z) |


####textStack.off() Remove the event listeners, so that we can delete this bad boy without any memory leaks


####textStack.redo([e]) Attempt a redo action

| Param | Type | Description | | ----- | ---- | ----------- | | [e] | Event | Event that triggered this function (optional) |


####textStack.undo([e]) Attempt an undo action

| Param | Type | Description | | ----- | ---- | ----------- | | [e] | Event | Event that triggered this function (optional) |


####textStack.snapshot([force]) ⇒ boolean Attempt to add a snapshot to the undoStack - returns false if the new snapshot matches the last available one

| Param | Type | Description | | ----- | ---- | ----------- | | [force=false] | boolean | Forces the snapshot to be added to the stack, even if there is no difference between it and the previous snapshot |

Returns: boolean - Whether or not the operation was successful


####textStack.diff([a], [b], [omitWhitespace]) ⇒ boolean Diff two strings, optionally omitting whitespace

| Param | Type | Description | | ----- | ---- | ----------- | | [a] | string | The first string to compare | | [b] | string | The second string, against which the first will be compared | | [omitWhitespace] | boolean | Do the comparison with or without whitespace included (ex: if true, "ab" === "a\n\n\nb") |

Returns: boolean - True means there is a difference, false means they are identical


####textStack.reset([clear]) Reset the TextStack's histories, and optionally clear the text element

| Param | Type | Description | | ----- | ---- | ----------- | | [clear=false] | boolean | Whether or not we should clear the text element as well - be careful with this! |

License

(MIT License)

copyright (c) 2014 Alex Zaslavsky

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.