Skip to content

Commit 4c28280

Browse files
committed
docs: npm usage
1 parent 9a75a24 commit 4c28280

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

README.md

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Node.js mixme
32

43
![Build Status](https://github.com/adaltas/node-mixme/actions/workflows/test.yml/badge.svg)
@@ -30,9 +29,9 @@ snake_case({aA: "1", bB: cC: "2"})
3029
Convert a camel case string to snake case, used internally by `snake_case`.
3130

3231
```js
33-
import { snake_case_str } from "mixme"
32+
import { snake_case_str } from "mixme";
3433

35-
snake_case("myValue")
34+
snake_case("myValue");
3635
// Return "my_value"
3736
```
3837

@@ -41,12 +40,12 @@ snake_case("myValue")
4140
Compare two items and return true if their values match.
4241

4342
```js
44-
import { compare } from "mixme"
43+
import { compare } from "mixme";
4544

46-
compare([{a: 1}], [{a: 1}])
45+
compare([{ a: 1 }], [{ a: 1 }]);
4746
// Return true
4847

49-
compare({a: 1}, {a: 2})
48+
compare({ a: 1 }, { a: 2 });
5049
// Return false
5150
```
5251

@@ -55,9 +54,9 @@ compare({a: 1}, {a: 2})
5554
It is possible to clone a literal object by simply calling `mixme` with this object as the first argument. Use the `clone` function in case you wish to clone any type of argument including arrays:
5655

5756
```js
58-
import { clone } from "mixme"
57+
import { clone } from "mixme";
5958

60-
const target = clone(["a", "b"])
59+
const target = clone(["a", "b"]);
6160
// target is now a copy of source
6261
```
6362

@@ -66,27 +65,27 @@ const target = clone(["a", "b"])
6665
Use the `is_object_literal` function to ensure an object is literate.
6766

6867
```js
69-
import { is_object_literal } from "mixme"
68+
import { is_object_literal } from "mixme";
7069

7170
// {} is literate
72-
is_object_literal({})
71+
is_object_literal({});
7372

7473
// error is not literate
75-
is_object_literal(new Error("Catch me"))
74+
is_object_literal(new Error("Catch me"));
7675

7776
// Array is not literate
78-
is_object_literal([])
77+
is_object_literal([]);
7978
```
8079

8180
### Function `merge(...data)`
8281

83-
The API is minimalist,
82+
The API is minimalist,
8483
Merge all literal object provided as arguments. This function is immutable, the source objects won't be altered.
8584

8685
```js
87-
import { merge } from "mixme"
86+
import { merge } from "mixme";
8887

89-
const target = merge({a: "1"}, {b: "2"});
88+
const target = merge({ a: "1" }, { b: "2" });
9089
// target is {a: "1", b: "2"}
9190
```
9291

@@ -95,10 +94,10 @@ const target = merge({a: "1"}, {b: "2"});
9594
Use the `mutate` function to enrich an object. The first argument will be mutated:
9695

9796
```js
98-
import { mutate } from "mixme"
97+
import { mutate } from "mixme";
9998

100-
const source = {a: "1"};
101-
const target = mutate(source, {b: "2"});
99+
const source = { a: "1" };
100+
const target = mutate(source, { b: "2" });
102101
target.c = "3";
103102
// source and target are both {a: "1", b: "2", c: "3"}
104103
```
@@ -119,9 +118,9 @@ snake_case({aA: "1", bB: cC: "2"})
119118
Convert a camel case string to snake case, used internally by `snake_case`.
120119

121120
```js
122-
import { snake_case_str } from "mixme"
121+
import { snake_case_str } from "mixme";
123122

124-
snake_case("myValue")
123+
snake_case("myValue");
125124
// Return "my_value"
126125
```
127126

@@ -130,26 +129,26 @@ snake_case("myValue")
130129
Create a new object from two objects:
131130

132131
```js
133-
import { merge } from "mixme"
132+
import { merge } from "mixme";
134133

135-
const obj1 = { a_key: "a value", b_key: "b value"}
136-
const obj2 = { b_key: "new b value"}
137-
const result = merge(obj1, obj2)
134+
const obj1 = { a_key: "a value", b_key: "b value" };
135+
const obj2 = { b_key: "new b value" };
136+
const result = merge(obj1, obj2);
138137

139-
assert.eql(result.b_key, "new b value")
138+
assert.eql(result.b_key, "new b value");
140139
```
141140

142141
Merge an existing object with a second one:
143142

144143
```js
145-
import { mutate } from "mixme"
144+
import { mutate } from "mixme";
146145

147-
const obj1 = { a_key: "a value", b_key: "b value"};
148-
const obj2 = { b_key: "new b value"};
149-
const result = mutate(obj1, obj2)
146+
const obj1 = { a_key: "a value", b_key: "b value" };
147+
const obj2 = { b_key: "new b value" };
148+
const result = mutate(obj1, obj2);
150149

151-
assert.eql(result, obj1)
152-
assert.eql(obj1.b_key, "new b value")
150+
assert.eql(result, obj1);
151+
assert.eql(obj1.b_key, "new b value");
153152
```
154153

155154
## Testing
@@ -167,15 +166,14 @@ npm run test
167166
To automatically generate a new version:
168167

169168
```bash
170-
yarn run release
169+
npm run release
171170
```
172171

173172
Package publication is handled by the CI/CD with GitHub action.
174173

175174
Note:
176175

177176
- On release, both the publish and test workflows run in parallel. Not very happy about it but I haven't found a better way.
178-
- `yarn` does not call the "postrelease" script and `npm` fails if the `package-lock.json` file is present and git ignored.
179177

180178
## Contributors
181179

0 commit comments

Comments
 (0)