Skip to content

Commit 948f7b6

Browse files
authored
Merge pull request #7 from vmcruz/chore/multiple-type-issues
Chore: Multiple type issues
2 parents fd8634c + 71e860a commit 948f7b6

17 files changed

Lines changed: 1163 additions & 851 deletions

docs/config.md

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
21
## Config
32

43
#### `.include: ChangeType | ChangeType[]`
54

6-
|||
7-
|-|-|
5+
| | |
6+
| --------------- | ------------------------------------------------------------------------------------- |
87
| **Description** | Include only these change types from the diff result. Can be combined with `exclude`. |
9-
| **Default** | `[ChangeType.NOOP, ChangeType.ADD, ChangeType.UPDATE, ChangeType.REMOVE]` |
8+
| **Default** | `[ChangeType.NOOP, ChangeType.ADD, ChangeType.UPDATE, ChangeType.REMOVE]` |
109

1110
```javascript
1211
diff(a, b, { include: [ChangeType.ADD] }); // only additions
@@ -19,10 +18,11 @@ diff(a, b, {
1918
---
2019

2120
#### `.exclude: ChangeType | ChangeType[]`
22-
|||
23-
|-|-|
21+
22+
| | |
23+
| --------------- | ------------------------------------------------------------------------------- |
2424
| **Description** | Excludes the change types from the diff result. Can be combined with `include`. |
25-
| **Default** | `[]` |
25+
| **Default** | `[]` |
2626

2727
```javascript
2828
diff(a, b, { exclude: ChangeType.NOOP });
@@ -34,10 +34,10 @@ diff(a, b, { exclude: [ChangeType.ADD, ChangeType.NOOP] });
3434

3535
#### `.strict: boolean`
3636

37-
|||
38-
|-|-|
37+
| | |
38+
| --------------- | -------------------------------------- |
3939
| **Description** | Performs loose type check if disabled. |
40-
| **Default** | `true` |
40+
| **Default** | `true` |
4141

4242
```javascript
4343
const a = { foo: 1 };
@@ -52,10 +52,10 @@ console.log(diff(a, b, { strict: false }).equal); // true
5252

5353
#### `.showUpdatedOnly: boolean`
5454

55-
|||
56-
|-|-|
55+
| | |
56+
| --------------- | ----------------------------------------------------------------------------------------------------------------------- |
5757
| **Description** | `@sandboxed/diff` creates a `ChangeType.REMOVE` entry for every `ChangeType.UPDATE`. This flags prevents this behavior. |
58-
| **Default** | `false` |
58+
| **Default** | `false` |
5959

6060
```javascript
6161
const a = { foo: 'baz' };
@@ -65,27 +65,28 @@ console.log(diff(a, b, { showUpdatedOnly: true }));
6565
```
6666

6767
**Output**:
68+
6869
```javascript
6970
[
7071
{ type: 'noop', str: '{', depth: 0, path: [] },
7172
{
7273
type: 'update',
7374
str: '"foo": "bar",',
7475
depth: 1,
75-
path: [ 'foo', { deleted: false, value: 'bar' } ]
76+
path: ['foo', { deleted: false, value: 'bar' }],
7677
},
77-
{ type: 'noop', str: '}', depth: 0, path: [] }
78-
]
78+
{ type: 'noop', str: '}', depth: 0, path: [] },
79+
];
7980
```
8081

8182
---
8283

8384
#### `.pathHints: PatHints`
8485

85-
|||
86-
|-|-|
86+
| | |
87+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------- |
8788
| **Description** | Hashmap of `map` and `set` path hints. These strings will be used in the `path` array to provide a hit about the object's type. |
88-
| **Default** | `{ map: '__MAP__', set: '__SET__' }` |
89+
| **Default** | `{ map: '__MAP__', set: '__SET__' }` |
8990

9091
⚠️ Warning: **Complex keys are not recursively diffed**, they are treated as references only.
9192
**Assume that any string entry in the path array comes from plain objects, and numeric entries come from arrays**. Without these hints, tracking back to the origin can be difficult, though can be disabled if not needed.
@@ -104,10 +105,10 @@ console.log(result[1].path); // ['__MAP__', 'foo', { deleted: false, value: 'bar
104105

105106
#### `.redactKeys: Array<string>`
106107

107-
|||
108-
|-|-|
109-
| **Description** | List of keys that should be redacted from the output. Works with `string` based keys and serialized `Symbol`.|
110-
|**Default** | `[ 'password', 'secret', 'token', 'Symbol(password)', 'Symbol (secret)', 'Symbol(token)' ]` |
108+
| | |
109+
| --------------- | ------------------------------------------------------------------------------------------------------------- |
110+
| **Description** | List of keys that should be redacted from the output. Works with `string` based keys and serialized `Symbol`. |
111+
| **Default** | `[ 'password', 'secret', 'token', 'Symbol(password)', 'Symbol (secret)', 'Symbol(token)' ]` |
111112

112113
⚠️ Warning: Only the result `str` is redacted, the `path` array still contains the reference to the actual values. Be careful when using this for logging.
113114

@@ -119,47 +120,48 @@ console.log(diff(a, b, { showUpdatedOnly: true }));
119120
```
120121

121122
**Output**:
123+
122124
```javascript
123125
[
124126
{ type: 'noop', str: '{', depth: 0, path: [] },
125127
{
126128
type: 'update',
127129
str: '"password": "*****",',
128130
depth: 1,
129-
path: [ 'password', { deleted: false, value: 'secret' } ]
131+
path: ['password', { deleted: false, value: 'secret' }],
130132
},
131-
{ type: 'noop', str: '}', depth: 0, path: [] }
132-
]
133+
{ type: 'noop', str: '}', depth: 0, path: [] },
134+
];
133135
```
134136

135137
---
136138

137139
#### `.maxDepth: number`
138140

139-
|||
140-
|-|-|
141+
| | |
142+
| --------------- | ------------------------------------------------------------------------------- |
141143
| **Description** | Max depth that the diffing function can traverse. Throws when reaching the max. |
142-
| **Default** | `50` |
143-
| **Throws** | `Max depth exceeded!` |
144+
| **Default** | `50` |
145+
| **Throws** | `Max depth exceeded!` |
144146

145147
---
146148

147149
#### `.maxKeys: number`
148150

149-
|||
150-
|-|-|
151+
| | |
152+
| --------------- | ------------------------------------------------------------------------- |
151153
| **Description** | Max keys the diffing function can traverse. Throws when reaching the max. |
152-
|**Default** | `50` |
153-
|**Throws** | `Object is too big to continue! Aborting.` |
154+
| **Default** | `50` |
155+
| **Throws** | `Object is too big to continue! Aborting.` |
154156

155157
---
156158

157159
#### `.timeout: number`
158160

159-
|||
160-
|-|-|
161+
| | |
162+
| --------------- | --------------------------------------------- |
161163
| **Description** | Milliseconds before throwing a timeout error. |
162-
|**Default** | `1000` |
163-
|**Throws** | `Diff took too much time! Aborting.` |
164+
| **Default** | `1000` |
165+
| **Throws** | `Diff took too much time! Aborting.` |
164166

165167
⚠️ Warning: The diffing function does not check for object size in memory. The process can still hang if the system is unable to handle the object in memory.

docs/utils.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ Highly configurable util that generates the diff string representation of the di
99
```javascript
1010
import diff from '@sandboxed/diff';
1111

12-
const a = { name: "Alice", age: 25 };
13-
const b = { name: "Alice", age: 26, city: "New York" };
12+
const a = { name: 'Alice', age: 25 };
13+
const b = { name: 'Alice', age: 26, city: 'New York' };
1414

1515
console.log(diff(a, b).toDiffString());
1616
```
1717

1818
**Output**:
19+
1920
```
2021
{
2122
"name": "Alice",
@@ -27,14 +28,13 @@ console.log(diff(a, b).toDiffString());
2728

2829
#### Config options
2930

30-
| config | default | Description |
31-
|------------|----------|-------------|
32-
| withColors | `true` | Formats the string using AnsiColors. |
31+
| config | default | Description |
32+
| ---------- | -------- | -------------------------------------------------------------------------------------------------------------------- |
33+
| withColors | `false` | Formats the string using AnsiColors. |
3334
| colors | `object` | Hashmap for coloring each line based on type: `[ChangeType]: (string) => string`. Should be compatible with `chalk`. |
34-
| symbols | `object` | Hashmap for prefixing each line based on type: `[ChangeType]: string`. |
35-
| wrapper | `[]` | Array with `string` entries. Wraps the result between the first two strings. |
36-
| indentSize | `2` | Whitespace after the `config.symbols`. Indentation is done using `space`. |
37-
35+
| symbols | `object` | Hashmap for prefixing each line based on type: `[ChangeType]: string`. |
36+
| wrapper | `[]` | Array with `string` entries. Wraps the result between the first two strings. |
37+
| indentSize | `2` | Whitespace after the `config.symbols`. Indentation is done using `space`. |
3838

3939
### Equality detection
4040

@@ -45,8 +45,8 @@ Determines whether the inputs are structurally equal based on the diff result. I
4545
```javascript
4646
import diff from '@sandboxed/diff';
4747

48-
const a = { name: "Alice", age: 25 };
49-
const b = { name: "Alice", age: 26, city: "New York" };
48+
const a = { name: 'Alice', age: 25 };
49+
const b = { name: 'Alice', age: 26, city: 'New York' };
5050

5151
console.log(diff(a, b).equal); // Output: false
5252

@@ -68,9 +68,7 @@ import diff, { ChangeType } from '@sandboxed/diff';
6868
const a = { name: 'Alice', foo: new Set([1, 2, 'test']) };
6969
const b = { name: 'Alice', bar: new Set(['test', 2, 1]) };
7070

71-
console.log(
72-
diff(a, b, { exclude: [ChangeType.ADD, ChangeType.REMOVE] }).equal
73-
); // Output: true
71+
console.log(diff(a, b, { exclude: [ChangeType.ADD, ChangeType.REMOVE] }).equal); // Output: true
7472
```
7573

7674
Given that the diff result will not detect the changes in **`foo`**(`ChangeType.REMOVE`) or **`bar`** (`ChangeType.ADD`), the diff result will contain only `ChangeType.NOOP`, causing `.equal` to be `true`.

0 commit comments

Comments
 (0)