Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rgba-image/common

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rgba-image/common

Common types and utils for rgba-image

  • 0.1.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

common

Common types and utils for rgba-image

install

npm install @rgba-image/common

usage

Clamp a value to byte:

const { clampByte } = require( '@rgba-image/common' )

// 123
const r = clampByte( 123.456 )

// 0
const g = clampByte( -1 )

// 255
cosnt b = clampByte( 257 )

Clamp a value to uint32:

const { clampUint32 } = require( '@rgba-image/common' )

// 4294967295
const v = clampUint32( 4294967296.456 )

// etc

Get an index into ImageData:

const { getIndex } = require( '@rgba-image/common' )

const x = 3
const y = 5
const width = 7

const index = getIndex( x, y, width )

Is the current processor little endian?

const { isLittleEndian } = require( '@rgba-image/common' )

if( isLittleEndian ){
  //...
}

Is the current object a valid ImageData?

nb - tests that the object matches the ImageData interface, not that it is an instance of ImageData

const { isImageData } = require( '@rgba-image/common' )

const id = new ImageData( 300, 150 )

if( isImageData( id ) ){
  //...
}

We also add a new interface, GrayData - the definition is the same as ImageData but it is expected to have 1 byte per pixel rather than 4. There is a predicate for checking that they match this:

const { isGrayData } = require( '@rgba-image/common' )

const gray = {
  width: 300,
  height: 150,
  data: new Uint8ClampedArray( 300 * 150 )
}

if( isGrayData( gray ) ){
  //...
}

Get the Uint32 representation of an RGBA color

nb - ImageData stores RGBA in little endian format

const { rgbaToUint32 } = require( '@rgba-image/common' )

const little = rgbaToUint32( 51, 153, 255, 127, true )
const big = rgbaToUint32( 51, 153, 255, 127, false )

TODO

  • Document gradient stop types and predicates - actually, all exported types
  • Add predicates for all exported types except functions

license

MIT License

Copyright (c) 2018 Nik Coughlin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Package last updated on 14 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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