Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cursores

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cursores

http://cursores.bitbucket.org

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Cursores.js

http://cursores.bitbucket.org

Cursores allows you to get and replace the token under the cursor in a textarea, text input, or string.

It does so by trying to match separate regexes for the text on the left side of the cursor and the text on the right. For performance reasons, the number of characters examined on either side of the cursor is restricted.

For example, if we match a whitespace delimited token in the string the quick brown fo|x jumps (where | denotes the cursor), the token under the cursor is fox.

Usage

By default new instances match whitespace delimited tokens:

> var cursor = new Cursores()

You can also create an instance that matches a whitespace delimited token that starts with a specific character:

> var cursor = Cursores.startsWith('@')

Finally, the Cursores constructor accepts the left regex, right regex, and maximum search window length either side of the cursor.

One can get the token under the cursor in a textarea or text input by calling cursor.token(el). Alternatively, you can pass in a string and the index of the cursor within that string:

> var split = 'The quick brown fo|x jumps'.split('|')
> var cursor = new Cursores()
> cursor.token(split.join(''), split[0].length)
{"value": "fox", "prefix": "fo", "suffix": "x"}

To replace the token under the cursor in a textarea or text input, call cursor.replace(el, replacement). You can also replace the token in a string:

> cursor.replace(split.join(''), split[0].length, 'Fantastic Mr. Fox')
"The quick brown Fantastic Mr. Fox jumps"

Browser support

Cursores supports modern browsers, including Internet Explorer 9, that implement selectionStart and setSelectionRange().

License

Cursores is licensed under Apache 2.0.

FAQs

Package last updated on 30 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc