1.0.3 • Published 3 years ago

cell-env v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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>
1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago