# dotject

> Dot notation to object. Supports nesting and same level objects as well as (multiple) value assignment and value overriding.

Latest version **0.6.6** (published 2015-04-27) · 0 weekly downloads

## Install

```sh
npm install dotject
pnpm add dotject
yarn add dotject
bun add dotject
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.6 |
| Published | 2015-04-27 |
| First published | 2014-03-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8.x |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Lee Crossley |
| Maintainers | leecrossley |
| Keywords | dot notation, shortcode, object, json, assignment, value |

## Links

- npm: https://www.npmjs.com/package/dotject
- Repository: git@github.com:leecrossley/dotject
- Homepage: http://ilee.co.uk
- Issues: https://github.com/leecrossley/dotject/issues
- npm.io page: https://npm.io/package/dotject

## Dependencies (1)

- [functional.js](https://npm.io/package/functional.js.md) ~0.6.x

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.6.6 (latest) — 2015-04-27
- 0.6.5 — 2014-12-12
- 0.6.4 — 2014-08-16
- 0.6.3 — 2014-08-11
- 0.6.2 — 2014-06-26
- 0.6.1 — 2014-04-01
- 0.6.0 — 2014-04-01
- 0.5.0 — 2014-03-31
- 0.4.2 — 2014-03-29
- 0.4.1 — 2014-03-29
- 0.4.0 — 2014-03-29
- 0.2.0 — 2014-03-29
- 0.1.0 — 2014-03-29
- 0.0.2 — 2014-03-29
- 0.0.1 — 2014-03-29

## README

# dotject [![Build Status](https://travis-ci.org/leecrossley/dotject.png?branch=master)](https://travis-ci.org/leecrossley/dotject) [![npm version](https://badge.fury.io/js/dotject.png)](https://npmjs.org/package/dotject) [![Dependency Status](https://david-dm.org/leecrossley/dotject/status.png)](https://david-dm.org/leecrossley/dotject#info=dependencies)

Dot notation to object. Shortcode your object creation and value assignments to nested objects.

Supports nesting and same level objects, as well as (multiple) value assignment and value overriding of existing objects.

dotject composition is also available as an [atom package](https://github.com/leecrossley/atom-dotject).

## Getting started

### Using npm

```
npm install dotject --save
```

```
var dotject = require("dotject");
```

## Examples

### Create an object

#### Simple nested properties

Separating property names with dots (like JavaScript dot notation) will create nested objects:

```javascript
dotject("a.b.c");

{
  "a": {
    "b": {
      "c": {}
    }
  }
}

```

#### Properties at the same level

Separating property names with a comma (similar to JavaScript objects) will create properties at the same level:

```javascript
dotject("a,b");

{
  "a": {},
  "b": {}
}

```

This notation can be combined with the dot style notation:

```javascript
dotject("a,b.c");

{
  "a": {},
  "b": {
    "c": {}
  }
}

```

### Extend an existing object

Extend an existing object with new properties by passing the existing object as a second (optional) argument:

```javascript
dotject("b.c", {"a":{}});

{
  "a": {},
  "b": {
    "c": {}
  }
}

```

Existing object values are retained:

```javascript
dotject("b.c", {"a": true});

{
  "a": true,
  "b": {
    "c": {}
  }
}

```

Existing nested object properties are retained:

```javascript
dotject("a.c", {"a":{"b":{}}});

{
  "a": {
    "b": {},
    "c": {}
  }
}

```

### Assign a value

You can assign a value to the last nested property:

```javascript
dotject("a.b", {}, 10);

{
  "a": {
    "b": 10
  }
}

```

### Assign multiple values

You can assign a values to the last nested properties:

```javascript
dotject("a,b.c,d", {}, true, 10, "test");

{
  "a": true,
  "b": {
    "c": 10
  },
  "d": "test"
}

```

### Assign multiple values and override existing

You can assign a values to the last nested properties:

```javascript
dotject("a,b", {"a": false}, true, "test")

{
  "a": true,
  "b": "test"
}

```

## "Real world" example

```javascript
var camera = {isEnabled: true};
camera = dotject("settings.encoding.format,output.data.base64", camera, "JPEG", true);

{
  "isEnabled": true,
  "settings": {
    "encoding": {
      "format": "JPEG"
    }
  },
  "output": {
    "data": {
      "base64": true
    }
  }
}

```

## License

[MIT License](http://ilee.mit-license.org)

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