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

line-info

v0.2.0

Published

Gather information about a line based on content and cursor position

Downloads

689

Readme

line-info Build status

Gather information about a line based on content and cursor position.

This was built as part of commander-completion, a shell completion library for commander.js.

Getting Started

Install the module with: npm install line-info

var lineInfo = require('line-info');
lineInfo({
  // git checkout|world
  line: 'git checkoutworld',
  cursor: 12
});
/* Result is
{
  line: {
    value: 'git checkoutworld',
    index: 12, // 'git checkout'.length
    partialLeft: 'git checkout',
    partialRight: 'world'
  },
  words: {
    value: ['git', 'checkoutworld'],
    index: 1, // Position of 'checkoutworld'
    partialLeft: ['git', 'checkout'],
    partialRight: ['world']
  },
  word: {
    value: 'checkoutworld',
    index: 8, // 'checkout'.length
    partialLeft: 'checkout',
    partialRight: 'world'
  }
}
*/

// Accessed via `result.word.partialLeft`; // 'checkout'

Documentation

line-info exposes a single function via its module.exports

lineInfo(params)

Collect info about a line given a set of shell completion parameters.

Input

  • params Object - Container for additional parameters
    • line String - Input to analyze (e.g. npm publish)
    • cursor Number - Position of cursor within string (e.g. ec|ho hai has a cursor of 2)

Returned

  • retObj Object - Container for information
    • line Object - Container for params.line information
      • value String - Original input from params.line
      • index Number - Original cursor position from params.cursor
      • partialLeft String- Left section of line before cursor (e.g. 'npm pub' in npm pub|lish)
      • partialRight String- Right section of line after cursor (e.g. 'lish' in npm pub|lish)
    • words Object - Information about words in line
      • value String[] - Array of words in the params.line
      • index Number - Index of word containing cursor
      • partialLeft String[] - Array of words from retObj.line.partialLeft (e.g. ['npm', 'pub'] in npm pub|lish)
        • Word containing cursor will be broken up here
      • partialRight String[] - Array of words from retObj.line.partialRight (e.g. ['lish'] in npm pub|lish)
        • Word containing cursor will be broken up here
    • word Object - Information about word containing cursor
      • value String - Word containing cursor
      • index Number - Position of cursor within word
      • partialLeft String - Left section of word before cursor (e.g. 'pub' in npm pub|lish)
      • partialRight String - Right section of word after cursor (e.g. 'lish' in npm pub|lish)

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via grunt and test via npm test.

Donating

Support this project and others by twolfson via gittip.

Support via Gittip

Unlicense

As of Dec 17 2013, Todd Wolfson has released this repository and its contents to the public domain.

It has been released under the UNLICENSE.