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

dynamodb-utils

v1.0.4

Published

Javascript utility functions mainly for Dynamodb

Downloads

1

Readme

dynamodb-utils

DynamoDB Javascript Utilities

Small group of functions for interacting with the DynamoDB Javascript API.

  • createError
  • createResponse
  • apiCallHandler
  • addObjectProperty
  • byteCount
  • kilobyteCount
  • toKilobyte
  • getObjectSize
  • itemSizeCount
  • objectSizeCount
  • arraySizeCount
  • stringSizeCount
  • numberSizeCount
  • binarySizeCOunt
  • nullBoolSizeCount
  • base64Encode
  • base64Decode
  • createSet
  • createAttribute
  • object2Map
  • objectOrNull
  • attributeOrNull
  • isObject
  • isArray
  • getPropertyPaths
  • toStringPath
  • toArrayPath
  • hasPropertyAtPath
  • hasAttributeAtPath
  • getAttributeAtPath
  • insertMultiObject
  • waitForTable

createError

Constructs and returns a custom error object with an additional "type" property

createResponse

Creates a response object good for AWS Lambda return values from a proxy API gateway

apiCallHandler

Constructs and returns a function using the provided callback.

addObjectProperty

Adds a new property with the name of the passed key parameter and a value of the passed value parameter.

byteCount

Returns the size in bytes of the string

kilobyteCount

Returns the size of the string in kilobytes

toKilobyte

Converts a value in bytes to Kilobytes

getObjectSize

Returns the size of a generic object.

itemSizeCount

Calculates the size (in KB) of the passed item and returns the size as AWS would determine it For example, if BatchWriteItem writes a 500 byte item and a 3.5 KB item, DynamoDB will calculate the size as 5 KB (1 KB + 4 KB), not 4 KB (500 bytes + 3.5 KB)

objectSizeCount

Sums up the size of the passed object and returns the total

arraySizeCount

Sums up the size of the passed array and returns the total

stringSizeCount

Returns the size of a string item (for AWS capactity unit consumption)

numberSizeCount

Returns the size of a number item (for AWS capactity unit consumption)

binarySizeCOunt

Returns the size of a binary/byte array item (for AWS capactity unit consumption)

nullBoolSizeCount

Returns the size of a boolean or null item (for AWS capactity unit consumption)

base64Encode

Encodes a string into a base 64 byte array value

base64Decode

Decodes a base 64 encoded byte array back to a string

createSet

Constructs and returns an AWS DynamoDB Set that can be used for API calls.

createAttribute

Constructs and returns an AWS DynamoDB attribute object that can be used for API calls.

object2Map

Constructs and returns an AWS DynamoDB map object that can be used for API calls.

objectOrNull

Returns either the object passed if it's something or null

attributeOrNull

Returns either the object passed if it's not null, or an attribute equaling the NULL item attribute value

isObject

Returns a boolean value that is true if the parameter passed is a property-based object

isArray

Returns a boolean value that is true if the parameter passed is an array object

getPropertyPaths

Returns an object with property names that match the top-level property names of the passed object, but where each value is an array of sub-level property names.

Example

// given
{
    property1: 'value1',
    property2: [1,2,3],
    property3: {
        property3_1: 'v3.1',
        property3_2: {
            property3_2_1: {
                pickle: 'rick',
                morty: {
                    versions: [
                        {universe: '31c-12', hasVirginity: true},
                        {universe: '31c-13', hasVirginity: true},
                        {universe: '31c-14', hasVirginity: true},
                        {universe: '31d-10', hasVirginity: true},
                        {universe: '31d-43', hasVirginity: true},
                        {universe: '38q-27', hasVirginity: false},
                        {universe: '47z-02', hasVirginity: true}
                    ]
                }
            }
        },
        property3_3: 101
    },
    property4: {
        property4_1: 'baz'
    }
}

// returns
{
    property1: [],
    property2: [
        {'0': []},
        {'1': []},
        {'2': []}
    ],
    property3: [
        {'property3_1': []},
        {
            'property3_2': [
                {
                    'property3_2_1': [
                        {'pickle': []},
                        {
                            'morty': [
                                {
                                    versions: [
                                        {
                                            universe: [],
                                            hasVirginity: []
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {'property3_3': []}
    ],
    property4: [
        {'property4_1': []}
    ]
}

toStringPath

Uses the passed property paths object and the array of strings to return a delimited string of valid child-descending property names.

toArrayPath

Uses the passed property paths object and delimited string of property names to return a valid array of child-descenting property names.

hasPropertyAtPath

Checks if the passed object has a property at the given path

hasAttributeAtPath

Checks if the passed item has an attribute at the given path

getAttributeAtPath

Returns the attribute in the passed AWS item at the given path.

insertMultiObject

A function that will call batchWrite() on a section of the provided data, until all the data has been written.

waitForTable

A function that will kick off another function only after a DynamoDB table has the "ACTIVE" status.