objects.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export function equals(one, other) {
  6. if (one === other) {
  7. return true;
  8. }
  9. if (one === null || one === undefined || other === null || other === undefined) {
  10. return false;
  11. }
  12. if (typeof one !== typeof other) {
  13. return false;
  14. }
  15. if (typeof one !== 'object') {
  16. return false;
  17. }
  18. if ((Array.isArray(one)) !== (Array.isArray(other))) {
  19. return false;
  20. }
  21. var i, key;
  22. if (Array.isArray(one)) {
  23. if (one.length !== other.length) {
  24. return false;
  25. }
  26. for (i = 0; i < one.length; i++) {
  27. if (!equals(one[i], other[i])) {
  28. return false;
  29. }
  30. }
  31. }
  32. else {
  33. var oneKeys = [];
  34. for (key in one) {
  35. oneKeys.push(key);
  36. }
  37. oneKeys.sort();
  38. var otherKeys = [];
  39. for (key in other) {
  40. otherKeys.push(key);
  41. }
  42. otherKeys.sort();
  43. if (!equals(oneKeys, otherKeys)) {
  44. return false;
  45. }
  46. for (i = 0; i < oneKeys.length; i++) {
  47. if (!equals(one[oneKeys[i]], other[oneKeys[i]])) {
  48. return false;
  49. }
  50. }
  51. }
  52. return true;
  53. }
  54. export function isNumber(val) {
  55. return typeof val === 'number';
  56. }
  57. export function isDefined(val) {
  58. return typeof val !== 'undefined';
  59. }
  60. export function isBoolean(val) {
  61. return typeof val === 'boolean';
  62. }
  63. export function isString(val) {
  64. return typeof val === 'string';
  65. }