# @profiscience/knockout-contrib-utils-from-js

> [![Version][npm-version-shield]][npm] [![Dependency Status][david-dm-shield]][david-dm] [![Peer Dependency Status][david-dm-peer-shield]][david-dm-peer] [![Dev Dependency Status][david-dm-dev-shield]][david-dm-dev] [![Downloads][npm-stats-shield]][npm-sta

Latest version **2.0.4** (published 2020-10-09) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install @profiscience/knockout-contrib-utils-from-js
pnpm add @profiscience/knockout-contrib-utils-from-js
yarn add @profiscience/knockout-contrib-utils-from-js
bun add @profiscience/knockout-contrib-utils-from-js
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2020-10-09 |
| First published | 2017-11-04 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 25.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Casey Webb |
| Maintainers | barsh, caseywebb |

## Links

- npm: https://www.npmjs.com/package/@profiscience/knockout-contrib-utils-from-js
- Repository: https://github.com/Profiscience/knockout-contrib
- Homepage: https://profiscience.github.io/knockout-contrib/packages/utils.fromJS
- Issues: https://github.com/Profiscience/knockout-contrib/issues
- npm.io page: https://npm.io/package/@profiscience/knockout-contrib-utils-from-js

## Dependencies (1)

- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0

## Recent versions

- 2.0.4 (latest) — 2020-10-09
- 2.0.0-rc.4 (rc) — 2018-10-04
- 2.0.0-alpha.54341a5d (next) — 2018-07-03
- 2.0.3 — 2019-12-12
- 2.0.2 — 2019-12-12
- 2.0.0 — 2019-02-22
- 2.0.0-rc.3 — 2018-08-08
- 2.0.0-rc.2 — 2018-07-20
- 2.0.0-rc.1 — 2018-07-13
- 2.0.0-rc.0 — 2018-06-28
- 1.0.1 — 2018-06-28
- 1.0.0-alpha.10 — 2018-05-23
- 1.0.0-alpha.9 — 2018-05-08
- 1.0.0-alpha.8 — 2018-04-13
- 1.0.0-alpha.7 — 2018-04-05
- … 7 more at https://npm.io/package/@profiscience/knockout-contrib-utils-from-js/versions

## README

# utils.fromJS

[![Version][npm-version-shield]][npm]
[![Dependency Status][david-dm-shield]][david-dm]
[![Peer Dependency Status][david-dm-peer-shield]][david-dm-peer]
[![Dev Dependency Status][david-dm-dev-shield]][david-dm-dev]
[![Downloads][npm-stats-shield]][npm-stats]

[david-dm]: https://david-dm.org/Profiscience/knockout-contrib?path=packages/utils.fromJS
[david-dm-shield]: https://david-dm.org/Profiscience/knockout-contrib/status.svg?path=packages/utils.fromJS
[david-dm-peer]: https://david-dm.org/Profiscience/knockout-contrib?path=packages/utils.fromJS&type=peer
[david-dm-peer-shield]: https://david-dm.org/Profiscience/knockout-contrib/peer-status.svg?path=packages/utils.fromJS
[david-dm-dev]: https://david-dm.org/Profiscience/knockout-contrib?path=packages/utils.fromJS&type=dev
[david-dm-dev-shield]: https://david-dm.org/Profiscience/knockout-contrib/dev-status.svg?path=packages/utils.fromJS
[npm]: https://www.npmjs.com/package/@profiscience/knockout-contrib-utils-from-js
[npm-version-shield]: https://img.shields.io/npm/v/@profiscience/knockout-contrib-utils-from-js.svg
[npm-stats]: http://npm-stat.com/charts.html?package=@profiscience/knockout-contrib-utils-from-js&author=&from=&to=
[npm-stats-shield]: https://img.shields.io/npm/dt/@profiscience/knockout-contrib-utils-from-js.svg?maxAge=2592000

> This package is intended for consumption via the [@profiscience/knockout-contrib] metapackage

## Usage

> fromJS(src[, mapArrayElements = false])

Creates a tree of observables from `src`.

If `mapArrayElements` is true, array elements will be passed to `fromJS` as well, else bare objects/primitives.

The much needed inverse to the undocumented `ko.toJS` function; a dumb version of [ko.mapping.fromJS](http://knockoutjs.com/documentation/plugins-mapping.html) that is [_a lot faster_](#benchmark).

```javascript
import { fromJS } from '@profiscience/knockout-contrib'

const foos = {
  foo: 'foo',
  bar: {
    baz: 'baz',
    qux: ['qux'],
  },
}

fromJS(foos)
// {
//   foo: ko.observable('foo'),
//   bar: {
//     baz: ko.observable('baz'),
//     qux: ko.observableArray([
//       'qux'
//     ])
//   }
// }

fromJS(foos, true)
// {
//   foo: ko.observable('foo'),
//   bar: {
//     baz: ko.observable('baz'),
//     qux: ko.observableArray([
//       ko.observable('qux') <--------- Array contents mapped when second argument is true
//     ])
//   }
// }
```

## Benchmark

```shell
$ ./benchmark.ts
utils.fromJS                    x 316,313 ops/sec ±3.37% (79 runs sampled)
utils.fromJS (mapArrayElements) x 151,401 ops/sec ±3.24% (81 runs sampled)
mapping.fromJS                  x 11,995 ops/sec ±3.82% (81 runs sampled)
```

---
_Source: https://npm.io/package/@profiscience/knockout-contrib-utils-from-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
