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

ascii-grid

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ascii-grid - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

2

package.json
{
"name": "ascii-grid",
"version": "1.0.1",
"version": "1.1.0",
"description": "Identify and Read an ARC/INFO ASCII Grid",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -9,2 +9,7 @@ # ascii-grid: beta

# install
```bash
npm install ascii-grid
```
# usage

@@ -94,2 +99,21 @@ ## identify ascii grid files

*/
```
```
## Reading Pixel Values into a Flat Array
Sometimes you may require the data to be returned in a one-dimensional flat array
instead of split up into rows. To do so, set flat to true like below
```javascript
const parseAsciiGridData = require("ascii-grid/parse-ascii-grid-data");
const result = await parseAsciiGridData({
data: buffer,
flat: true
});
/*
result's values array is as long as width * height
{
values: [55.874908, 57.874924, 58.874939, ...]
}
*/
```

@@ -26,3 +26,4 @@ const getByte = require("get-byte");

end_row, // index of last row (using zero-based index)
meta
meta,
flat = false
}) => {

@@ -33,4 +34,7 @@ if (debug_level >= 1) console.time("[asci-grid] parse-ascii-grid-data took");

let row = [];
let num = "";
let numstr = "";
if (end_column < start_column) throw new Error("[ascii-grid/parse-ascii-grid-data] end_column must be greater than or equal to start_column");
if (end_row < start_row) throw new Error("[ascii-grid/parse-ascii-grid-data] end_row must be greater than or equal to start_row");
const read_length = Math.min(data.length, max_read_length);

@@ -76,4 +80,11 @@ if (debug_level >= 1) console.log("[ascii-grid/parse-ascii-grid-data] read_length:", read_length);

if (num !== "" && c >= start_column && c <= end_column) {
row.push(parseFloat(num));
if (numstr !== "" && c >= start_column && c <= end_column) {
const num = parseFloat(numstr);
if (flat) {
if (r >= start_row && r <= end_row) {
table.push(num);
}
} else {
row.push(num);
}
} else {

@@ -83,7 +94,7 @@ if (debug_level >= 2) console.log("[ascii-grid/parse-ascii-grid-data] skipping value at [", r, "][", c, "]");

num = "";
numstr = "";
// reached end of the row
if (c == meta.ncols - 1) {
if (r >= start_row && r <= end_row) {
if (!flat && r >= start_row && r <= end_row) {
table.push(row);

@@ -105,3 +116,3 @@ }

) {
num += String.fromCharCode(byte);
numstr += String.fromCharCode(byte);
} else if (debug_level >= 2) {

@@ -108,0 +119,0 @@ console.error("[ascii-grid/parse-ascii-grid-data]: unknown byte", [byte]);

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