Socket
Socket
Sign inDemoInstall

icefog

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icefog

a utility for passing environment/config info from server to client


Version published
Weekly downloads
7
decreased by-30%
Maintainers
0
Weekly downloads
 
Created
Source

icefog

a utility for passing environment/config info from server to client

install

pnpm -D add icefog

use

On the server, create a config string:

import { createConfig } from 'icefog/server'

const configString = createConfig({ isDev: true, token: 'abc' })
// then add this string to your rendered markup
// e.g. - `<div id="app" ${configString}></div>`

Then on the client, read the config string:

import 'icefog/init' // for the default element of '#app'

or

import { initConfig } from 'icefog'
initConfig('my-dom-element')

the config export is then available for use anywhere in your app:

import { config } from 'icefog'

if (config.isDev) // do development-specific things

api

createConfig

createConfig(config: object): string

Creates a base64-encoded, stringified version of the object provided.

initConifg

initConfig(element: (Element | string) = '#app', { windowAttr: string = 'configs', configId: string = '_id' })

  • element is the DOM element you render the configString onto and can be either an Element or a querySelector

config

Effectively the object you provided to createConfig, with any functions stripped

getConfig

getConfig(element: (Element | string) = '#app')

Returns the config found on the element and removes it.

useConfig

useConfig()

Returns the config export, useful in a Typescript environment

FAQs

Package last updated on 04 Aug 2024

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