@zukhruf/python 0.8.42 → 0.8.44
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.
- package/README.md +60 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,8 +4,14 @@ The results of CPython 3.12 in JavaScript, to the last bit: the `sum()` of float
|
|
|
4
4
|
|
|
5
5
|
The package is public on npm. Until 2026-11-07 it was private and reached through a workspace path (ADR 0001); it became public with `@zukhruf/evals`, which depends on it (backlog #3888).
|
|
6
6
|
|
|
7
|
+
The words in these documents have one meaning each. See the glossary in [CONTEXT.md](./CONTEXT.md).
|
|
8
|
+
|
|
7
9
|
## Use it
|
|
8
10
|
|
|
11
|
+
```sh
|
|
12
|
+
npm install @zukhruf/python
|
|
13
|
+
```
|
|
14
|
+
|
|
9
15
|
```ts
|
|
10
16
|
import {
|
|
11
17
|
type JsonData,
|
|
@@ -41,8 +47,62 @@ new RegExp(`[${PYTHON_WORD}]+`, 'u'); // Python's \w
|
|
|
41
47
|
| `toJsonParseValue` | none: the way out of `JsonData` | The value that `JSON.parse` gives for the same text, for code that reads only plain JavaScript, such as a JSON Schema validator. A dict becomes an object, so its integer-like keys move first. An int becomes the nearest `number`, so an int beyond 2^53 loses digits. The int `-0` gives `0`. Keep the `JsonData`, and convert only where such code reads it (ADR 0002). |
|
|
42
48
|
| `JsonParseValue` | none | The type of a value of `toJsonParseValue`: `null`, `boolean`, `number`, `string`, arrays and plain objects of them. |
|
|
43
49
|
|
|
50
|
+
## Errors
|
|
51
|
+
|
|
52
|
+
| Error | When |
|
|
53
|
+
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
54
|
+
| `SyntaxError` | `loadsJson` reads a text that is not JSON, as Python raises a `JSONDecodeError`. Comments and trailing commas are not JSON, and a `NaN`, `Infinity` or `-Infinity` key is not either. |
|
|
55
|
+
| `RangeError` | `loadsJson` reads an int of more than 4300 digits, as Python raises a `ValueError` (`sys.int_info.default_max_str_digits`). `NeumaierSum.mean` gets no value, as Python raises a `ZeroDivisionError`. |
|
|
56
|
+
|
|
57
|
+
The golden test `src/cpython.golden.test.ts` proves each error against CPython 3.12.
|
|
58
|
+
|
|
59
|
+
## API
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
function compareStrings(left: string, right: string): number;
|
|
63
|
+
|
|
64
|
+
function floatRepr(value: number): string;
|
|
65
|
+
|
|
66
|
+
type JsonData =
|
|
67
|
+
| null
|
|
68
|
+
| boolean
|
|
69
|
+
| bigint
|
|
70
|
+
| number
|
|
71
|
+
| string
|
|
72
|
+
| JsonData[]
|
|
73
|
+
| Map<string, JsonData>;
|
|
74
|
+
|
|
75
|
+
function loadsJson(text: string): JsonData; // throws SyntaxError, RangeError
|
|
76
|
+
|
|
77
|
+
class NeumaierSum {
|
|
78
|
+
static of(values: Iterable<number>): number;
|
|
79
|
+
static mean(values: Iterable<number>): number; // throws RangeError for no value
|
|
80
|
+
add(value: number): void;
|
|
81
|
+
get value(): number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const PYTHON_SPACE: string; // the body of a RegExp class, u flag
|
|
85
|
+
const PYTHON_WORD: string; // the body of a RegExp class, u flag
|
|
86
|
+
|
|
87
|
+
type JsonParseValue =
|
|
88
|
+
| null
|
|
89
|
+
| boolean
|
|
90
|
+
| number
|
|
91
|
+
| string
|
|
92
|
+
| JsonParseValue[]
|
|
93
|
+
| { [key: string]: JsonParseValue };
|
|
94
|
+
|
|
95
|
+
function toJsonParseValue(value: JsonData): JsonParseValue;
|
|
96
|
+
```
|
|
97
|
+
|
|
44
98
|
## Documentation
|
|
45
99
|
|
|
100
|
+
**Recipes**
|
|
101
|
+
|
|
102
|
+
- [Give a JsonData value to a schema validator at an edge](./docs/recipes/give-json-data-to-a-validator-at-an-edge.md)
|
|
103
|
+
|
|
104
|
+
**Decisions**
|
|
105
|
+
|
|
46
106
|
- [ADR 0001: one home for the CPython rules that three places copied, reached through a workspace path](docs/adr/0001-one-home-for-the-cpython-rules-that-three-places-copied.md)
|
|
47
107
|
- [ADR 0002: JsonData has one way out, and code takes it only at an edge](docs/adr/0002-json-data-has-one-way-out-at-an-edge.md)
|
|
48
108
|
- [ADR 0003: the mean that a Python program writes as sum(values) / len(values) is NeumaierSum.mean](docs/adr/0003-the-mean-of-a-python-program-is-neumaier-sum-mean.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/python",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.44",
|
|
4
4
|
"description": "The results of CPython 3.12 in JavaScript: the compensated `sum()` of floats, the `repr()` of a float, `json.loads` with the order of keys and ints apart from floats, and the white space of `str.isspace()`.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|