# notation

> Utility for modifying / processing the contents of Javascript objects or arrays via object notation strings or globs.

Latest version **3.0.2** (published 2026-11-14) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 70/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2026-11-14 |
| First published | 2016-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 261.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 29 |
| Author | Onur Yıldırım |
| Maintainers | onury |
| Keywords | object, array, notation, dot-notation, property, bracket, glob, pointer, enumerable, template, placeholder, data, value, parse, build |

## Links

- npm: https://www.npmjs.com/package/notation
- Repository: https://github.com/onury/notation
- Homepage: https://onury.io/notation
- Issues: https://github.com/onury/notation/issues
- npm.io page: https://npm.io/package/notation

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2026-11-14
- 3.0.1 — 2026-06-23
- 3.0.0 — 2026-06-15
- 2.0.0 — 2020-09-03
- 1.3.6 — 2018-02-24
- 1.3.5 — 2017-10-04
- 1.3.0 — 2017-09-30
- 1.1.0 — 2016-09-26
- 1.0.0 — 2016-05-06

## README

<p align="center">
  <a href="https://onury.io/notation"><img src="https://raw.githubusercontent.com/onury/notation/master/notation-logo.svg" width="420" alt="Notation.js" /></a>
</p>

<p align="center">
  <a href="https://github.com/onury/notation/actions/workflows/ci.yml"><img src="https://github.com/onury/notation/actions/workflows/ci.yml/badge.svg" alt="build" /></a>
  <a href="#quality"><img src="https://img.shields.io/badge/coverage-100%25-2BB150?logo=vitest&logoColor=%23FDC72B&style=flat" alt="coverage" /></a>
  <a href="https://stryker-mutator.io/docs/"><img src="https://img.shields.io/badge/mutation-84%25-2BB150?style=flat" alt="mutation score" /></a>
  <a href="https://www.npmjs.com/package/notation"><img src="https://img.shields.io/npm/v/notation.svg?style=flat&label=&color=%23C6234B&logo=npm" alt="version" /></a>
  <a href="https://www.npmjs.com/package/notation"><img src="https://img.shields.io/npm/dt/notation.svg?style=flat&color=2BB150" alt="downloads" /></a>
  <a href="https://gist.github.com/onury/d3f3d765d7db2e8b2d050d14315f2ac7"><img src="https://img.shields.io/badge/ESM-F7DF1E?style=flat" alt="ESM" /></a>
  <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TS-3260C7?style=flat" alt="TS" /></a>
  <a href="https://github.com/onury/notation/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/notation.svg?style=flat&color=blue" alt="license" /></a>
  <a href="https://onury.io/notation"><img src="https://img.shields.io/badge/docs-onury.io-c27cf4?style=flat" alt="documentation" /></a>
</p>

> This module is **ESM** 🔆. Please [**read this**](https://gist.github.com/onury/d3f3d765d7db2e8b2d050d14315f2ac7).

📖 &nbsp;**Full documentation & guides:** &nbsp;**[onury.io/notation](https://onury.io/notation)**

A utility for reading, modifying, and filtering the contents of JavaScript objects and arrays — using object/bracket **notation** strings or **glob** patterns.

```js
Notation.create({ x: 1 }).set('some.prop', true).filter(['*.prop']).value
// { some: { prop: true } }
```

> [!IMPORTANT]
> This library is intended for **data objects** with enumerable properties. It does **not** preserve an object's prototype chain, and does not support objects with circular references.

## Table of Contents
- [Usage](#usage)
- [Notation](#notation)
- [Glob Notation](#glob-notation)
- [Filtering Data with Glob patterns](#filtering-data-with-glob-patterns)
- [Object and Bracket Notation Syntax](#object-and-bracket-notation-syntax)
- [Globs and Data Integrity](#globs-and-data-integrity)
- [Source Object Mutation](#source-object-mutation)
- [Documentation](#documentation)
- [Quality](#quality)

## Usage

Install via **NPM**:

```sh
npm i notation
```

```js
import { Notation } from 'notation';
```


## Notation
`Notation` is a class for modifying or inspecting the contents (property keys and values) of a data object or array.

When **reading or inspecting** an **enumerable** property value such as `obj.very.deep.prop`; with pure JS, you would have to do several checks:
```js
if (obj 
        && obj.hasOwnProperty('very') 
        && obj.very.hasOwnProperty('deep')  
        && obj.very.deep.hasOwnProperty('prop')
    ) {
    return obj.very.deep.prop === undefined ? defaultValue : obj.very.deep.prop;
}
```
With `Notation`, you can do this:
```js
const notate = Notation.create;
return notate(obj).get('very.deep.prop', defaultValue);
```
You can also **inspect & get** the value:
```js
console.log(notate(obj).inspectGet('very.deep.prop'));
// {
//     notation: 'very.deep.prop',
//     has: true,
//     value: 'some value',
//     type: 'string',
//     level: 3,
//     lastNote: 'prop'
// }
```

To **modify** or **build** a data object:

```js
const notate = Notation.create;
const obj = { car: { brand: "Dodge", model: "Charger" }, dog: { breed: "Akita" } };
notate(obj)                          // initialize. equivalent to `new Notation(obj)`
    .set('car.color', 'red')         // { car: { brand: "Dodge", model: "Charger", color: "red" }, dog: { breed: "Akita" } }
    .remove('car.model')             // { car: { brand: "Dodge", color: "red" }, dog: { breed: "Akita" } }
    .filter(['*', '!car'])           // { dog: { breed: "Akita" } } // equivalent to .filter(['dog'])
    .flatten()                       // { "dog.breed": "Akita" }
    .expand()                        // { dog: { breed: "Akita" } }
    .merge({ 'dog.color': 'white' }) // { dog: { breed: "Akita", color: "white" } }
    .copyFrom(other, 'boat.name')    // { dog: { breed: "Akita", color: "white" }, boat: { name: "Mojo" } }
    .rename('boat.name', 'dog.name') // { dog: { breed: "Akita", color: "white", name: "Mojo" } }
    .value;                          // result object ^
```
See the [documentation][docs] for more...

## Glob Notation

With a glob-notation, you can use wildcard stars `*` and bang `!` prefix. A wildcard star will include all the properties at that level and a bang prefix negates that notation for exclusion.

- Only **`Notation#filter()`** method accepts glob notations. Regular notations (without any wildcard `*` or `!` prefix) should be used with all other members of the **`Notation`** class.
- For raw Glob operations, you can use the **`NotationGlob`** class.

### Normalizing a glob notation list

Removes duplicates, redundant items and logically sorts the array:
```js
import { NotationGlob } from 'notation';

const globs = ['*', '!id', 'name', 'car.model', '!car.*', 'id', 'name', 'age'];
console.log(NotationGlob.normalize(globs));
// ——» ['*', '!car.*', '!id', 'car.model']
```

In the normalized result `['*', '!car.*', '!id', 'car.model']`:
- `id` is removed and `!id` (negated version) is kept. (In normalization, negated always wins over the positive, if both are same).
- Duplicate glob, `name` is removed. The remaining `name` is also removed bec. `*` renders it redundant; which covers all possible notations.
- (In non-restrictive mode) `car.model` is kept (although `*` matches it) bec. it's explicitly defined while we have a negated glob that also matches it: `!car.*`.

```js
console.log(NotationGlob.normalize(globs, { restrictive: true }));
// ——» ['*', '!car.*', '!id']
```
- In restrictive mode, negated removes every match.

> [!NOTE]
> `Notation#filter()` and `NotationGlob.union()` methods automatically pre-normalize the given glob list(s).

### Union of two glob notation lists

Unites two glob arrays optimistically and sorts the result array logically:
```js
const globsA = ['*', '!car.model', 'car.brand', '!*.age'];
const globsB = ['car.model', 'user.age', 'user.name'];
const union = NotationGlob.union(globsA, globsB); 
console.log(union);
// ——» ['*', '!*.age', 'user.age']
```
In the united result `['*', '!*.age', 'user.age']`:
- (negated) `!car.model` of `globsA` is removed because `globsB` has the exact positive version of it. (In union, positive wins over the negated, if both are same.) 
- But then, `car.model` is redundant and removed bec. we have `*` wildcard, which covers all possible non-negated notations. 
- Same applies to other redundant globs except `user.age` bec. we have a `!*.age` in `globsA`, which matches `user.age`. So both are kept in the final array.

## Filtering Data with Glob patterns

When filtering a data object with a globs array; properties that are explicitly defined with globs or implied with wildcards, will be included. Any matching negated-pattern will be excluded. The resulting object is created from scratch without mutating the original.
```js
const data = {
    car: {
        brand: 'Ford',
        model: 'Mustang',
        age: 52
    },
    user: {
        name: 'John',
        age: 40
    }
};
const globs = ['*', '!*.age', 'user.age'];
const filtered = Notation.create(data).filter(globs).value;
console.log(filtered);
// ——»
// {
//     car: {
//         brand: 'Ford',
//         model: 'Mustang'
//     },
//     user: {
//         name: 'John',
//         age: 40
//     }
// }
```

In **non**-restrictive mode; even though we have the `!*.age` negated glob; `user.age` is still included in the result because it's explicitly defined. 

But you can also do **restrictive** filtering. Let's take the same example:
```js
const globs = ['*', '!*.age', 'user.age'];
const filtered = Notation.create(data).filter(globs, { restrictive: true }).value;
console.log(filtered);
// ——»
// {
//     car: {
//         brand: 'Ford',
//         model: 'Mustang'
//     },
//     user: {
//         name: 'John'
//     }
// }
```
Note that in restrictive mode, `user.age` is removed this time; due to `!*.age` pattern.

## Object and Bracket Notation Syntax

Each note (level) of a notation is validated against **EcmaScript variable syntax**, array index notation and object bracket notation.

### Property Keys
- `x[y]`, `x.1`, `x.y-z`, `x.@` are **incorrect** and will never match. 
- `x["y"]`, `x['1']`, `x["y-z"]`, `x['@']` are **correct** object bracket notations. 

### Array Indexes
- `[0].x` indicates `x` property of the first item of the **root array**.
- `x[1]` indicates second item of `x` property of the **root object**.

### Wildcards
- `*` is valid **wildcard** for **glob** notation. Indicates all properties of an object.
- `[*]` is valid **wildcard** for **glob** notation. Indicates all items of an array.
- `x[*]` is valid **wildcard** for **glob** notation. Indicates all items of `x` property which should be an array.
- `x['*']` just indicates a property/key (star), not a wildcard. Valid **regular** notation.
- `x.*` is valid **wildcard** for **glob** notation.
- `x`, `x.*` and `x.*.*` (and so on) are all **equivalent globs**. All normalize to `x`.
- **Negated** versions are **NOT** equivalent. 
  - `!x` indicates removal of `x`.
  - `!x.*` only indicates removal of all first-level properties of `x` but not itself (empty object).
  - `!x.*.*` only indicates removal of all second-level properties of `x`; but not itself and its first-level properties (`x.*`).
  - Same rule applies for bracket notation or mixed notations. 
    - `[0]` = `[0][*]` but `![0]` ≠ `![0][*]`
    - `x` = `x[*]` but `!x` ≠ `!x[*]`
    - `[*]` = `[*].*` but `![*]` ≠ `![*].*`

### Example
Below, we filter to; 
- keep all properties of the source object,
- remove the second item of `colors` property (which is an array),
- and empty `my-colors` property (which is an object).
```js
const source = {
    name: 'Jack',
    colors: ['blue', 'green', 'red'],
    'my-colors': { '1': 'yellow' }     // non-standard name "my-colors"
};
const globs = ['*', '!colors[1]', '!["my-colors"].*'];
console.log(Notation.create(source).filter(globs).value);
// —» 
// {
//     name: 'Jack',
//     colors: ['blue', 'red'],
//     'my-colors': {}
// }
```
In the example above, `colors` item at index 1 is emptied.

## Globs and Data Integrity

### Glob List Integrity
In a glob list, you cannot have both object and array notations for **root level**. The root level implies the source type which is either an object or array; never both.

For example, `['[*]', '!x.y']` will throw because when you filter a source array with this glob list; `!x.y` will never match since the root `x` indicates an object property (e.g. `source.x`).

### Glob vs Data (Value) Integrity
Each glob you use should conform with the given source object.

For example:
```js
const obj = { x: { y: 1 } };
const globs = ['*', '!x.*'];
console.log(Notation.create(obj).filter(globs).value);
// ——» { x: {} }
```
Here, we used `!x.*` negated glob to remove all the properties of `x` but not itself. So the result object has an `x` property with an empty object as its value. All good.

But in the source object; if the actual value of `x` is not an object, using the same glob list would throw:
```js
const obj = { x: 1 }; // x is number
const globs = ['*', '!x.*'];
console.log(Notation.create(obj).filter(globs).value);
// ——» ERROR
```
This kind of type mismatch is critical so it will throw. The value `1` is a `Number` not an object, so it cannot be emptied with `!x.*`. (But we could have removed it instead, with glob `!x`.)

## Source Object Mutation

The source object or array will be mutated by default (except the `#filter()` method). To prevent mutation; you can call `#clone()` method before calling any method that modifies the object. The source object will be cloned deeply.

```js
const notate = Notation.create;

const mutated = notate(source1).set('newProp', true).value;
console.log(source1.newProp); // ——» true

const cloned = notate(source2).clone().set('newProp', true).value;
console.log('newProp' in source2); // ——» false
console.log(cloned.newProp); // ——» true
```

> [!WARNING]
> `Notation` expects a data object (or array) with enumerable properties. In addition to plain objects and arrays; supported cloneable property/value types are primitives (such as `String`, `Number`, `Boolean`, `Symbol`, `null` and `undefined`) and built-in types (such as `Date` and `RegExp`).
>
> Enumerable properties with types other than these (such as methods, special objects, custom class instances, etc) will be copied by reference. Non-enumerable properties will not be cloned.
>
> If you still need full clone support, you can use a library like lodash. e.g. `Notation.create(_.cloneDeep(source))`

## Documentation

Read the full [**documentation**][docs] — guides, concepts and the API reference. For what changed in v3, see the [change log](#change-log).

## Change-Log

Read the [CHANGELOG][changelog].

## Quality

- **100% test coverage** (statements, branches, functions, lines) — enforced via
  Vitest thresholds. Run `npm run cover`.
- **~84% mutation score** via [StrykerJS](https://stryker-mutator.io/). Run
  `npm run mutation`.

[Mutation testing](https://stryker-mutator.io/docs/) goes beyond coverage: it
makes hundreds of small edits ("mutants") to the source — flipping `>` to `>=`,
`&&` to `||`, returning `undefined`, etc. — and checks that a test **fails** for
each. It catches tests that *execute* code without actually *asserting* its
behavior (the trap where `function getPositive(x){ return x }` reaches 100%
coverage but verifies nothing). Most of the surviving mutants here are
[equivalent mutants](https://stryker-mutator.io/docs/mutation-testing-elements/equivalent-mutants/)
in the glob normalization/cover/union logic — redundant-but-harmless branches
that produce identical results — plus environment-defensive guards. These can't
be killed by definition, so the realistic, healthy target is a high score, not
100%.

## Related Projects

- [**accesscontrol**](https://github.com/onury/accesscontrol) — Role and attribute based access control (RBAC + ABAC) with conditions, enforced ownership, custom actions and mandatory gates.
- [**configuard**](https://github.com/onury/configuard) — Turn flat config rows from a database table into a nested, typed configuration object — with `${...}` templating and accessor-based (ABAC) filtering.

## License

© 2026, Onur Yıldırım. [**MIT**](https://github.com/onury/notation/blob/master/LICENSE) License.

[docs]:https://onury.io/notation
[changelog]:https://github.com/onury/notation/blob/master/CHANGELOG.md

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