@effectionx/worker 0.3.2 → 0.4.0
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/dist/message-channel.d.ts.map +1 -0
- package/dist/mod.d.ts +4 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/test-simple-worker.d.ts +2 -0
- package/dist/test-simple-worker.d.ts.map +1 -0
- package/dist/test-simple-worker.js +11 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts.map +1 -0
- package/{esm → dist}/worker-main.d.ts +1 -1
- package/dist/worker-main.d.ts.map +1 -0
- package/{esm → dist}/worker-main.js +34 -16
- package/dist/worker.d.ts.map +1 -0
- package/{esm → dist}/worker.js +3 -4
- package/message-channel.ts +13 -0
- package/mod.ts +3 -0
- package/package.json +22 -16
- package/test-assets/boom-result-worker.ts +5 -0
- package/test-assets/boom-worker.ts +7 -0
- package/test-assets/counter-worker.ts +15 -0
- package/test-assets/crash-worker.ts +1 -0
- package/test-assets/echo-worker.ts +7 -0
- package/test-assets/result-worker.ts +5 -0
- package/test-assets/shutdown-worker.ts +24 -0
- package/test-assets/suspend-worker.ts +4 -0
- package/test-simple-worker.ts +12 -0
- package/tsconfig.json +20 -0
- package/types.ts +38 -0
- package/worker-main.ts +248 -0
- package/worker.test.ts +179 -0
- package/worker.ts +159 -0
- package/esm/_dnt.shims.d.ts +0 -2
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -57
- package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.js +0 -46
- package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts +0 -24
- package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.js +0 -46
- package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts +0 -16
- package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/assert.js +0 -22
- package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +0 -26
- package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +0 -30
- package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts +0 -17
- package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/equal.js +0 -186
- package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts +0 -35
- package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/equals.js +0 -59
- package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts +0 -18
- package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/exists.js +0 -27
- package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts +0 -15
- package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/fail.js +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts +0 -18
- package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/false.js +0 -22
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater.js +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.js +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +0 -23
- package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.js +0 -52
- package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts +0 -25
- package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.js +0 -53
- package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts +0 -19
- package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/less.js +0 -28
- package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.js +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts +0 -18
- package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/match.js +0 -26
- package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts +0 -44
- package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/mod.js +0 -45
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts +0 -21
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.js +0 -33
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.js +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts +0 -18
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.js +0 -26
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts +0 -23
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.js +0 -32
- package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.js +0 -167
- package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts +0 -42
- package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.js +0 -53
- package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts +0 -24
- package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.js +0 -58
- package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts +0 -18
- package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.js +0 -26
- package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts +0 -45
- package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/throws.js +0 -44
- package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts +0 -15
- package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.js +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts +0 -15
- package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.js +0 -20
- package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts +0 -80
- package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.js +0 -116
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts +0 -140
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff.js +0 -276
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts +0 -99
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.js +0 -182
- package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts +0 -29
- package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/format.js +0 -70
- package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts +0 -159
- package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/styles.js +0 -207
- package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts +0 -25
- package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/types.js +0 -3
- package/esm/message-channel.d.ts.map +0 -1
- package/esm/mod.d.ts +0 -4
- package/esm/mod.d.ts.map +0 -1
- package/esm/package.json +0 -3
- package/esm/types.d.ts.map +0 -1
- package/esm/worker-main.d.ts.map +0 -1
- package/esm/worker.d.ts.map +0 -1
- package/script/_dnt.shims.d.ts +0 -2
- package/script/_dnt.shims.d.ts.map +0 -1
- package/script/_dnt.shims.js +0 -60
- package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts +0 -29
- package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.js +0 -49
- package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts +0 -24
- package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.js +0 -49
- package/script/deps/jsr.io/@std/assert/1.0.16/assert.d.ts +0 -16
- package/script/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/assert.js +0 -25
- package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +0 -26
- package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +0 -34
- package/script/deps/jsr.io/@std/assert/1.0.16/equal.d.ts +0 -17
- package/script/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/equal.js +0 -222
- package/script/deps/jsr.io/@std/assert/1.0.16/equals.d.ts +0 -35
- package/script/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/equals.js +0 -62
- package/script/deps/jsr.io/@std/assert/1.0.16/exists.d.ts +0 -18
- package/script/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/exists.js +0 -30
- package/script/deps/jsr.io/@std/assert/1.0.16/fail.d.ts +0 -15
- package/script/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/fail.js +0 -23
- package/script/deps/jsr.io/@std/assert/1.0.16/false.d.ts +0 -18
- package/script/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/false.js +0 -25
- package/script/deps/jsr.io/@std/assert/1.0.16/greater.d.ts +0 -20
- package/script/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/greater.js +0 -32
- package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts +0 -20
- package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.js +0 -32
- package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +0 -23
- package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.js +0 -55
- package/script/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts +0 -25
- package/script/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/is_error.js +0 -56
- package/script/deps/jsr.io/@std/assert/1.0.16/less.d.ts +0 -19
- package/script/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/less.js +0 -31
- package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts +0 -20
- package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.js +0 -32
- package/script/deps/jsr.io/@std/assert/1.0.16/match.d.ts +0 -18
- package/script/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/match.js +0 -29
- package/script/deps/jsr.io/@std/assert/1.0.16/mod.d.ts +0 -44
- package/script/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/mod.js +0 -61
- package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts +0 -21
- package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.js +0 -36
- package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts +0 -20
- package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.js +0 -32
- package/script/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts +0 -18
- package/script/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/not_match.js +0 -29
- package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts +0 -23
- package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.js +0 -35
- package/script/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts +0 -29
- package/script/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/object_match.js +0 -170
- package/script/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts +0 -42
- package/script/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/rejects.js +0 -56
- package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts +0 -24
- package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.js +0 -61
- package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts +0 -18
- package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.js +0 -29
- package/script/deps/jsr.io/@std/assert/1.0.16/throws.d.ts +0 -45
- package/script/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/throws.js +0 -47
- package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts +0 -15
- package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.js +0 -23
- package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts +0 -15
- package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.js +0 -23
- package/script/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts +0 -80
- package/script/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/build_message.js +0 -121
- package/script/deps/jsr.io/@std/internal/1.0.12/diff.d.ts +0 -140
- package/script/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/diff.js +0 -283
- package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts +0 -99
- package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.js +0 -188
- package/script/deps/jsr.io/@std/internal/1.0.12/format.d.ts +0 -29
- package/script/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/format.js +0 -106
- package/script/deps/jsr.io/@std/internal/1.0.12/styles.d.ts +0 -159
- package/script/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/styles.js +0 -252
- package/script/deps/jsr.io/@std/internal/1.0.12/types.d.ts +0 -25
- package/script/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/types.js +0 -4
- package/script/message-channel.d.ts +0 -3
- package/script/message-channel.d.ts.map +0 -1
- package/script/message-channel.js +0 -16
- package/script/mod.d.ts +0 -4
- package/script/mod.d.ts.map +0 -1
- package/script/mod.js +0 -19
- package/script/package.json +0 -3
- package/script/types.d.ts +0 -33
- package/script/types.d.ts.map +0 -1
- package/script/types.js +0 -2
- package/script/worker-main.d.ts +0 -84
- package/script/worker-main.d.ts.map +0 -1
- package/script/worker-main.js +0 -190
- package/script/worker.d.ts +0 -63
- package/script/worker.d.ts.map +0 -1
- package/script/worker.js +0 -124
- /package/{esm → dist}/message-channel.d.ts +0 -0
- /package/{esm → dist}/message-channel.js +0 -0
- /package/{esm → dist}/mod.js +0 -0
- /package/{esm → dist}/types.d.ts +0 -0
- /package/{esm → dist}/types.js +0 -0
- /package/{esm → dist}/worker.d.ts +0 -0
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
const REMOVED = 1;
|
|
4
|
-
const COMMON = 2;
|
|
5
|
-
const ADDED = 3;
|
|
6
|
-
/**
|
|
7
|
-
* Creates an array of common elements between two arrays.
|
|
8
|
-
*
|
|
9
|
-
* @typeParam T The type of elements in the arrays.
|
|
10
|
-
*
|
|
11
|
-
* @param A The first array.
|
|
12
|
-
* @param B The second array.
|
|
13
|
-
*
|
|
14
|
-
* @returns An array containing the common elements between the two arrays.
|
|
15
|
-
*
|
|
16
|
-
* @example Usage
|
|
17
|
-
* ```ts
|
|
18
|
-
* import { createCommon } from "@std/internal/diff";
|
|
19
|
-
* import { assertEquals } from "@std/assert";
|
|
20
|
-
*
|
|
21
|
-
* const a = [1, 2, 3];
|
|
22
|
-
* const b = [1, 2, 4];
|
|
23
|
-
*
|
|
24
|
-
* assertEquals(createCommon(a, b), [1, 2]);
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export function createCommon(A, B) {
|
|
28
|
-
const common = [];
|
|
29
|
-
if (A.length === 0 || B.length === 0)
|
|
30
|
-
return [];
|
|
31
|
-
for (let i = 0; i < Math.min(A.length, B.length); i += 1) {
|
|
32
|
-
const a = A[i];
|
|
33
|
-
const b = B[i];
|
|
34
|
-
if (a !== undefined && a === b) {
|
|
35
|
-
common.push(a);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return common;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return common;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Asserts that the value is a {@linkcode FarthestPoint}.
|
|
45
|
-
* If not, an error is thrown.
|
|
46
|
-
*
|
|
47
|
-
* @param value The value to check.
|
|
48
|
-
*
|
|
49
|
-
* @returns A void value that returns once the assertion completes.
|
|
50
|
-
*
|
|
51
|
-
* @example Usage
|
|
52
|
-
* ```ts
|
|
53
|
-
* import { assertFp } from "@std/internal/diff";
|
|
54
|
-
* import { assertThrows } from "@std/assert";
|
|
55
|
-
*
|
|
56
|
-
* assertFp({ y: 0, id: 0 });
|
|
57
|
-
* assertThrows(() => assertFp({ id: 0 }));
|
|
58
|
-
* assertThrows(() => assertFp({ y: 0 }));
|
|
59
|
-
* assertThrows(() => assertFp(undefined));
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export function assertFp(value) {
|
|
63
|
-
if (value == null ||
|
|
64
|
-
typeof value !== "object" ||
|
|
65
|
-
typeof value?.y !== "number" ||
|
|
66
|
-
typeof value?.id !== "number") {
|
|
67
|
-
throw new Error(`Unexpected value, expected 'FarthestPoint': received ${typeof value}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Creates an array of backtraced differences.
|
|
72
|
-
*
|
|
73
|
-
* @typeParam T The type of elements in the arrays.
|
|
74
|
-
*
|
|
75
|
-
* @param A The first array.
|
|
76
|
-
* @param B The second array.
|
|
77
|
-
* @param current The current {@linkcode FarthestPoint}.
|
|
78
|
-
* @param swapped Boolean indicating if the arrays are swapped.
|
|
79
|
-
* @param routes The routes array.
|
|
80
|
-
* @param diffTypesPtrOffset The offset of the diff types in the routes array.
|
|
81
|
-
*
|
|
82
|
-
* @returns An array of backtraced differences.
|
|
83
|
-
*
|
|
84
|
-
* @example Usage
|
|
85
|
-
* ```ts
|
|
86
|
-
* import { backTrace } from "@std/internal/diff";
|
|
87
|
-
* import { assertEquals } from "@std/assert";
|
|
88
|
-
*
|
|
89
|
-
* assertEquals(
|
|
90
|
-
* backTrace([], [], { y: 0, id: 0 }, false, new Uint32Array(0), 0),
|
|
91
|
-
* [],
|
|
92
|
-
* );
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export function backTrace(A, B, current, swapped, routes, diffTypesPtrOffset) {
|
|
96
|
-
const M = A.length;
|
|
97
|
-
const N = B.length;
|
|
98
|
-
const result = [];
|
|
99
|
-
let a = M - 1;
|
|
100
|
-
let b = N - 1;
|
|
101
|
-
let j = routes[current.id];
|
|
102
|
-
let type = routes[current.id + diffTypesPtrOffset];
|
|
103
|
-
while (true) {
|
|
104
|
-
if (!j && !type)
|
|
105
|
-
break;
|
|
106
|
-
const prev = j;
|
|
107
|
-
if (type === REMOVED) {
|
|
108
|
-
result.unshift({
|
|
109
|
-
type: swapped ? "removed" : "added",
|
|
110
|
-
value: B[b],
|
|
111
|
-
});
|
|
112
|
-
b -= 1;
|
|
113
|
-
}
|
|
114
|
-
else if (type === ADDED) {
|
|
115
|
-
result.unshift({
|
|
116
|
-
type: swapped ? "added" : "removed",
|
|
117
|
-
value: A[a],
|
|
118
|
-
});
|
|
119
|
-
a -= 1;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
result.unshift({ type: "common", value: A[a] });
|
|
123
|
-
a -= 1;
|
|
124
|
-
b -= 1;
|
|
125
|
-
}
|
|
126
|
-
j = routes[prev];
|
|
127
|
-
type = routes[prev + diffTypesPtrOffset];
|
|
128
|
-
}
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Creates a {@linkcode FarthestPoint}.
|
|
133
|
-
*
|
|
134
|
-
* @param k The current index.
|
|
135
|
-
* @param M The length of the first array.
|
|
136
|
-
* @param routes The routes array.
|
|
137
|
-
* @param diffTypesPtrOffset The offset of the diff types in the routes array.
|
|
138
|
-
* @param ptr The current pointer.
|
|
139
|
-
* @param slide The slide {@linkcode FarthestPoint}.
|
|
140
|
-
* @param down The down {@linkcode FarthestPoint}.
|
|
141
|
-
*
|
|
142
|
-
* @returns A {@linkcode FarthestPoint}.
|
|
143
|
-
*
|
|
144
|
-
* @example Usage
|
|
145
|
-
* ```ts
|
|
146
|
-
* import { createFp } from "@std/internal/diff";
|
|
147
|
-
* import { assertEquals } from "@std/assert";
|
|
148
|
-
*
|
|
149
|
-
* assertEquals(
|
|
150
|
-
* createFp(
|
|
151
|
-
* 0,
|
|
152
|
-
* 0,
|
|
153
|
-
* new Uint32Array(0),
|
|
154
|
-
* 0,
|
|
155
|
-
* 0,
|
|
156
|
-
* { y: -1, id: 0 },
|
|
157
|
-
* { y: 0, id: 0 },
|
|
158
|
-
* ),
|
|
159
|
-
* { y: -1, id: 1 },
|
|
160
|
-
* );
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
export function createFp(k, M, routes, diffTypesPtrOffset, ptr, slide, down) {
|
|
164
|
-
if (slide && slide.y === -1 && down && down.y === -1) {
|
|
165
|
-
return { y: 0, id: 0 };
|
|
166
|
-
}
|
|
167
|
-
const isAdding = (down?.y === -1) ||
|
|
168
|
-
k === M ||
|
|
169
|
-
(slide?.y ?? 0) > (down?.y ?? 0) + 1;
|
|
170
|
-
if (slide && isAdding) {
|
|
171
|
-
const prev = slide.id;
|
|
172
|
-
ptr++;
|
|
173
|
-
routes[ptr] = prev;
|
|
174
|
-
routes[ptr + diffTypesPtrOffset] = ADDED;
|
|
175
|
-
return { y: slide.y, id: ptr };
|
|
176
|
-
}
|
|
177
|
-
if (down && !isAdding) {
|
|
178
|
-
const prev = down.id;
|
|
179
|
-
ptr++;
|
|
180
|
-
routes[ptr] = prev;
|
|
181
|
-
routes[ptr + diffTypesPtrOffset] = REMOVED;
|
|
182
|
-
return { y: down.y + 1, id: ptr };
|
|
183
|
-
}
|
|
184
|
-
throw new Error("Unexpected missing FarthestPoint");
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Renders the differences between the actual and expected values.
|
|
188
|
-
*
|
|
189
|
-
* @typeParam T The type of elements in the arrays.
|
|
190
|
-
*
|
|
191
|
-
* @param A Actual value
|
|
192
|
-
* @param B Expected value
|
|
193
|
-
*
|
|
194
|
-
* @returns An array of differences between the actual and expected values.
|
|
195
|
-
*
|
|
196
|
-
* @example Usage
|
|
197
|
-
* ```ts
|
|
198
|
-
* import { diff } from "@std/internal/diff";
|
|
199
|
-
* import { assertEquals } from "@std/assert";
|
|
200
|
-
*
|
|
201
|
-
* const a = [1, 2, 3];
|
|
202
|
-
* const b = [1, 2, 4];
|
|
203
|
-
*
|
|
204
|
-
* assertEquals(diff(a, b), [
|
|
205
|
-
* { type: "common", value: 1 },
|
|
206
|
-
* { type: "common", value: 2 },
|
|
207
|
-
* { type: "removed", value: 3 },
|
|
208
|
-
* { type: "added", value: 4 },
|
|
209
|
-
* ]);
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
export function diff(A, B) {
|
|
213
|
-
const prefixCommon = createCommon(A, B);
|
|
214
|
-
A = A.slice(prefixCommon.length);
|
|
215
|
-
B = B.slice(prefixCommon.length);
|
|
216
|
-
const swapped = B.length > A.length;
|
|
217
|
-
[A, B] = swapped ? [B, A] : [A, B];
|
|
218
|
-
const M = A.length;
|
|
219
|
-
const N = B.length;
|
|
220
|
-
if (!M && !N && !prefixCommon.length)
|
|
221
|
-
return [];
|
|
222
|
-
if (!N) {
|
|
223
|
-
return [
|
|
224
|
-
...prefixCommon.map((value) => ({ type: "common", value })),
|
|
225
|
-
...A.map((value) => ({ type: swapped ? "added" : "removed", value })),
|
|
226
|
-
];
|
|
227
|
-
}
|
|
228
|
-
const offset = N;
|
|
229
|
-
const delta = M - N;
|
|
230
|
-
const length = M + N + 1;
|
|
231
|
-
const fp = Array.from({ length }, () => ({ y: -1, id: -1 }));
|
|
232
|
-
/**
|
|
233
|
-
* Note: this buffer is used to save memory and improve performance. The first
|
|
234
|
-
* half is used to save route and the last half is used to save diff type.
|
|
235
|
-
*/
|
|
236
|
-
const routes = new Uint32Array((M * N + length + 1) * 2);
|
|
237
|
-
const diffTypesPtrOffset = routes.length / 2;
|
|
238
|
-
let ptr = 0;
|
|
239
|
-
function snake(k, A, B, slide, down) {
|
|
240
|
-
const M = A.length;
|
|
241
|
-
const N = B.length;
|
|
242
|
-
const fp = createFp(k, M, routes, diffTypesPtrOffset, ptr, slide, down);
|
|
243
|
-
ptr = fp.id;
|
|
244
|
-
while (fp.y + k < M && fp.y < N && A[fp.y + k] === B[fp.y]) {
|
|
245
|
-
const prev = fp.id;
|
|
246
|
-
ptr++;
|
|
247
|
-
fp.id = ptr;
|
|
248
|
-
fp.y += 1;
|
|
249
|
-
routes[ptr] = prev;
|
|
250
|
-
routes[ptr + diffTypesPtrOffset] = COMMON;
|
|
251
|
-
}
|
|
252
|
-
return fp;
|
|
253
|
-
}
|
|
254
|
-
let currentFp = fp[delta + offset];
|
|
255
|
-
assertFp(currentFp);
|
|
256
|
-
let p = -1;
|
|
257
|
-
while (currentFp.y < N) {
|
|
258
|
-
p = p + 1;
|
|
259
|
-
for (let k = -p; k < delta; ++k) {
|
|
260
|
-
const index = k + offset;
|
|
261
|
-
fp[index] = snake(k, A, B, fp[index - 1], fp[index + 1]);
|
|
262
|
-
}
|
|
263
|
-
for (let k = delta + p; k > delta; --k) {
|
|
264
|
-
const index = k + offset;
|
|
265
|
-
fp[index] = snake(k, A, B, fp[index - 1], fp[index + 1]);
|
|
266
|
-
}
|
|
267
|
-
const index = delta + offset;
|
|
268
|
-
fp[delta + offset] = snake(delta, A, B, fp[index - 1], fp[index + 1]);
|
|
269
|
-
currentFp = fp[delta + offset];
|
|
270
|
-
assertFp(currentFp);
|
|
271
|
-
}
|
|
272
|
-
return [
|
|
273
|
-
...prefixCommon.map((value) => ({ type: "common", value })),
|
|
274
|
-
...backTrace(A, B, currentFp, swapped, routes, diffTypesPtrOffset),
|
|
275
|
-
];
|
|
276
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type { DiffResult } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Unescape invisible characters.
|
|
4
|
-
*
|
|
5
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#escape_sequences}
|
|
6
|
-
*
|
|
7
|
-
* @param string String to unescape.
|
|
8
|
-
*
|
|
9
|
-
* @returns Unescaped string.
|
|
10
|
-
*
|
|
11
|
-
* @example Usage
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { unescape } from "@std/internal/diff-str";
|
|
14
|
-
* import { assertEquals } from "@std/assert";
|
|
15
|
-
*
|
|
16
|
-
* assertEquals(unescape("Hello\nWorld"), "Hello\\n\nWorld");
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare function unescape(string: string): string;
|
|
20
|
-
/**
|
|
21
|
-
* Tokenizes a string into an array of tokens.
|
|
22
|
-
*
|
|
23
|
-
* @param string The string to tokenize.
|
|
24
|
-
* @param wordDiff If true, performs word-based tokenization. Default is false.
|
|
25
|
-
*
|
|
26
|
-
* @returns An array of tokens.
|
|
27
|
-
*
|
|
28
|
-
* @example Usage
|
|
29
|
-
* ```ts
|
|
30
|
-
* import { tokenize } from "@std/internal/diff-str";
|
|
31
|
-
* import { assertEquals } from "@std/assert";
|
|
32
|
-
*
|
|
33
|
-
* assertEquals(tokenize("Hello\nWorld"), ["Hello\n", "World"]);
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function tokenize(string: string, wordDiff?: boolean): string[];
|
|
37
|
-
/**
|
|
38
|
-
* Create details by filtering relevant word-diff for current line and merge
|
|
39
|
-
* "space-diff" if surrounded by word-diff for cleaner displays.
|
|
40
|
-
*
|
|
41
|
-
* @param line Current line
|
|
42
|
-
* @param tokens Word-diff tokens
|
|
43
|
-
*
|
|
44
|
-
* @returns Array of diff results.
|
|
45
|
-
*
|
|
46
|
-
* @example Usage
|
|
47
|
-
* ```ts
|
|
48
|
-
* import { createDetails } from "@std/internal/diff-str";
|
|
49
|
-
* import { assertEquals } from "@std/assert";
|
|
50
|
-
*
|
|
51
|
-
* const tokens = [
|
|
52
|
-
* { type: "added", value: "a" },
|
|
53
|
-
* { type: "removed", value: "b" },
|
|
54
|
-
* { type: "common", value: "c" },
|
|
55
|
-
* ] as const;
|
|
56
|
-
* assertEquals(
|
|
57
|
-
* createDetails({ type: "added", value: "a" }, [...tokens]),
|
|
58
|
-
* [{ type: "added", value: "a" }, { type: "common", value: "c" }]
|
|
59
|
-
* );
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export declare function createDetails(line: DiffResult<string>, tokens: DiffResult<string>[]): DiffResult<string>[];
|
|
63
|
-
/**
|
|
64
|
-
* Renders the differences between the actual and expected strings. Partially
|
|
65
|
-
* inspired from {@link https://github.com/kpdecker/jsdiff}.
|
|
66
|
-
*
|
|
67
|
-
* @param A Actual string
|
|
68
|
-
* @param B Expected string
|
|
69
|
-
*
|
|
70
|
-
* @returns Array of diff results.
|
|
71
|
-
*
|
|
72
|
-
* @example Usage
|
|
73
|
-
* ```ts
|
|
74
|
-
* import { diffStr } from "@std/internal/diff-str";
|
|
75
|
-
* import { assertEquals } from "@std/assert";
|
|
76
|
-
*
|
|
77
|
-
* assertEquals(diffStr("Hello!", "Hello"), [
|
|
78
|
-
* {
|
|
79
|
-
* type: "removed",
|
|
80
|
-
* value: "Hello!\n",
|
|
81
|
-
* details: [
|
|
82
|
-
* { type: "common", value: "Hello" },
|
|
83
|
-
* { type: "removed", value: "!" },
|
|
84
|
-
* { type: "common", value: "\n" }
|
|
85
|
-
* ]
|
|
86
|
-
* },
|
|
87
|
-
* {
|
|
88
|
-
* type: "added",
|
|
89
|
-
* value: "Hello\n",
|
|
90
|
-
* details: [
|
|
91
|
-
* { type: "common", value: "Hello" },
|
|
92
|
-
* { type: "common", value: "\n" }
|
|
93
|
-
* ]
|
|
94
|
-
* }
|
|
95
|
-
* ]);
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
export declare function diffStr(A: string, B: string): DiffResult<string>[];
|
|
99
|
-
//# sourceMappingURL=diff_str.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"diff_str.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.12/diff_str.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAqB,UAAU,EAAE,MAAM,YAAY,CAAC;AAGhE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAY/C;AAKD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,MAAM,EAAE,CAiBnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,EACxB,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,GAC3B,UAAU,CAAC,MAAM,CAAC,EAAE,CAetB;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAkDlE"}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
import { diff } from "./diff.js";
|
|
4
|
-
/**
|
|
5
|
-
* Unescape invisible characters.
|
|
6
|
-
*
|
|
7
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#escape_sequences}
|
|
8
|
-
*
|
|
9
|
-
* @param string String to unescape.
|
|
10
|
-
*
|
|
11
|
-
* @returns Unescaped string.
|
|
12
|
-
*
|
|
13
|
-
* @example Usage
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { unescape } from "@std/internal/diff-str";
|
|
16
|
-
* import { assertEquals } from "@std/assert";
|
|
17
|
-
*
|
|
18
|
-
* assertEquals(unescape("Hello\nWorld"), "Hello\\n\nWorld");
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export function unescape(string) {
|
|
22
|
-
return string
|
|
23
|
-
.replaceAll("\\", "\\\\")
|
|
24
|
-
.replaceAll("\b", "\\b")
|
|
25
|
-
.replaceAll("\f", "\\f")
|
|
26
|
-
.replaceAll("\t", "\\t")
|
|
27
|
-
.replaceAll("\v", "\\v")
|
|
28
|
-
// This does not remove line breaks
|
|
29
|
-
.replaceAll(/\r\n|\r|\n/g, (str) => str === "\r" ? "\\r" : str === "\n" ? "\\n\n" : "\\r\\n\r\n");
|
|
30
|
-
}
|
|
31
|
-
const WHITESPACE_SYMBOLS = /((?:\\[bftv]|[^\S\r\n])+|\\[rn\\]|[()[\]{}'"\r\n]|\b)/;
|
|
32
|
-
/**
|
|
33
|
-
* Tokenizes a string into an array of tokens.
|
|
34
|
-
*
|
|
35
|
-
* @param string The string to tokenize.
|
|
36
|
-
* @param wordDiff If true, performs word-based tokenization. Default is false.
|
|
37
|
-
*
|
|
38
|
-
* @returns An array of tokens.
|
|
39
|
-
*
|
|
40
|
-
* @example Usage
|
|
41
|
-
* ```ts
|
|
42
|
-
* import { tokenize } from "@std/internal/diff-str";
|
|
43
|
-
* import { assertEquals } from "@std/assert";
|
|
44
|
-
*
|
|
45
|
-
* assertEquals(tokenize("Hello\nWorld"), ["Hello\n", "World"]);
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export function tokenize(string, wordDiff = false) {
|
|
49
|
-
if (wordDiff) {
|
|
50
|
-
return string
|
|
51
|
-
.split(WHITESPACE_SYMBOLS)
|
|
52
|
-
.filter((token) => token);
|
|
53
|
-
}
|
|
54
|
-
const tokens = [];
|
|
55
|
-
const lines = string.split(/(\n|\r\n)/).filter((line) => line);
|
|
56
|
-
for (const [i, line] of lines.entries()) {
|
|
57
|
-
if (i % 2) {
|
|
58
|
-
tokens[tokens.length - 1] += line;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
tokens.push(line);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return tokens;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Create details by filtering relevant word-diff for current line and merge
|
|
68
|
-
* "space-diff" if surrounded by word-diff for cleaner displays.
|
|
69
|
-
*
|
|
70
|
-
* @param line Current line
|
|
71
|
-
* @param tokens Word-diff tokens
|
|
72
|
-
*
|
|
73
|
-
* @returns Array of diff results.
|
|
74
|
-
*
|
|
75
|
-
* @example Usage
|
|
76
|
-
* ```ts
|
|
77
|
-
* import { createDetails } from "@std/internal/diff-str";
|
|
78
|
-
* import { assertEquals } from "@std/assert";
|
|
79
|
-
*
|
|
80
|
-
* const tokens = [
|
|
81
|
-
* { type: "added", value: "a" },
|
|
82
|
-
* { type: "removed", value: "b" },
|
|
83
|
-
* { type: "common", value: "c" },
|
|
84
|
-
* ] as const;
|
|
85
|
-
* assertEquals(
|
|
86
|
-
* createDetails({ type: "added", value: "a" }, [...tokens]),
|
|
87
|
-
* [{ type: "added", value: "a" }, { type: "common", value: "c" }]
|
|
88
|
-
* );
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export function createDetails(line, tokens) {
|
|
92
|
-
return tokens.filter(({ type }) => type === line.type || type === "common")
|
|
93
|
-
.map((result, i, t) => {
|
|
94
|
-
const token = t[i - 1];
|
|
95
|
-
if ((result.type === "common") && token &&
|
|
96
|
-
(token.type === t[i + 1]?.type) && /\s+/.test(result.value)) {
|
|
97
|
-
return {
|
|
98
|
-
...result,
|
|
99
|
-
type: token.type,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
const NON_WHITESPACE_REGEXP = /\S/;
|
|
106
|
-
/**
|
|
107
|
-
* Renders the differences between the actual and expected strings. Partially
|
|
108
|
-
* inspired from {@link https://github.com/kpdecker/jsdiff}.
|
|
109
|
-
*
|
|
110
|
-
* @param A Actual string
|
|
111
|
-
* @param B Expected string
|
|
112
|
-
*
|
|
113
|
-
* @returns Array of diff results.
|
|
114
|
-
*
|
|
115
|
-
* @example Usage
|
|
116
|
-
* ```ts
|
|
117
|
-
* import { diffStr } from "@std/internal/diff-str";
|
|
118
|
-
* import { assertEquals } from "@std/assert";
|
|
119
|
-
*
|
|
120
|
-
* assertEquals(diffStr("Hello!", "Hello"), [
|
|
121
|
-
* {
|
|
122
|
-
* type: "removed",
|
|
123
|
-
* value: "Hello!\n",
|
|
124
|
-
* details: [
|
|
125
|
-
* { type: "common", value: "Hello" },
|
|
126
|
-
* { type: "removed", value: "!" },
|
|
127
|
-
* { type: "common", value: "\n" }
|
|
128
|
-
* ]
|
|
129
|
-
* },
|
|
130
|
-
* {
|
|
131
|
-
* type: "added",
|
|
132
|
-
* value: "Hello\n",
|
|
133
|
-
* details: [
|
|
134
|
-
* { type: "common", value: "Hello" },
|
|
135
|
-
* { type: "common", value: "\n" }
|
|
136
|
-
* ]
|
|
137
|
-
* }
|
|
138
|
-
* ]);
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
export function diffStr(A, B) {
|
|
142
|
-
// Compute multi-line diff
|
|
143
|
-
const diffResult = diff(tokenize(`${unescape(A)}\n`), tokenize(`${unescape(B)}\n`));
|
|
144
|
-
const added = [];
|
|
145
|
-
const removed = [];
|
|
146
|
-
for (const result of diffResult) {
|
|
147
|
-
if (result.type === "added") {
|
|
148
|
-
added.push(result);
|
|
149
|
-
}
|
|
150
|
-
if (result.type === "removed") {
|
|
151
|
-
removed.push(result);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Compute word-diff
|
|
155
|
-
const hasMoreRemovedLines = added.length < removed.length;
|
|
156
|
-
const aLines = hasMoreRemovedLines ? added : removed;
|
|
157
|
-
const bLines = hasMoreRemovedLines ? removed : added;
|
|
158
|
-
for (const a of aLines) {
|
|
159
|
-
let tokens = [];
|
|
160
|
-
let b;
|
|
161
|
-
// Search another diff line with at least one common token
|
|
162
|
-
while (bLines.length) {
|
|
163
|
-
b = bLines.shift();
|
|
164
|
-
const tokenized = [
|
|
165
|
-
tokenize(a.value, true),
|
|
166
|
-
tokenize(b.value, true),
|
|
167
|
-
];
|
|
168
|
-
if (hasMoreRemovedLines)
|
|
169
|
-
tokenized.reverse();
|
|
170
|
-
tokens = diff(tokenized[0], tokenized[1]);
|
|
171
|
-
if (tokens.some(({ type, value }) => type === "common" && NON_WHITESPACE_REGEXP.test(value))) {
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
// Register word-diff details
|
|
176
|
-
a.details = createDetails(a, tokens);
|
|
177
|
-
if (b) {
|
|
178
|
-
b.details = createDetails(b, tokens);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return diffResult;
|
|
182
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export type InspectFn = (v: unknown, options: {
|
|
2
|
-
depth: number;
|
|
3
|
-
sorted: boolean;
|
|
4
|
-
trailingComma: boolean;
|
|
5
|
-
compact: boolean;
|
|
6
|
-
iterableLimit: number;
|
|
7
|
-
getters: boolean;
|
|
8
|
-
strAbbreviateSize: number;
|
|
9
|
-
}) => string;
|
|
10
|
-
/**
|
|
11
|
-
* Converts the input into a string. Objects, Sets and Maps are sorted so as to
|
|
12
|
-
* make tests less flaky.
|
|
13
|
-
*
|
|
14
|
-
* @param v Value to be formatted
|
|
15
|
-
*
|
|
16
|
-
* @returns The formatted string
|
|
17
|
-
*
|
|
18
|
-
* @example Usage
|
|
19
|
-
* ```ts
|
|
20
|
-
* import { format } from "@std/internal/format";
|
|
21
|
-
* import { assertEquals } from "@std/assert";
|
|
22
|
-
*
|
|
23
|
-
* assertEquals(format({ a: 1, b: 2 }), "{\n a: 1,\n b: 2,\n}");
|
|
24
|
-
* assertEquals(format(new Set([1, 2])), "Set(2) {\n 1,\n 2,\n}");
|
|
25
|
-
* assertEquals(format(new Map([[1, 2]])), "Map(1) {\n 1 => 2,\n}");
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare function format(v: unknown): string;
|
|
29
|
-
//# sourceMappingURL=format.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.12/format.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,SAAS,GAAG,CACtB,CAAC,EAAE,OAAO,EACV,OAAO,EAAE;IACP,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,KACE,MAAM,CAAC;AAEZ;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAmBzC"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
/** An inspect function conforming to the shape of `Deno.inspect` and `node:util`'s `inspect` */
|
|
4
|
-
import * as dntShim from "../../../../../_dnt.shims.js";
|
|
5
|
-
/**
|
|
6
|
-
* Converts the input into a string. Objects, Sets and Maps are sorted so as to
|
|
7
|
-
* make tests less flaky.
|
|
8
|
-
*
|
|
9
|
-
* @param v Value to be formatted
|
|
10
|
-
*
|
|
11
|
-
* @returns The formatted string
|
|
12
|
-
*
|
|
13
|
-
* @example Usage
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { format } from "@std/internal/format";
|
|
16
|
-
* import { assertEquals } from "@std/assert";
|
|
17
|
-
*
|
|
18
|
-
* assertEquals(format({ a: 1, b: 2 }), "{\n a: 1,\n b: 2,\n}");
|
|
19
|
-
* assertEquals(format(new Set([1, 2])), "Set(2) {\n 1,\n 2,\n}");
|
|
20
|
-
* assertEquals(format(new Map([[1, 2]])), "Map(1) {\n 1 => 2,\n}");
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function format(v) {
|
|
24
|
-
// deno-lint-ignore no-explicit-any
|
|
25
|
-
const { Deno, process } = dntShim.dntGlobalThis;
|
|
26
|
-
const inspect = Deno?.inspect ??
|
|
27
|
-
process?.getBuiltinModule?.("node:util")?.inspect;
|
|
28
|
-
return typeof inspect === "function"
|
|
29
|
-
? inspect(v, {
|
|
30
|
-
depth: Infinity,
|
|
31
|
-
sorted: true,
|
|
32
|
-
trailingComma: true,
|
|
33
|
-
compact: false,
|
|
34
|
-
iterableLimit: Infinity,
|
|
35
|
-
// getters should be true in assertEquals.
|
|
36
|
-
getters: true,
|
|
37
|
-
strAbbreviateSize: Infinity,
|
|
38
|
-
})
|
|
39
|
-
: basicInspect(v);
|
|
40
|
-
}
|
|
41
|
-
const formatters = [
|
|
42
|
-
(v) => {
|
|
43
|
-
if (typeof v === "undefined")
|
|
44
|
-
return "undefined";
|
|
45
|
-
if (typeof v === "bigint")
|
|
46
|
-
return `${v}n`;
|
|
47
|
-
if (typeof v === "string" ||
|
|
48
|
-
typeof v === "number" ||
|
|
49
|
-
typeof v === "boolean" ||
|
|
50
|
-
v === null ||
|
|
51
|
-
Array.isArray(v) ||
|
|
52
|
-
[null, Object.prototype].includes(Object.getPrototypeOf(v))) {
|
|
53
|
-
return JSON.stringify(v, null, 2);
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
(v) => String(v),
|
|
57
|
-
(v) => Object.prototype.toString.call(v),
|
|
58
|
-
];
|
|
59
|
-
// for environments lacking both `Deno.inspect` and `process.inspect`
|
|
60
|
-
function basicInspect(v) {
|
|
61
|
-
for (const fmt of formatters) {
|
|
62
|
-
try {
|
|
63
|
-
const result = fmt(v);
|
|
64
|
-
if (typeof result === "string")
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
catch { /* try the next one */ }
|
|
68
|
-
}
|
|
69
|
-
return "[[Unable to format value]]";
|
|
70
|
-
}
|