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

env-json-cache

v1.0.6

Published

Load once and use it anywhere in your application. This library allows you to store the state of a key-value pair.(Json value can be loaded)

Downloads

9

Readme

Introduction:

A lightweight library with a singleton caching module that allows for the manipulation of keys and values pairs through set, get, and delete functions. By importing the library, an additional function called loadJson and loadJsonFile makes it possible to load the JSON value to cache and utilize across application files.

MOTO: Load once and use it anywhere in your application. This library allows you to store the state of a key-value pair.

Kindly share your feedback in this issue

Install

npm i env-json-cache

How to use ?

env-json-cache is the singleton object library, user can set get and delete the cache, also they can pass a json object to load. By deafult all the process.env value will be loaded. if user wants to load JSON value they can use "loadJson(data)" or loadJsonFile(filepath) function to push the data to cache.

Functions

  • set()
  • get()
  • getKeys()
  • has()
  • delete()
  • loadJson()
  • loadJsonFile()

Example to fetch all the keys

const env = require('env-json-cache')

// to get all the keys from cache 
console.log(env.getKeys())

Example of get and set functions

const env = require('env-json-cache')

// to set key and value 
env.set("TEST_KEY","TEST_VALUE")

//to get the value from cache
const value = env.get("TEST_KEY")

//env.set("TEST_DEFAULT_VALUE",true)

// get the value if the value is not present default value will return, i.e, second parameter
if(env.get("TEST_DEFAULT_VALUE",false)){
    console.log("Hey am here")
}

Example of delete and has functions

const env = require('env-json-cache')

// function to delete the key value pair
env.delete("TEST_KEY")

// returns boolean value if the key is exist
if(env.has("TEST_KEY")){
    console.log("Hey i have a value")
}

Example of loadJson and loadJsonFile

// test.json

{
    "EXAMPLE1": "TEST"
}

// test1.js file 


const env = require('env-json-cache')

// to load json file in cache 
env.loadJson({JSON_TEST_KEY1:"value", JSON_TEST_KEY2:"value2"}, console) //you can also pass logger as second parameter 

// to load json data from json file location internally uses fs to read the file
env.loadJson("./test.json", console) //you can also pass logger as second parameter to print logs
//test2.js no need to load json or process.env

const env = require('env-json-cache')

//to get the value from cache, this has been set in test1.js as a json value
const value = env.get("JSON_TEST_KEY1")

//to get the value from cache, this has been set in test1.js from json file
const value = env.get("EXAMPLE1")