pythonlib 1.0.0 → 1.0.2

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.
Files changed (63) hide show
  1. package/dist/{chunk-6POEDI34.js → chunk-56DGFWIJ.js} +1 -1
  2. package/dist/chunk-56DGFWIJ.js.map +1 -0
  3. package/dist/{chunk-CXKGPD5D.js → chunk-5AOJFFYN.js} +1 -1
  4. package/dist/chunk-5AOJFFYN.js.map +1 -0
  5. package/dist/{chunk-H76SKASU.js → chunk-7BZB2TQF.js} +1 -1
  6. package/dist/chunk-7BZB2TQF.js.map +1 -0
  7. package/dist/{chunk-4QG3772L.js → chunk-CEZSBJJV.js} +1 -1
  8. package/dist/chunk-CEZSBJJV.js.map +1 -0
  9. package/dist/{chunk-HQ42WNKZ.js → chunk-CUP6EPDB.js} +1 -1
  10. package/dist/chunk-CUP6EPDB.js.map +1 -0
  11. package/dist/{chunk-4KYJT3DR.js → chunk-G6PUQTVZ.js} +1 -1
  12. package/dist/chunk-G6PUQTVZ.js.map +1 -0
  13. package/dist/{chunk-LWO6BIAD.js → chunk-OSX7QZAW.js} +1 -1
  14. package/dist/chunk-OSX7QZAW.js.map +1 -0
  15. package/dist/{chunk-EE7SK2GV.js → chunk-QURVRHY2.js} +1 -1
  16. package/dist/chunk-QURVRHY2.js.map +1 -0
  17. package/dist/{chunk-7TH4FCVQ.js → chunk-RSBRI27Z.js} +1 -1
  18. package/dist/chunk-RSBRI27Z.js.map +1 -0
  19. package/dist/{chunk-6ZAJ37MR.js → chunk-TAYRRHJ3.js} +3 -2
  20. package/dist/chunk-TAYRRHJ3.js.map +1 -0
  21. package/dist/{collections-CJur5Wg-.d.ts → collections-BthXtkEp.d.ts} +5 -1
  22. package/dist/collections.d.ts +1 -1
  23. package/dist/collections.js +1 -1
  24. package/dist/{datetime-Bpce8gG2.d.ts → datetime-BM_IjhTq.d.ts} +3 -1
  25. package/dist/datetime.d.ts +1 -1
  26. package/dist/datetime.js +1 -1
  27. package/dist/{functools-NrsZAqJk.d.ts → functools-uIa5g75p.d.ts} +3 -1
  28. package/dist/functools.d.ts +1 -1
  29. package/dist/functools.js +1 -1
  30. package/dist/index.d.ts +272 -54
  31. package/dist/index.js +78 -81
  32. package/dist/index.js.map +1 -1
  33. package/dist/{itertools-Sjl1LB_0.d.ts → itertools-T0rwOk2j.d.ts} +2 -4
  34. package/dist/itertools.d.ts +1 -1
  35. package/dist/itertools.js +1 -1
  36. package/dist/{json-DAlvCadU.d.ts → json-DoWhX04T.d.ts} +1 -0
  37. package/dist/json.d.ts +1 -1
  38. package/dist/json.js +1 -1
  39. package/dist/{math-DwEGjjQ-.d.ts → math-D2NPMc-x.d.ts} +2 -1
  40. package/dist/math.d.ts +1 -1
  41. package/dist/math.js +1 -1
  42. package/dist/{os-C6Nt7Ijx.d.ts → os-CqGKe872.d.ts} +3 -2
  43. package/dist/os.d.ts +1 -1
  44. package/dist/os.js +1 -1
  45. package/dist/{random-BJv_rSpL.d.ts → random-DcS5jtEs.d.ts} +3 -5
  46. package/dist/random.d.ts +1 -1
  47. package/dist/random.js +1 -1
  48. package/dist/{re-B1CHCgyr.d.ts → re-Bo-IOqov.d.ts} +3 -7
  49. package/dist/re.d.ts +1 -1
  50. package/dist/re.js +1 -1
  51. package/dist/string.d.ts +3 -1
  52. package/dist/string.js +1 -1
  53. package/package.json +1 -1
  54. package/dist/chunk-4KYJT3DR.js.map +0 -1
  55. package/dist/chunk-4QG3772L.js.map +0 -1
  56. package/dist/chunk-6POEDI34.js.map +0 -1
  57. package/dist/chunk-6ZAJ37MR.js.map +0 -1
  58. package/dist/chunk-7TH4FCVQ.js.map +0 -1
  59. package/dist/chunk-CXKGPD5D.js.map +0 -1
  60. package/dist/chunk-EE7SK2GV.js.map +0 -1
  61. package/dist/chunk-H76SKASU.js.map +0 -1
  62. package/dist/chunk-HQ42WNKZ.js.map +0 -1
  63. package/dist/chunk-LWO6BIAD.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  random_exports
3
- } from "./chunk-H76SKASU.js";
3
+ } from "./chunk-7BZB2TQF.js";
4
4
  import {
5
5
  re_exports
6
- } from "./chunk-7TH4FCVQ.js";
6
+ } from "./chunk-RSBRI27Z.js";
7
7
  import {
8
8
  Template,
9
9
  asciiLetters,
@@ -17,28 +17,28 @@ import {
17
17
  punctuation,
18
18
  string,
19
19
  whitespace
20
- } from "./chunk-4QG3772L.js";
20
+ } from "./chunk-CEZSBJJV.js";
21
21
  import {
22
22
  collections_exports
23
- } from "./chunk-6ZAJ37MR.js";
23
+ } from "./chunk-TAYRRHJ3.js";
24
24
  import {
25
25
  datetime_exports
26
- } from "./chunk-LWO6BIAD.js";
26
+ } from "./chunk-OSX7QZAW.js";
27
27
  import {
28
28
  functools_exports
29
- } from "./chunk-EE7SK2GV.js";
29
+ } from "./chunk-QURVRHY2.js";
30
30
  import {
31
31
  itertools_exports
32
- } from "./chunk-HQ42WNKZ.js";
32
+ } from "./chunk-CUP6EPDB.js";
33
33
  import {
34
34
  json_exports
35
- } from "./chunk-4KYJT3DR.js";
35
+ } from "./chunk-G6PUQTVZ.js";
36
36
  import {
37
37
  math_exports
38
- } from "./chunk-6POEDI34.js";
38
+ } from "./chunk-56DGFWIJ.js";
39
39
  import {
40
40
  os_exports
41
- } from "./chunk-CXKGPD5D.js";
41
+ } from "./chunk-5AOJFFYN.js";
42
42
  import "./chunk-PZ5AY32C.js";
43
43
 
44
44
  // src/core.ts
@@ -271,20 +271,14 @@ function iter(obj) {
271
271
  return [];
272
272
  }
273
273
  function reversed(iterable) {
274
- const arr = Array.from(iterable);
275
- return {
276
- *[Symbol.iterator]() {
277
- for (let i = arr.length - 1; i >= 0; i--) {
278
- yield arr[i];
279
- }
280
- }
281
- };
274
+ const arr = Array.isArray(iterable) ? iterable : Array.from(iterable);
275
+ return arr.toReversed();
282
276
  }
283
277
  function sorted(iterable, options) {
284
- const arr = Array.from(iterable);
285
278
  const key = options?.key ?? ((x) => x);
286
279
  const reverse = options?.reverse ?? false;
287
- arr.sort((a, b) => {
280
+ const arr = Array.isArray(iterable) ? iterable : Array.from(iterable);
281
+ return arr.toSorted((a, b) => {
288
282
  const aKey = key(a);
289
283
  const bKey = key(b);
290
284
  let cmp;
@@ -295,27 +289,16 @@ function sorted(iterable, options) {
295
289
  }
296
290
  return reverse ? -cmp : cmp;
297
291
  });
298
- return arr;
292
+ }
293
+ function getIterator(iterable) {
294
+ return iterable[Symbol.iterator]();
299
295
  }
300
296
  function map(fn, iterable) {
301
- return {
302
- *[Symbol.iterator]() {
303
- for (const item of iterable) {
304
- yield fn(item);
305
- }
306
- }
307
- };
297
+ return getIterator(iterable).map(fn);
308
298
  }
309
299
  function filter(fn, iterable) {
310
- return {
311
- *[Symbol.iterator]() {
312
- for (const item of iterable) {
313
- if (fn === null ? bool(item) : fn(item)) {
314
- yield item;
315
- }
316
- }
317
- }
318
- };
300
+ const predicate = fn === null ? (x) => bool(x) : fn;
301
+ return getIterator(iterable).filter(predicate);
319
302
  }
320
303
  function list(iterable) {
321
304
  if (iterable === void 0) {
@@ -699,6 +682,39 @@ function format(value, spec) {
699
682
  }
700
683
  return result;
701
684
  }
685
+ function getattr(obj, name, defaultValue) {
686
+ if (obj === null || obj === void 0) {
687
+ if (arguments.length >= 3) {
688
+ return defaultValue;
689
+ }
690
+ throw new TypeError(
691
+ `'${obj === null ? "NoneType" : "undefined"}' object has no attribute '${name}'`
692
+ );
693
+ }
694
+ const target = obj;
695
+ if (name in target) {
696
+ return target[name];
697
+ }
698
+ if (arguments.length >= 3) {
699
+ return defaultValue;
700
+ }
701
+ throw new TypeError(`'${typeof obj}' object has no attribute '${name}'`);
702
+ }
703
+ function hasattr(obj, name) {
704
+ if (obj === null || obj === void 0) {
705
+ return false;
706
+ }
707
+ return name in obj;
708
+ }
709
+ function setattr(obj, name, value) {
710
+ if (obj === null || obj === void 0) {
711
+ throw new TypeError(
712
+ `'${obj === null ? "NoneType" : "undefined"}' object has no attribute '${name}'`
713
+ );
714
+ }
715
+ ;
716
+ obj[name] = value;
717
+ }
702
718
 
703
719
  // src/list.ts
704
720
  var list2 = {
@@ -1000,25 +1016,21 @@ var set2 = {
1000
1016
  },
1001
1017
  /**
1002
1018
  * Python set.union() - returns new set with all elements
1019
+ * Uses ES2024 Set.prototype.union()
1003
1020
  */
1004
1021
  union(a, ...others) {
1005
- const result = new Set(a);
1022
+ let result = new Set(a);
1006
1023
  for (const other of others) {
1007
- for (const item of other) {
1008
- result.add(item);
1009
- }
1024
+ result = result.union(other instanceof Set ? other : new Set(other));
1010
1025
  }
1011
1026
  return result;
1012
1027
  },
1013
1028
  /**
1014
1029
  * Python set.intersection() - returns new set with common elements
1030
+ * Uses ES2024 Set.prototype.intersection()
1015
1031
  */
1016
1032
  intersection(a, b) {
1017
- const result = /* @__PURE__ */ new Set();
1018
- for (const item of a) {
1019
- if (b.has(item)) result.add(item);
1020
- }
1021
- return result;
1033
+ return a.intersection(b);
1022
1034
  },
1023
1035
  /**
1024
1036
  * Python set.intersection_update() - keep only common elements
@@ -1030,13 +1042,10 @@ var set2 = {
1030
1042
  },
1031
1043
  /**
1032
1044
  * Python set.difference() - returns new set with elements in a but not in b
1045
+ * Uses ES2024 Set.prototype.difference()
1033
1046
  */
1034
1047
  difference(a, b) {
1035
- const result = /* @__PURE__ */ new Set();
1036
- for (const item of a) {
1037
- if (!b.has(item)) result.add(item);
1038
- }
1039
- return result;
1048
+ return a.difference(b);
1040
1049
  },
1041
1050
  /**
1042
1051
  * Python set.difference_update() - remove elements found in b
@@ -1048,58 +1057,40 @@ var set2 = {
1048
1057
  },
1049
1058
  /**
1050
1059
  * Python set.symmetric_difference() - returns new set with elements in either but not both
1060
+ * Uses ES2024 Set.prototype.symmetricDifference()
1051
1061
  */
1052
1062
  symmetricDifference(a, b) {
1053
- const result = /* @__PURE__ */ new Set();
1054
- for (const item of a) {
1055
- if (!b.has(item)) result.add(item);
1056
- }
1057
- for (const item of b) {
1058
- if (!a.has(item)) result.add(item);
1059
- }
1060
- return result;
1063
+ return a.symmetricDifference(b);
1061
1064
  },
1062
1065
  /**
1063
1066
  * Python set.symmetric_difference_update() - update with symmetric difference
1067
+ * Uses ES2024 Set.prototype.symmetricDifference()
1064
1068
  */
1065
1069
  symmetricDifferenceUpdate(a, b) {
1066
- const toAdd = [];
1067
- const toRemove = [];
1068
- for (const item of a) {
1069
- if (b.has(item)) toRemove.push(item);
1070
- }
1071
- for (const item of b) {
1072
- if (!a.has(item)) toAdd.push(item);
1073
- }
1074
- for (const item of toRemove) a.delete(item);
1075
- for (const item of toAdd) a.add(item);
1070
+ const result = a.symmetricDifference(b);
1071
+ a.clear();
1072
+ for (const item of result) a.add(item);
1076
1073
  },
1077
1074
  /**
1078
1075
  * Python set.isSubset() - test if all elements are in other
1076
+ * Uses ES2024 Set.prototype.isSubsetOf()
1079
1077
  */
1080
1078
  isSubset(a, b) {
1081
- for (const item of a) {
1082
- if (!b.has(item)) return false;
1083
- }
1084
- return true;
1079
+ return a.isSubsetOf(b);
1085
1080
  },
1086
1081
  /**
1087
1082
  * Python set.isSuperset() - test if all other elements are in this set
1083
+ * Uses ES2024 Set.prototype.isSupersetOf()
1088
1084
  */
1089
1085
  isSuperset(a, b) {
1090
- for (const item of b) {
1091
- if (!a.has(item)) return false;
1092
- }
1093
- return true;
1086
+ return a.isSupersetOf(b);
1094
1087
  },
1095
1088
  /**
1096
1089
  * Python set.isDisjoint() - test if no common elements
1090
+ * Uses ES2024 Set.prototype.isDisjointFrom()
1097
1091
  */
1098
1092
  isDisjoint(a, b) {
1099
- for (const item of a) {
1100
- if (b.has(item)) return false;
1101
- }
1102
- return true;
1093
+ return a.isDisjointFrom(b);
1103
1094
  }
1104
1095
  };
1105
1096
 
@@ -1180,6 +1171,9 @@ var isinstance2 = isinstance;
1180
1171
  var type2 = type;
1181
1172
  var input2 = input;
1182
1173
  var format2 = format;
1174
+ var getattr2 = getattr;
1175
+ var hasattr2 = hasattr;
1176
+ var setattr2 = setattr;
1183
1177
  export {
1184
1178
  abs2 as abs,
1185
1179
  all2 as all,
@@ -1200,6 +1194,8 @@ export {
1200
1194
  floorDiv2 as floorDiv,
1201
1195
  format2 as format,
1202
1196
  functools,
1197
+ getattr2 as getattr,
1198
+ hasattr2 as hasattr,
1203
1199
  hex2 as hex,
1204
1200
  input2 as input,
1205
1201
  int2 as int,
@@ -1227,6 +1223,7 @@ export {
1227
1223
  reversed2 as reversed,
1228
1224
  round2 as round,
1229
1225
  set3 as set,
1226
+ setattr2 as setattr,
1230
1227
  slice2 as slice,
1231
1228
  sorted2 as sorted,
1232
1229
  sprintf2 as sprintf,