Coder Social home page Coder Social logo

firestore-size's Introduction

Inspired by [email protected]:miktam/sizeof.git

firestore-size

npm bundle size MIT license David npm This tiny package calculates the approximate size (in bytes) of a Firestore document.

Installation

npm i firestore-size

Usage

import sizeof from 'firestore-size'

const snapshot = db
      .collection("data")
      .doc(id)
      .get();
const data = snapshot.data(); 

const bytes = sizeof(data);
console.log( bytes > 1000 ? "I'm in awe of the size of this lad!": "Ew..")
console.log( typeof bytes === 'number'); //true

How it works

  • Array - The sum of the sizes of its values
  • Boolean - 1 byte
  • Bytes - Byte length
  • Date and time - 8 bytes
  • Floating-point number - 8 bytes
  • Geographical point - 16 bytes
  • Integer - 8 bytes
  • Map - The size of the map, calculated the same way as document size
  • Null - 1 byte
  • Reference - The document name size
  • Text string - Number of UTF-8 encoded bytes + 1

More on how the size is calculated in firestore docs - documentation

Important notice

Does not take into account the name of a document.

For a document in the subcollection users/jeff/tasks with a string document ID of my_task_id, the document name size is 6 + 5 + 6 + 11 + 16 = 44 bytes. More about it in the docs.

Does not take into account indexing. Indexes can be disabled - docs - to free up more space.

Caught a Bug?

Fork this repository to your own GitHub account and then clone it to your local device

As always, you can run the tests using: npm test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.