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

jshexgrid

v0.0.1

Published

JSHexGrid =========

Downloads

5

Readme

JSHexGrid

JSHexGrid is a JavaScript object which allows analysis of data in byte and text form. It can be used to analyze file content or any other data sources.

An implementation is currently used in the HexReader app for Chrome.

Usage

JSHexGrid can be initialized by using the grid constructor. Parameters are passed using the various properties listed below.

Creating a grid instance

var Grid = new JSHexGrid.grid({
    rows:       // Number of rows to display in grid. 
    (required)  // eg. 16
            
                
    container:  // Calling Grid.render will append grid to this element
    (required)  // eg. document.getElementById('myGrid')
    
    dataSrc:    // This should contain a DataHandler object described below
    (required)  

    colors:     // set colors of grid based on passed object
                // built in themes are available
                // JSHexGrid.theme.default, JSHexGrid.theme.dark, JSHexGrid.theme.light
});

DataHandler

DataHandlers are used to supply the grid with bytes during load time and any time the user scrolls the view.

JSHexGrid comes with a built in File DataHandler. (assuming myFile contains a File retrieved via an <input type='file'/> dialog)

dataSrc: JSHexGrid.dataHandler.file(myFile)

If you're not retrieving data from a File, you can implement your own DataHandler.

Whatever the source of your data, DataHandlers should eventually expose these methods:

getSize(void) should return the total amount of bytes available to be read.

getByteArray(int start, int end, function callback) should get the data bytes starting at offset start and ending at offset end and apply them to the passed callback function as a Uint8Array parameter.

Grid Methods

getBuffer(void)

Returns ArrayBuffer of bytes in current view.

The returned buffer will contain 7 more bytes following the current view (if available). These may be useful for computing 16bit/32bit/64bit values when mouse hovers over last byte in view.

getDimensions(void)

Returns dimension information for grid. This could be useful for proper styling of grid surroundings. The object returned contains this structure:

{
    height:336,    // height of grid in pixels
    width:647,     // width of grid in pixels
    row:{
        height:21, // height of one row in pixels
        count:16   // total number of rows in view
    }
}

 

getElementsByIndex(int index)

Return object with two properties.

getOffset(void)

Returns current view offset. (absolute address of first byte in view)

getSelection

Returns GridSelection object for current selection in view.

getSize(void)

Returns total number of bytes which can fit the current view. (16 x number of rows)

render(void)

Appends the grid element to the element specified by the constructor parameter 'container'.

scrollBy(int rowOffset)

Scrolls view by rowOffset. (use negative values for upward scrolling)

scrollByPage(int pageOffset)

Scrolls view by pageOffset. (use negative values for upward scrolling)

scrollToBottom(void)

Scrolls view to absolute bottom.

scrollToTop(void)

Scrolls view to absolute top. This is identical to showFrom(0).

showFrom(int offset)

Scrolls view so that first byte is at specified offset. Value must be 0 or a multiple of 16.

Grid Events

Several events are emitted by a JSHexGrid instance. Listeners can be added by using the on method.

Event: bytecontext

Emitted when a user right clicks on a byte in the current view.

Grid.on('bytecontext',function(offset) {
    // offset.absolute, position in buffer
    // offset.relative, position in current view
});

Event: byteout

Emitted when the mouse pointer moves out of a byte cell in the current view. (no parameters in callback)

Event: bytehover

Emitted when the mouse pointer moves over a byte cell in the current view.

Grid.on('bytehover',function(offset) {
    // offset.absolute, position in buffer
    // offset.relative, position in current view
});

Event: rangechange

Emitted when a new selection is created or an existant selection is modified.

Grid.on('rangechange',function(curSelect, preSelect) {
    // curSelect, GridSelection object for current selection
    // preSelect, GridSelection object for previous selection
});

Event: update

Emitted when data in the current view changes.

Grid.on('update',function(viewInfo) {
    // viewInfo.offset, position in buffer of first byte in view
    // viewInfo.length, total bytes in view
});