string-selection
v2.1.1
Published
Describe selections with a string.
Downloads
9
Readme
String Selection
Installation
# Install with NPM
$ npm install string-selection
# Install by copying the dist file.
$ git clone https://github.com/iamJoeTaylor/string-selection.git
$ cp string-selection/dist/string-selection.js path/to/vendor/string-selection.js
Usage
parseDescription
var desc = Selection.parseDescription('W|olver|ine');
> {
> caret: { input: 'Wolverine', start: 1, end: 6 },
> affinity: null,
> value: 'Wolverine'
> }
var desc = Selection.parseDescription('S<to|rm');
> {
> caret: { input: 'Storm', start: 1, end: 3 },
> affinity: 0,
> value: 'Storm'
> }
printDescription
var desc = Selection.printDescription({
caret: {
start: 2,
end: 2
},
affinity: null,
value: 'Beast'
});
> 'Be|ast';
var desc = Selection.printDescription({
caret: {
start: 3,
end: 6
},
affinity: 0,
value: 'Kitty Pride'
});
> 'Kit<ty |Pride';