1 | ## Modules
|
2 |
|
3 | <dl>
|
4 | <dt><a href="#module_node-object-hash/objectSorter">node-object-hash/objectSorter</a> : <code><a href="#module_node-object-hash/objectSorter..makeObjectSorter..objectToString">objectToString</a></code></dt>
|
5 | <dd><p>Object sorter module.
|
6 | It provides object sorter function constructor.</p>
|
7 | </dd>
|
8 | <dt><a href="#module_node-object-hash">node-object-hash</a> : <code><a href="#module_node-object-hash..apiConstructor">apiConstructor</a></code></dt>
|
9 | <dd><p>Node object hash module.
|
10 | It provides a methods that return object hash or sorted object string.</p>
|
11 | </dd>
|
12 | </dl>
|
13 |
|
14 | <a name="module_node-object-hash/objectSorter"></a>
|
15 |
|
16 | ## node-object-hash/objectSorter : <code>[objectToString](#module_node-object-hash/objectSorter..makeObjectSorter..objectToString)</code>
|
17 | Object sorter module.
|
18 | It provides object sorter function constructor.
|
19 |
|
20 |
|
21 | * [node-object-hash/objectSorter](#module_node-object-hash/objectSorter) : <code>[objectToString](#module_node-object-hash/objectSorter..makeObjectSorter..objectToString)</code>
|
22 | * [~_guessObjectType(obj)](#module_node-object-hash/objectSorter.._guessObjectType) ⇒ <code>string</code> ℗
|
23 | * [~_guessType(obj)](#module_node-object-hash/objectSorter.._guessType) ⇒ <code>string</code> ℗
|
24 | * [~makeObjectSorter([options])](#module_node-object-hash/objectSorter..makeObjectSorter) ⇒ <code>[objectToString](#module_node-object-hash/objectSorter..makeObjectSorter..objectToString)</code> ℗
|
25 | * [~objectToString(obj)](#module_node-object-hash/objectSorter..makeObjectSorter..objectToString) ⇒ <code>string</code> ℗
|
26 |
|
27 | <a name="module_node-object-hash/objectSorter.._guessObjectType"></a>
|
28 |
|
29 | ### node-object-hash/objectSorter~_guessObjectType(obj) ⇒ <code>string</code> ℗
|
30 | Guesses object's type
|
31 |
|
32 | **Kind**: inner method of <code>[node-object-hash/objectSorter](#module_node-object-hash/objectSorter)</code>
|
33 | **Returns**: <code>string</code> - Object type
|
34 | **Access:** private
|
35 |
|
36 | | Param | Type | Description |
|
37 | | --- | --- | --- |
|
38 | | obj | <code>Object</code> | Object to guess type |
|
39 |
|
40 | **Example**
|
41 | ```js
|
42 | var a = [];
|
43 | _guessObjectType(a) === 'array'; // true
|
44 | ```
|
45 | <a name="module_node-object-hash/objectSorter.._guessType"></a>
|
46 |
|
47 | ### node-object-hash/objectSorter~_guessType(obj) ⇒ <code>string</code> ℗
|
48 | Guesses variable type
|
49 |
|
50 | **Kind**: inner method of <code>[node-object-hash/objectSorter](#module_node-object-hash/objectSorter)</code>
|
51 | **Returns**: <code>string</code> - Variable type
|
52 | **Access:** private
|
53 |
|
54 | | Param | Type | Description |
|
55 | | --- | --- | --- |
|
56 | | obj | <code>\*</code> | Variable to guess type |
|
57 |
|
58 | **Example**
|
59 | ```js
|
60 | var a = '';
|
61 | _guessType(a) === 'string'; // true
|
62 | ```
|
63 | <a name="module_node-object-hash/objectSorter..makeObjectSorter"></a>
|
64 |
|
65 | ### node-object-hash/objectSorter~makeObjectSorter([options]) ⇒ <code>[objectToString](#module_node-object-hash/objectSorter..makeObjectSorter..objectToString)</code> ℗
|
66 | Creates object sorter function
|
67 |
|
68 | **Kind**: inner method of <code>[node-object-hash/objectSorter](#module_node-object-hash/objectSorter)</code>
|
69 | **Returns**: <code>[objectToString](#module_node-object-hash/objectSorter..makeObjectSorter..objectToString)</code> - Object sorting function
|
70 | **Access:** private
|
71 |
|
72 | | Param | Type | Default | Description |
|
73 | | --- | --- | --- | --- |
|
74 | | [options] | <code>Object</code> | | Sorter options |
|
75 | | [options.coerce] | <code>boolean</code> | <code>true</code> | Performs type coercion |
|
76 | | [options.sort] | <code>boolean</code> | <code>true</code> | Performs array, object, etc. sorting |
|
77 |
|
78 | **Example**
|
79 | ```js
|
80 | // with coercion
|
81 | var sorter = makeObjectSorter({coerce: true, sort: false});
|
82 | sorter(1) === "1"; // true
|
83 | // with sort
|
84 | var sorter = makeObjectSorter({coerce: false, sort: true});
|
85 | sorter([2, 3, 1]) === [1, 2, 3]; // true
|
86 | ```
|
87 | <a name="module_node-object-hash/objectSorter..makeObjectSorter..objectToString"></a>
|
88 |
|
89 | #### makeObjectSorter~objectToString(obj) ⇒ <code>string</code> ℗
|
90 | Object sorting function
|
91 |
|
92 | **Kind**: inner method of <code>[makeObjectSorter](#module_node-object-hash/objectSorter..makeObjectSorter)</code>
|
93 | **Returns**: <code>string</code> - Sorted string
|
94 | **Access:** private
|
95 |
|
96 | | Param | Type | Description |
|
97 | | --- | --- | --- |
|
98 | | obj | <code>Object</code> | Object to sort |
|
99 |
|
100 | <a name="module_node-object-hash"></a>
|
101 |
|
102 | ## node-object-hash : <code>[apiConstructor](#module_node-object-hash..apiConstructor)</code>
|
103 | Node object hash module.
|
104 | It provides a methods that return object hash or sorted object string.
|
105 |
|
106 |
|
107 | * [node-object-hash](#module_node-object-hash) : <code>[apiConstructor](#module_node-object-hash..apiConstructor)</code>
|
108 | * _instance_
|
109 | * [.sort(obj)](#module_node-object-hash+sort) ⇒ <code>string</code>
|
110 | * [.hash(obj, [opts])](#module_node-object-hash+hash) ⇒ <code>string</code>
|
111 | * _inner_
|
112 | * [~apiConstructor([options])](#module_node-object-hash..apiConstructor) ⇒ <code>[API](#module_node-object-hash..API)</code>
|
113 | * [~API](#module_node-object-hash..API) : <code>Object</code>
|
114 |
|
115 | <a name="module_node-object-hash+sort"></a>
|
116 |
|
117 | ### node-object-hash.sort(obj) ⇒ <code>string</code>
|
118 | Creates sorted string from given object
|
119 |
|
120 | **Kind**: instance method of <code>[node-object-hash](#module_node-object-hash)</code>
|
121 | **Returns**: <code>string</code> - Sorted object string
|
122 | **Access:** public
|
123 | **See**: [objectToString](#module_node-object-hash/objectSorter..makeObjectSorter..objectToString)
|
124 |
|
125 | | Param | Type | Description |
|
126 | | --- | --- | --- |
|
127 | | obj | <code>\*</code> | JS object to be sorted |
|
128 |
|
129 | **Example**
|
130 | ```js
|
131 | var apiConstructor = require('node-object-hash');
|
132 | var sorter = apiConstructor({sort:true, coerce:true}).sort;
|
133 |
|
134 | sort({b: {b: 1, d: 'x'}, c: 2, a: [3, 5, 1]});
|
135 | // "{a:[1,3,5],b:{b:1,d:x},c:2}"
|
136 | ```
|
137 | <a name="module_node-object-hash+hash"></a>
|
138 |
|
139 | ### node-object-hash.hash(obj, [opts]) ⇒ <code>string</code>
|
140 | Creates hash from given object
|
141 |
|
142 | **Kind**: instance method of <code>[node-object-hash](#module_node-object-hash)</code>
|
143 | **Returns**: <code>string</code> - Object hash value
|
144 | **Access:** public
|
145 |
|
146 | | Param | Type | Default | Description |
|
147 | | --- | --- | --- | --- |
|
148 | | obj | <code>\*</code> | | JS object to hash |
|
149 | | [opts] | <code>Object</code> | | Options |
|
150 | | [opts.alg] | <code>string</code> | <code>"sha256"</code> | Crypto algorithm to use |
|
151 | | [opts.enc] | <code>string</code> | <code>"hex"</code> | Hash string encoding |
|
152 |
|
153 | **Example**
|
154 | ```js
|
155 | var apiConstructor = require('node-object-hash');
|
156 | var hasher = apiConstructor({sort:true, coerce:true}).hash;
|
157 |
|
158 | hash({b: {b: 1, d: 'x'}, c: 2, a: [3, 5, 1]});
|
159 | // "4c18ce0dcb1696b329c8568d94a9830da810437d8c9e6cecf5d969780335a26b"
|
160 | ```
|
161 | <a name="module_node-object-hash..apiConstructor"></a>
|
162 |
|
163 | ### node-object-hash~apiConstructor([options]) ⇒ <code>[API](#module_node-object-hash..API)</code>
|
164 | Generates node-object-hash API object
|
165 |
|
166 | **Kind**: inner method of <code>[node-object-hash](#module_node-object-hash)</code>
|
167 | **Returns**: <code>[API](#module_node-object-hash..API)</code> - Node object hash API instance
|
168 |
|
169 | | Param | Type | Default | Description |
|
170 | | --- | --- | --- | --- |
|
171 | | [options] | <code>Object</code> | | Library options |
|
172 | | [options.coerce] | <code>boolean</code> | <code>true</code> | Performs type coercion |
|
173 | | [options.sort] | <code>boolean</code> | <code>true</code> | Performs array, object, etc. sorting |
|
174 | | [options.alg] | <code>string</code> | <code>"sha256"</code> | Default crypto algorithm to use (can be overridden) |
|
175 | | [options.enc] | <code>string</code> | <code>"hex"</code> | Hash string encoding (can be overridden) |
|
176 |
|
177 | **Example**
|
178 | ```js
|
179 | var apiConstructor = require('node-object-hash');
|
180 | var hashSortCoerce = apiConstructor({sort:true, coerce:true});
|
181 | // or
|
182 | var hashSort = apiConstructor({sort:true, coerce:false});
|
183 | // or
|
184 | var hashCoerce = apiConstructor({sort:false, coerce:true});
|
185 |
|
186 | var objects = {
|
187 | a: {
|
188 | a: [{c: 2, a: 1, b: {a: 3, c: 2, b: 0}}],
|
189 | b: [1, 'a', {}, null],
|
190 | },
|
191 | b: {
|
192 | b: ['a', 1, {}, undefined],
|
193 | a: [{c: '2', b: {b: false, c: 2, a: '3'}, a: true}]
|
194 | },
|
195 | c: ['4', true, 0, 2, 3]
|
196 | };
|
197 | hashSortCoerce.hash(objects.a) === hashSortCoerce.hash(objects.b);
|
198 | // returns true
|
199 |
|
200 | hashSortCoerce.sort(object.c);
|
201 | // returns '[0,1,2,3,4]'
|
202 | ```
|
203 | <a name="module_node-object-hash..API"></a>
|
204 |
|
205 | ### node-object-hash~API : <code>Object</code>
|
206 | Node object hash API object
|
207 |
|
208 | **Kind**: inner typedef of <code>[node-object-hash](#module_node-object-hash)</code>
|
209 | **Properties**
|
210 |
|
211 | | Name | Type | Description |
|
212 | | --- | --- | --- |
|
213 | | hash | <code>function</code> | Returns object hash string (see [hash](#module_node-object-hash+hash)) |
|
214 | | sort | <code>function</code> | Returns sorted object string (see [sort](#module_node-object-hash+sort)) |
|
215 |
|