* Deterministically turns an object into a string. Disregards ordering
(object)
| 72 | * Deterministically turns an object into a string. Disregards ordering |
| 73 | */ |
| 74 | function stringify(object): string { |
| 75 | if (typeof object !== 'object' || object === null) { |
| 76 | if (typeof object === 'string') { |
| 77 | return '"' + object.replace(/\|/g, '%|') + '"'; |
| 78 | } |
| 79 | return object + ''; |
| 80 | } |
| 81 | if (Array.isArray(object)) { |
| 82 | var copy = object.map(stringify); |
| 83 | copy.sort(); |
| 84 | return '[' + copy.join(',') + ']'; |
| 85 | } |
| 86 | var sections = []; |
| 87 | var keys = Object.keys(object); |
| 88 | keys.sort(); |
| 89 | for (var k = 0; k < keys.length; k++) { |
| 90 | sections.push(stringify(keys[k]) + ':' + stringify(object[keys[k]])); |
| 91 | } |
| 92 | return '{' + sections.join(',') + '}'; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Generate a hash from a query, with unique fields for columns, values, order, |