Skip to content

DYSDF/cell-env

Repository files navigation

Web Env Reader

Install

npm install cell-env

Usage

Basic Example

import Env from 'cell-env'

const env = Env({
  'some-item': 'string',
  'some-other-item': {}
})

Default Value

import Env from 'cell-env'

const env = Env({
  'default-item': {
    def: 'foobar'
  }
})

Format Value

import Env from 'cell-env'

const env = Env({
  'some-item': {
    fit: value => 'value: ' + value
  },
  'some-other-item': {
    def: 'default-value',
    fit: (v, ctx) => {
      return `self value: ${v}, some-item value: ${ctx['some-item']}`
    }
  }
})

Protect Value

import Env from 'cell-env'

const env = Env({
  'some-protected-item': Env.protect('this is a protected value')
})

Rewrite Value

The following ways:

  • Set variables to urlQuery.
  • Write to a specific global variable(default is window.__env__).

It should be noted that the priority of the urlQuery is higher than the global variable.

Use urlQuery

http://foobar.com?some-item=1&some-other-item=2

urlQuery value default use decodeURIComponent to decode

Use global variable

<script>
window.__env__ = {
  'some-item': 1,
  'some-other-item': 2
}
</script>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published