New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

char-props

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

char-props - npm Package Compare versions

Comparing version

to
0.1.3

2

lib/charProps.js

@@ -63,3 +63,3 @@ /**

if (index <= lineItem.end) {
if (index < lineItem.end) {
break;

@@ -66,0 +66,0 @@ }

{
"name": "char-props",
"description": "Utility for looking up line and column of a character at a given index and vice versa",
"version": "0.1.2",
"version": "0.1.3",
"homepage": "https://github.com/twolfson/char-props",

@@ -6,0 +6,0 @@ "author": {

@@ -58,6 +58,41 @@ # char-props

## Examples
_(Coming soon)_
### Initial load
```js
var charProps = require('char-props'),
jquerySrc = fs.readFileSync('jquery.js', 'utf8');
For now, please refer to [tests](/blob/master/test/charProps_test.js).
// Load jQuery into charProps
var jqueryProps = charProps(jquerySrc);
```
### lineAt usage
```js
// Look up line of character at index 42
jqueryProps.lineAt(42);
```
### columnAt usage
```js
// Look up column of character at index 88
jqueryProps.columnAt(88);
```
### indexAt usage
```js
// Look up the index of a character at line 9000, column 1
jqueryProps.indexAt({'line': 9000, 'column': 1});
```
### charAt usage
```js
// Get the character at line 20, column 20
jqueryProps.charAt({'line': 20, 'column': 20});
```
## lineAt advanced usage
```js
// Look up line of character at index 9001 with a minimum line of 99
jqueryProps.lineAt(9001, {'minLine': 99});
```
## Contributing

@@ -64,0 +99,0 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint your code via [grunt](http://gruntjs.com/) and test via [vows](http://vowsjs.org/).

@@ -110,3 +110,3 @@ var vows = require('vows'),

// Assert it is on the second line
assert.strictEqual(line, 1, 'The character us on the second line');
assert.strictEqual(line, 1, 'The character at index 26 on the second line');

@@ -117,3 +117,41 @@ // Grab the column number of char

// Assert it is in the nineteenth column
assert.strictEqual(col, 19, 'The character at index 26 is in the zero-th column');
assert.strictEqual(col, 19, 'The character at index 26 is in the nineteenth column');
},
'considers the first character of a line to be on that line': function (indexer) {
var index = 27, // 3 of line 3
char = file.charAt(index);
// Sanity check
assert.strictEqual(char, '3', 'The character we are the positions of finding is 3');
// Grab the line number of char
var line = indexer.lineAt(index);
// Assert it is on the third line
assert.strictEqual(line, 2, 'The character at index 27 on the third line');
// Grab the column number of char
var col = indexer.columnAt(index);
// Assert it is in the zeroth column
assert.strictEqual(col, 0, 'The character at index 27 is in the zero-th column');
},
'considers the last character of a line to be on that line': function (indexer) {
var index = 5, // 1 of line 1
char = file.charAt(index);
// Sanity check
assert.strictEqual(char, '1', 'The character we are the positions of finding is 1');
// Grab the line number of char
var line = indexer.lineAt(index);
// Assert it is on the first line
assert.strictEqual(line, 0, 'The character at index 6 on the first line');
// Grab the column number of char
var col = indexer.columnAt(index);
// Assert it is in the fifth column
assert.strictEqual(col, 5, 'The character at index 6 is in the fifth column');
}

@@ -120,0 +158,0 @@ }