line-info
Advanced tools
Weekly downloads
Readme
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.
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'
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
Object
- Container for additional parameters
String
- Input to analyze (e.g. npm publish
)Number
- Position of cursor within string (e.g. ec|ho hai
has a cursor
of 2)Returned
Object
- Container for information
Object
- Container for params.line
information
String
- Original input from params.line
Number
- Original cursor position from params.cursor
String
- Left section of line before cursor (e.g. 'npm pub'
in npm pub|lish
)String
- Right section of line after cursor (e.g. 'lish'
in npm pub|lish
)Object
- Information about words in line
String[]
- Array of words in the params.line
Number
- Index of word containing cursorString[]
- Array of words from retObj.line.partialLeft
(e.g. ['npm', 'pub']
in npm pub|lish
)
cursor
will be broken up hereString[]
- Array of words from retObj.line.partialRight
(e.g. ['lish']
in npm pub|lish
)
cursor
will be broken up hereObject
- Information about word containing cursor
String
- Word containing cursor
Number
- Position of cursor
within wordString
- Left section of word before cursor (e.g. 'pub'
in npm pub|lish
)String
- Right section of word after cursor (e.g. 'lish'
in npm pub|lish
)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
.
Support this project and others by twolfson via gittip.
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.
FAQs
Gather information about a line based on content and cursor position
The npm package line-info receives a total of 421 weekly downloads. As such, line-info popularity was classified as not popular.
We found that line-info demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.