# cell-env

> front end enviroment reader.

Latest version **1.0.3** (published 2021-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install cell-env
pnpm add cell-env
yarn add cell-env
bun add cell-env
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-11-12 |
| First published | 2021-10-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 253.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | accelerator_top |

## Links

- npm: https://www.npmjs.com/package/cell-env
- Repository: https://github.com/DYSDF/cell-env
- Homepage: https://github.com/DYSDF/cell-env#readme
- Issues: https://github.com/DYSDF/cell-env/issues
- npm.io page: https://npm.io/package/cell-env

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.19

## Recent versions

- 1.0.3 (latest) — 2021-11-12
- 1.0.2 — 2021-10-22
- 1.0.1 — 2021-10-16

## README

# Web Env Reader

### [中文文档](./README-CN.md)

## Install

``` shell
npm install cell-env
```

## Usage

### Basic Example

``` js
import Env from 'cell-env'

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

### Default Value

``` js
import Env from 'cell-env'

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

### Format Value

``` js
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

``` js
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

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

---
_Source: https://npm.io/package/cell-env · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
