|
286 | 286 | * for most purposes. |
287 | 287 | * @param string The string to hash. |
288 | 288 | * @returns A hash of the string. |
| 289 | + * @example |
| 290 | + * This example gets the hash of two similar strings. |
| 291 | + * ```js |
| 292 | + * import {getHash} from 'tinybase'; |
| 293 | + * console.log(getHash('Hello, world!')); |
| 294 | + * // -> 3985698964 |
| 295 | + * console.log(getHash('Hello, world?')); |
| 296 | + * // -> 3549480870 |
| 297 | + * ``` |
289 | 298 | * @category Hash |
290 | 299 | * @since v6.2.0 |
291 | 300 | */ |
|
302 | 311 | * @param hash2 A second hash to add or remove from the first. |
303 | 312 | * @returns The resulting hash of the two hashes added to or removed from each |
304 | 313 | * other. |
| 314 | + * @example |
| 315 | + * This example adds two hashes together. |
| 316 | + * ```js |
| 317 | + * import {addOrRemoveHash} from 'tinybase'; |
| 318 | + * |
| 319 | + * const hash1 = 123456789; |
| 320 | + * const hash2 = 987654321; |
| 321 | + * console.log(addOrRemoveHash(hash1, hash2)); |
| 322 | + * // -> 1032168868 |
| 323 | + * |
| 324 | + * console.log(addOrRemoveHash(1032168868, hash1)); |
| 325 | + * // -> 987654321 |
| 326 | + * console.log(addOrRemoveHash(1032168868, hash2)); |
| 327 | + * // -> 123456789 |
| 328 | + * ``` |
305 | 329 | * @category Hash |
306 | 330 | * @since v6.2.0 |
307 | 331 | */ |
|
313 | 337 | * @param tableHashes An object containing each Table Id and its hash. |
314 | 338 | * @param tablesHlc The top-level HLC of the tabular part of the Store. |
315 | 339 | * @returns A hash of the Tables. |
| 340 | + * @example |
| 341 | + * This example gets the hash of the tabular part of a Store. |
| 342 | + * ```js |
| 343 | + * import {getTablesHash} from 'tinybase'; |
| 344 | + * |
| 345 | + * const tableHashes = { |
| 346 | + * pets: 2544679909, // hash of its contents |
| 347 | + * }; |
| 348 | + * const tablesHlc = '03E3B------mmxrx'; |
| 349 | + * |
| 350 | + * console.log(getTablesHash(tableHashes, tablesHlc)); |
| 351 | + * // -> 1835775460 |
| 352 | + * ``` |
316 | 353 | * @category Hash |
317 | 354 | * @since v6.2.0 |
318 | 355 | */ |
|
324 | 361 | * @param tableId The Id of the Table. |
325 | 362 | * @param tableHash The hash of the Table. |
326 | 363 | * @returns A hash of the Table based on its content and Id. |
| 364 | + * @example |
| 365 | + * This example gets the hash of a Table and its Id. |
| 366 | + * ```js |
| 367 | + * import {getTableInTablesHash} from 'tinybase'; |
| 368 | + * |
| 369 | + * const tableId = 'pets'; |
| 370 | + * const tableHash = 2544679909; // hash of its contents |
| 371 | + * |
| 372 | + * console.log(getTableInTablesHash(tableId, tableHash)); |
| 373 | + * // -> 2778789628 |
| 374 | + * ``` |
327 | 375 | * @category Hash |
328 | 376 | * @since v6.2.0 |
329 | 377 | */ |
|
335 | 383 | * @param rowHashes An object containing each Row Id and its hash. |
336 | 384 | * @param tableHlc The HLC of the Table. |
337 | 385 | * @returns A hash of the Table. |
| 386 | + * @example |
| 387 | + * This example gets the hash of a Table. |
| 388 | + * ```js |
| 389 | + * import {getTableHash} from 'tinybase'; |
| 390 | + * |
| 391 | + * const rowHashes = { |
| 392 | + * fido: 703486916, // hash of its contents |
| 393 | + * }; |
| 394 | + * const tableHlc = '03E3B------mmxrx'; |
| 395 | + * |
| 396 | + * console.log(getTableHash(rowHashes, tableHlc)); |
| 397 | + * // -> 2544679909 |
| 398 | + * ``` |
338 | 399 | * @category Hash |
339 | 400 | * @since v6.2.0 |
340 | 401 | */ |
|
346 | 407 | * @param rowId The Id of the Row. |
347 | 408 | * @param rowHash The hash of the Row. |
348 | 409 | * @returns A hash of the Row based on its content and Id. |
| 410 | + * @example |
| 411 | + * This example gets the hash of a Row and its Id. |
| 412 | + * ```js |
| 413 | + * import {getRowInTableHash} from 'tinybase'; |
| 414 | + * |
| 415 | + * const rowId = 'fido'; |
| 416 | + * const rowHash = 703486916; // hash of its contents |
| 417 | + * |
| 418 | + * console.log(getRowInTableHash(rowId, rowHash)); |
| 419 | + * // -> 1600649469 |
| 420 | + * ``` |
349 | 421 | * @category Hash |
350 | 422 | * @since v6.2.0 |
351 | 423 | */ |
|
357 | 429 | * @param cellHashes An object containing each Cell Id and its hash. |
358 | 430 | * @param rowHlc The HLC of the Row. |
359 | 431 | * @returns A hash of the Row. |
| 432 | + * @example |
| 433 | + * This example gets the hash of a Row. |
| 434 | + * ```js |
| 435 | + * import {getRowHash} from 'tinybase'; |
| 436 | + * |
| 437 | + * const cellHashes = { |
| 438 | + * 'species': 3002200796, // hash of 'dog' and '03E3B------mmxrx' |
| 439 | + * }; |
| 440 | + * const rowHlc = '03E3B------mmxrx'; |
| 441 | + * |
| 442 | + * console.log(getRowHash(cellHashes, rowHlc)); |
| 443 | + * // -> 703486916 |
| 444 | + * ``` |
360 | 445 | * @category Hash |
361 | 446 | * @since v6.2.0 |
362 | 447 | */ |
|
368 | 453 | * @param cellId The Id of the Cell. |
369 | 454 | * @param cellHash The hash of the Cell. |
370 | 455 | * @returns A hash of the Cell based on its content and Id. |
| 456 | + * @example |
| 457 | + * This example gets the hash of a Cell and its Id. |
| 458 | + * ```js |
| 459 | + * import {getCellInRowHash} from 'tinybase'; |
| 460 | + * |
| 461 | + * const cellId = 'species'; |
| 462 | + * const cellHash = '3002200796'; // hash of 'dog' and '03E3B------mmxrx' |
| 463 | + * |
| 464 | + * console.log(getCellInRowHash(cellId, cellHash)); |
| 465 | + * // -> 3777304796 |
| 466 | + * ``` |
371 | 467 | * @category Hash |
372 | 468 | * @since v6.2.0 |
373 | 469 | */ |
|
379 | 475 | * @param cell The Cell's value (or `undefined`). |
380 | 476 | * @param cellHlc The HLC of the Cell. |
381 | 477 | * @returns A hash of the Cell. |
| 478 | + * @example |
| 479 | + * This example gets the hash of a Cell and its HLC. |
| 480 | + * ```js |
| 481 | + * import {getCellHash} from 'tinybase'; |
| 482 | + * |
| 483 | + * const cell = 'dog'; |
| 484 | + * const cellHlc = '03E3B------mmxrx'; |
| 485 | + * |
| 486 | + * console.log(getCellHash(cell, cellHlc)); |
| 487 | + * // -> 3002200796 |
| 488 | + * ``` |
382 | 489 | * @category Hash |
383 | 490 | * @since v6.2.0 |
384 | 491 | */ |
|
390 | 497 | * @param valueHashes An object containing each Value Id and its hash. |
391 | 498 | * @param valuesHlc The HLC of the Values. |
392 | 499 | * @returns A hash of the Values. |
| 500 | + * @example |
| 501 | + * This example gets the hash of a Values object. |
| 502 | + * ```js |
| 503 | + * import {getValuesHash} from 'tinybase'; |
| 504 | + * |
| 505 | + * const valueHashes = { |
| 506 | + * meaningOfLife: 312420374, // hash of 42 and '03E3B------mmxrx' |
| 507 | + * }; |
| 508 | + * const valuesHlc = '03E3B------mmxrx'; |
| 509 | + * |
| 510 | + * console.log(getValuesHash(valueHashes, valuesHlc)); |
| 511 | + * // -> 3680840875 |
| 512 | + * ``` |
393 | 513 | * @category Hash |
394 | 514 | * @since v6.2.0 |
395 | 515 | */ |
|
401 | 521 | * @param valueId The Id of the Value. |
402 | 522 | * @param valueHash The hash of the Value. |
403 | 523 | * @returns A hash of the Value based on its content and Id. |
| 524 | + * @example |
| 525 | + * This example gets the hash of a Value and its Id. |
| 526 | + * ```js |
| 527 | + * import {getValueInValuesHash} from 'tinybase'; |
| 528 | + * |
| 529 | + * const valueId = 'meaningOfLife'; |
| 530 | + * const valueHash = 312420374; // hash of 42 and '03E3B------mmxrx' |
| 531 | + * |
| 532 | + * console.log(getValueInValuesHash(valueId, valueHash)); |
| 533 | + * // -> 330198963 |
| 534 | + * ``` |
404 | 535 | * @category Hash |
405 | 536 | * @since v6.2.0 |
406 | 537 | */ |
|
412 | 543 | * @param value The Value (or `undefined`). |
413 | 544 | * @param valueHlc The HLC of the Value. |
414 | 545 | * @returns A hash of the Value. |
| 546 | + * @example |
| 547 | + * This example gets the hash of a Value and its HLC. |
| 548 | + * ```js |
| 549 | + * import {getValueHash} from 'tinybase'; |
| 550 | + * |
| 551 | + * const value = 42; |
| 552 | + * const valueHlc = '03E3B------mmxrx'; |
| 553 | + * |
| 554 | + * console.log(getValueHash(value, valueHlc)); |
| 555 | + * // -> 312420374 |
| 556 | + * ``` |
415 | 557 | * @category Hash |
416 | 558 | * @since v6.2.0 |
417 | 559 | */ |
|
0 commit comments