@dxos/util 0.7.5-main.9d26e3a → 0.7.5-main.e9bb01b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,39 @@ var distinctBy = (array, selector) => {
33
33
  return true;
34
34
  });
35
35
  };
36
+ var partition = (array, guard) => {
37
+ return array.reduce(([accepted, rejected], item, index, array2) => guard(item, index, array2) ? [
38
+ [
39
+ ...accepted,
40
+ item
41
+ ],
42
+ rejected
43
+ ] : [
44
+ accepted,
45
+ [
46
+ ...rejected,
47
+ item
48
+ ]
49
+ ], [
50
+ [],
51
+ []
52
+ ]);
53
+ };
54
+
55
+ // packages/common/util/src/array-to-hex.ts
56
+ var byteToHex = [];
57
+ for (let n = 0; n <= 255; ++n) {
58
+ const hexOctet = n.toString(16).padStart(2, "0");
59
+ byteToHex.push(hexOctet);
60
+ }
61
+ var arrayToHex = (buf) => {
62
+ const buff = new Uint8Array(buf);
63
+ const hexOctets = [];
64
+ for (let i = 0; i < buff.length; ++i) {
65
+ hexOctets.push(byteToHex[buff[i]]);
66
+ }
67
+ return hexOctets.join("");
68
+ };
36
69
 
37
70
  // packages/common/util/src/binder.ts
38
71
  import util from "@dxos/node-std/util";
@@ -1203,6 +1236,22 @@ var inferRecordOrder = (objectMap, order = []) => {
1203
1236
  }, {}), objectMap);
1204
1237
  };
1205
1238
 
1239
+ // packages/common/util/src/order-keys.ts
1240
+ var orderKeys = (obj, order) => {
1241
+ const ordered = {};
1242
+ for (const key of order) {
1243
+ if (key in obj) {
1244
+ ordered[key] = obj[key];
1245
+ }
1246
+ }
1247
+ for (const key in obj) {
1248
+ if (!(key in ordered)) {
1249
+ ordered[key] = obj[key];
1250
+ }
1251
+ }
1252
+ return ordered;
1253
+ };
1254
+
1206
1255
  // packages/common/util/src/pick.ts
1207
1256
  var pick = (obj, keys) => {
1208
1257
  return keys.reduce((result, key) => {
@@ -1272,6 +1321,20 @@ var getHostPlatform = () => {
1272
1321
  }
1273
1322
  };
1274
1323
 
1324
+ // packages/common/util/src/position.ts
1325
+ var byPosition = (a, b) => {
1326
+ const aPosition = a.position ?? "static";
1327
+ const bPosition = b.position ?? "static";
1328
+ if (aPosition === bPosition) {
1329
+ return 0;
1330
+ } else if (aPosition === "hoist" || bPosition === "fallback") {
1331
+ return -1;
1332
+ } else if (bPosition === "hoist" || aPosition === "fallback") {
1333
+ return 1;
1334
+ }
1335
+ return 0;
1336
+ };
1337
+
1275
1338
  // packages/common/util/src/random.ts
1276
1339
  var randomInt = (max, min = 0) => {
1277
1340
  min = Math.ceil(min);
@@ -1931,19 +1994,12 @@ var WeakDictionary = class {
1931
1994
  }
1932
1995
  };
1933
1996
 
1934
- // packages/common/util/src/array-to-hex.ts
1935
- var byteToHex = [];
1936
- for (let n = 0; n <= 255; ++n) {
1937
- const hexOctet = n.toString(16).padStart(2, "0");
1938
- byteToHex.push(hexOctet);
1939
- }
1940
- var arrayToHex = (buf) => {
1941
- const buff = new Uint8Array(buf);
1942
- const hexOctets = [];
1943
- for (let i = 0; i < buff.length; ++i) {
1944
- hexOctets.push(byteToHex[buff[i]]);
1997
+ // packages/common/util/src/string.ts
1998
+ var capitalize = (str) => {
1999
+ if (str.length === 0) {
2000
+ return "";
1945
2001
  }
1946
- return hexOctets.join("");
2002
+ return str.charAt(0).toUpperCase() + str.slice(1);
1947
2003
  };
1948
2004
 
1949
2005
  // packages/common/util/src/remove-undefined-keys.ts
@@ -1958,22 +2014,6 @@ var removeUndefinedProperties = (object) => {
1958
2014
  }
1959
2015
  return object;
1960
2016
  };
1961
-
1962
- // packages/common/util/src/order-keys.ts
1963
- var orderKeys = (obj, order) => {
1964
- const ordered = {};
1965
- for (const key of order) {
1966
- if (key in obj) {
1967
- ordered[key] = obj[key];
1968
- }
1969
- }
1970
- for (const key in obj) {
1971
- if (!(key in ordered)) {
1972
- ordered[key] = obj[key];
1973
- }
1974
- }
1975
- return ordered;
1976
- };
1977
2017
  export {
1978
2018
  BitField,
1979
2019
  Callback,
@@ -1994,6 +2034,8 @@ export {
1994
2034
  arraysEqual,
1995
2035
  boolGuard,
1996
2036
  bufferToArray,
2037
+ byPosition,
2038
+ capitalize,
1997
2039
  chunkArray,
1998
2040
  compareMulti,
1999
2041
  compareObject,
@@ -2054,6 +2096,7 @@ export {
2054
2096
  numericalValues,
2055
2097
  omit,
2056
2098
  orderKeys,
2099
+ partition,
2057
2100
  pick,
2058
2101
  pickBy,
2059
2102
  randomInt,