structured-outputs 0.1.0-beta.2 → 0.1.0-beta.20
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 +77 -6
- package/esm/ResponseFormat.js +33 -5
- package/esm/ResponseFormat.js.map +1 -1
- package/esm/Tool.js +17 -0
- package/esm/Tool.js.map +1 -0
- package/esm/_dnt.polyfills.js +16 -0
- package/esm/_dnt.polyfills.js.map +1 -0
- package/esm/_dnt.shims.js +58 -0
- package/esm/_dnt.shims.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/almost_equals.js +47 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/almost_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/array_includes.js +47 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/array_includes.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assert.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assert.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assertion_error.js +31 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assertion_error.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equal.js +184 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equals.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/exists.js +28 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/exists.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/fail.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/fail.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/false.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/false.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/instance_of.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/instance_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/is_error.js +54 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/is_error.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less_or_equal.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less_or_equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/match.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/mod.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/mod.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_equals.js +33 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_instance_of.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_instance_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_match.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.js +33 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/object_match.js +160 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/object_match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/rejects.js +54 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/rejects.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/strict_equals.js +58 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/strict_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/string_includes.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/string_includes.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/throws.js +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/throws.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unimplemented.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unimplemented.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unreachable.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unreachable.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/_utils.js +19 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/_utils.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.js +51 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_by.js +45 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_with.js +41 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_with.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/chunk.js +51 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/chunk.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/deep_merge.js +96 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/deep_merge.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct.js +28 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct_by.js +39 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_last_while.js +33 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_last_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_while.js +34 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_entries.js +43 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_entries.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_keys.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_keys.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_values.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_values.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/find_single.js +45 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/find_single.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.js +42 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/includes_value.js +39 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/includes_value.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/intersect.js +36 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/intersect.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert.js +29 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert_by.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/join_to_string.js +59 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/join_to_string.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_entries.js +47 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_entries.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_keys.js +42 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_keys.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.js +43 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_values.js +13 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_values.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_by.js +15 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_of.js +17 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_with.js +41 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_with.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_by.js +15 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_of.js +17 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_with.js +37 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_with.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/mod.js +75 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/mod.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/omit.js +29 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/omit.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition.js +16 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition_entries.js +54 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition_entries.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/permutations.js +58 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/permutations.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/pick.js +33 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/pick.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/reduce_groups.js +40 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/reduce_groups.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/running_reduce.js +32 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/running_reduce.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sample.js +35 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sample.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sliding_windows.js +57 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sliding_windows.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sort_by.js +30 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sort_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sum_of.js +37 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sum_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_last_while.js +34 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_last_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_while.js +39 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/union.js +34 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/union.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/unzip.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/unzip.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/without_all.js +28 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/without_all.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/zip.js +43 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/zip.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js +111 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js +277 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js +180 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.js +38 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js +208 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.js +3 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.js.map +1 -0
- package/esm/mod.js +3 -10
- package/esm/mod.js.map +1 -1
- package/esm/types/Ref.js +11 -0
- package/esm/types/Ref.js.map +1 -0
- package/esm/types/RootTy.js +19 -0
- package/esm/types/RootTy.js.map +1 -0
- package/esm/types/Ty.js +17 -0
- package/esm/types/Ty.js.map +1 -0
- package/esm/types/array.js +9 -0
- package/esm/types/array.js.map +1 -0
- package/esm/types/constant.js +8 -0
- package/esm/types/constant.js.map +1 -0
- package/esm/types/constantUnion.js +25 -0
- package/esm/types/constantUnion.js.map +1 -0
- package/esm/types/leaves.js +18 -0
- package/esm/types/leaves.js.map +1 -0
- package/esm/types/mod.js +11 -0
- package/esm/types/mod.js.map +1 -0
- package/esm/{object.js → types/object.js} +4 -4
- package/esm/types/object.js.map +1 -0
- package/esm/types/std/Option.js +9 -0
- package/esm/types/std/Option.js.map +1 -0
- package/esm/types/std/Wrapper.js +5 -0
- package/esm/types/std/Wrapper.js.map +1 -0
- package/esm/types/std/mod.js +3 -0
- package/esm/types/std/mod.js.map +1 -0
- package/esm/types/taggedUnion.js +20 -0
- package/esm/types/taggedUnion.js.map +1 -0
- package/esm/util/phantoms.js +4 -0
- package/esm/util/phantoms.js.map +1 -0
- package/esm/util/recombineTaggedTemplateArgs.js +4 -0
- package/esm/util/recombineTaggedTemplateArgs.js.map +1 -0
- package/package.json +10 -7
- package/src/ResponseFormat.ts +76 -25
- package/src/Tool.ts +38 -0
- package/src/_dnt.polyfills.ts +27 -0
- package/src/_dnt.shims.ts +60 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/almost_equals.ts +55 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/array_includes.ts +57 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/assert.ts +23 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/assertion_error.ts +31 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/equal.ts +210 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/equals.ts +52 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/exists.ts +31 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/fail.ts +21 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/false.ts +26 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/greater.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/instance_of.ts +64 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/is_error.ts +65 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/less.ts +29 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/less_or_equal.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/match.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/mod.ts +47 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_equals.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_instance_of.ts +33 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_match.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.ts +42 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/object_match.ts +202 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/rejects.ts +123 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/strict_equals.ts +67 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/string_includes.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/throws.ts +111 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/unimplemented.ts +21 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/unreachable.ts +21 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/_utils.ts +26 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.ts +62 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/associate_by.ts +50 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/associate_with.ts +46 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/chunk.ts +56 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/deep_merge.ts +578 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/distinct.ts +29 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/distinct_by.ts +42 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/drop_last_while.ts +36 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/drop_while.ts +39 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/filter_entries.ts +48 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/filter_keys.ts +51 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/filter_values.ts +51 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/find_single.ts +48 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.ts +47 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/includes_value.ts +45 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/intersect.ts +35 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/invert.ts +38 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/invert_by.ts +56 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/join_to_string.ts +109 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_entries.ts +53 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_keys.ts +47 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.ts +49 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_values.ts +96 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/max_by.ts +153 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/max_of.ts +90 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/max_with.ts +46 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/min_by.ts +151 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/min_of.ts +90 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/min_with.ts +42 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/mod.ts +76 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/omit.ts +34 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/partition.ts +85 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/partition_entries.ts +58 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/permutations.ts +66 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/pick.ts +34 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/reduce_groups.ts +45 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/running_reduce.ts +38 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sample.ts +36 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sliding_windows.ts +86 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sort_by.ts +219 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sum_of.ts +42 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/take_last_while.ts +37 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/take_while.ts +44 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/union.ts +36 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/unzip.ts +50 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/without_all.ts +28 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/zip.ts +49 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/build_message.ts +134 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/diff.ts +317 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/diff_str.ts +204 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/format.ts +39 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/styles.ts +233 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/types.ts +18 -0
- package/src/mod.ts +3 -18
- package/src/types/Ref.ts +16 -0
- package/src/types/RootTy.ts +40 -0
- package/src/types/Ty.ts +57 -0
- package/src/types/array.ts +9 -0
- package/src/types/constant.ts +8 -0
- package/src/types/constantUnion.ts +27 -0
- package/src/types/leaves.ts +21 -0
- package/src/types/mod.ts +10 -0
- package/src/types/object.ts +15 -0
- package/src/types/std/Option.ts +15 -0
- package/src/types/std/Wrapper.ts +8 -0
- package/src/types/std/mod.ts +2 -0
- package/src/types/taggedUnion.ts +28 -0
- package/src/util/phantoms.ts +3 -0
- package/src/util/recombineTaggedTemplateArgs.ts +6 -0
- package/types/ResponseFormat.d.ts +26 -0
- package/types/ResponseFormat.d.ts.map +1 -0
- package/types/Tool.d.ts +13 -0
- package/types/Tool.d.ts.map +1 -0
- package/types/_dnt.polyfills.d.ts +12 -0
- package/types/_dnt.polyfills.d.ts.map +1 -0
- package/types/_dnt.shims.d.ts +2 -0
- package/types/_dnt.shims.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/almost_equals.d.ts +29 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/almost_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/array_includes.d.ts +24 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/array_includes.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assert.d.ts +16 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assert.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assertion_error.d.ts +26 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assertion_error.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equal.d.ts +17 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equals.d.ts +22 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/exists.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/exists.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/fail.d.ts +15 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/fail.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/false.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/false.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/instance_of.d.ts +23 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/instance_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/is_error.d.ts +25 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/is_error.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less.d.ts +19 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less_or_equal.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less_or_equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/match.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/match.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/mod.d.ts +44 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/mod.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_equals.d.ts +21 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_instance_of.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_instance_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_match.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_match.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.d.ts +23 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/object_match.d.ts +28 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/object_match.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/rejects.d.ts +42 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/rejects.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/strict_equals.d.ts +24 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/strict_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/string_includes.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/string_includes.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/throws.d.ts +45 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/throws.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unimplemented.d.ts +15 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unimplemented.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unreachable.d.ts +15 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unreachable.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/_utils.d.ts +6 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/_utils.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.d.ts +41 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_by.d.ts +37 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_with.d.ts +33 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_with.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/chunk.d.ts +38 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/chunk.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/deep_merge.d.ts +322 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/deep_merge.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct.d.ts +23 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct_by.d.ts +26 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_last_while.d.ts +26 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_last_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_while.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_entries.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_entries.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_keys.d.ts +36 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_keys.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_values.d.ts +35 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_values.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/find_single.d.ts +31 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/find_single.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/includes_value.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/includes_value.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/intersect.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/intersect.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert_by.d.ts +34 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/join_to_string.d.ts +75 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/join_to_string.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_entries.d.ts +37 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_entries.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_keys.d.ts +33 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_keys.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_values.d.ts +71 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_values.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_by.d.ts +117 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_of.d.ts +61 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_with.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_with.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_by.d.ts +115 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_of.d.ts +61 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_with.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_with.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/mod.d.ts +73 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/mod.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/omit.d.ts +24 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/omit.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition.d.ts +60 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition_entries.d.ts +39 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition_entries.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/permutations.d.ts +27 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/permutations.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/pick.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/pick.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/reduce_groups.d.ts +35 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/reduce_groups.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/running_reduce.d.ts +27 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/running_reduce.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sample.d.ts +24 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sample.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sliding_windows.d.ts +66 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sliding_windows.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sort_by.d.ts +161 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sort_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sum_of.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sum_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_last_while.d.ts +27 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_last_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_while.d.ts +30 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/union.d.ts +24 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/union.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/unzip.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/unzip.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/without_all.d.ts +23 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/without_all.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/zip.d.ts +34 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/zip.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts +82 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff.d.ts +140 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts +99 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/format.d.ts +2 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/format.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/styles.d.ts +159 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/styles.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/types.d.ts +16 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/types.d.ts.map +1 -0
- package/types/mod.d.ts +5 -0
- package/types/mod.d.ts.map +1 -0
- package/types/types/Ref.d.ts +4 -0
- package/types/types/Ref.d.ts.map +1 -0
- package/types/types/RootTy.d.ts +8 -0
- package/types/types/RootTy.d.ts.map +1 -0
- package/types/types/Ty.d.ts +27 -0
- package/types/types/Ty.d.ts.map +1 -0
- package/types/types/array.d.ts +3 -0
- package/types/types/array.d.ts.map +1 -0
- package/types/types/constant.d.ts +3 -0
- package/types/types/constant.d.ts.map +1 -0
- package/types/types/constantUnion.d.ts +3 -0
- package/types/types/constantUnion.d.ts.map +1 -0
- package/types/types/leaves.d.ts +6 -0
- package/types/types/leaves.d.ts.map +1 -0
- package/types/types/mod.d.ts +11 -0
- package/types/types/mod.d.ts.map +1 -0
- package/types/types/object.d.ts +6 -0
- package/types/types/object.d.ts.map +1 -0
- package/types/types/std/Option.d.ts +7 -0
- package/types/types/std/Option.d.ts.map +1 -0
- package/types/types/std/Wrapper.d.ts +7 -0
- package/types/types/std/Wrapper.d.ts.map +1 -0
- package/types/types/std/mod.d.ts +3 -0
- package/types/types/std/mod.d.ts.map +1 -0
- package/types/types/taggedUnion.d.ts +8 -0
- package/types/types/taggedUnion.d.ts.map +1 -0
- package/types/util/phantoms.d.ts +2 -0
- package/types/util/phantoms.d.ts.map +1 -0
- package/types/util/recombineTaggedTemplateArgs.d.ts +2 -0
- package/types/util/recombineTaggedTemplateArgs.d.ts.map +1 -0
- package/esm/F.d.ts +0 -13
- package/esm/F.d.ts.map +0 -1
- package/esm/F.js +0 -10
- package/esm/F.js.map +0 -1
- package/esm/ResponseFormat.d.ts +0 -14
- package/esm/ResponseFormat.d.ts.map +0 -1
- package/esm/_base.d.ts +0 -13
- package/esm/_base.d.ts.map +0 -1
- package/esm/_base.js +0 -40
- package/esm/_base.js.map +0 -1
- package/esm/array.d.ts +0 -4
- package/esm/array.d.ts.map +0 -1
- package/esm/array.js +0 -9
- package/esm/array.js.map +0 -1
- package/esm/common.d.ts +0 -6
- package/esm/common.d.ts.map +0 -1
- package/esm/common.js +0 -2
- package/esm/common.js.map +0 -1
- package/esm/literal.d.ts +0 -4
- package/esm/literal.d.ts.map +0 -1
- package/esm/literal.js +0 -8
- package/esm/literal.js.map +0 -1
- package/esm/mod.d.ts +0 -16
- package/esm/mod.d.ts.map +0 -1
- package/esm/number.d.ts +0 -4
- package/esm/number.d.ts.map +0 -1
- package/esm/number.js +0 -8
- package/esm/number.js.map +0 -1
- package/esm/object.d.ts +0 -7
- package/esm/object.d.ts.map +0 -1
- package/esm/object.js.map +0 -1
- package/esm/schema.d.ts +0 -4
- package/esm/schema.d.ts.map +0 -1
- package/esm/schema.js +0 -9
- package/esm/schema.js.map +0 -1
- package/esm/string.d.ts +0 -4
- package/esm/string.d.ts.map +0 -1
- package/esm/string.js +0 -8
- package/esm/string.js.map +0 -1
- package/esm/union.d.ts +0 -6
- package/esm/union.d.ts.map +0 -1
- package/esm/union.js +0 -8
- package/esm/union.js.map +0 -1
- package/src/F.ts +0 -27
- package/src/_base.ts +0 -25
- package/src/array.ts +0 -11
- package/src/common.ts +0 -6
- package/src/literal.ts +0 -10
- package/src/number.ts +0 -10
- package/src/object.ts +0 -17
- package/src/schema.ts +0 -10
- package/src/string.ts +0 -10
- package/src/union.ts +0 -12
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { AssertionError } from "./assertion_error.js";
|
|
4
|
+
import { assertIsError } from "./is_error.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Executes a function which returns a promise, expecting it to reject.
|
|
8
|
+
*
|
|
9
|
+
* To assert that a synchronous function throws, use {@linkcode assertThrows}.
|
|
10
|
+
*
|
|
11
|
+
* @example Usage
|
|
12
|
+
* ```ts ignore
|
|
13
|
+
* import { assertRejects } from "@std/assert";
|
|
14
|
+
*
|
|
15
|
+
* await assertRejects(async () => Promise.reject(new Error())); // Doesn't throw
|
|
16
|
+
* await assertRejects(async () => console.log("Hello world")); // Throws
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param fn The function to execute.
|
|
20
|
+
* @param msg The optional message to display if the assertion fails.
|
|
21
|
+
* @returns The promise which resolves to the thrown error.
|
|
22
|
+
*/
|
|
23
|
+
export function assertRejects(
|
|
24
|
+
fn: () => PromiseLike<unknown>,
|
|
25
|
+
msg?: string,
|
|
26
|
+
): Promise<unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Executes a function which returns a promise, expecting it to reject.
|
|
29
|
+
* If it does not, then it throws. An error class and a string that should be
|
|
30
|
+
* included in the error message can also be asserted.
|
|
31
|
+
*
|
|
32
|
+
* To assert that a synchronous function throws, use {@linkcode assertThrows}.
|
|
33
|
+
*
|
|
34
|
+
* @example Usage
|
|
35
|
+
* ```ts ignore
|
|
36
|
+
* import { assertRejects } from "@std/assert";
|
|
37
|
+
*
|
|
38
|
+
* await assertRejects(async () => Promise.reject(new Error()), Error); // Doesn't throw
|
|
39
|
+
* await assertRejects(async () => Promise.reject(new Error()), SyntaxError); // Throws
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @typeParam E The error class to assert.
|
|
43
|
+
* @param fn The function to execute.
|
|
44
|
+
* @param ErrorClass The error class to assert.
|
|
45
|
+
* @param msgIncludes The string that should be included in the error message.
|
|
46
|
+
* @param msg The optional message to display if the assertion fails.
|
|
47
|
+
* @returns The promise which resolves to the thrown error.
|
|
48
|
+
*/
|
|
49
|
+
export function assertRejects<E extends Error = Error>(
|
|
50
|
+
fn: () => PromiseLike<unknown>,
|
|
51
|
+
// deno-lint-ignore no-explicit-any
|
|
52
|
+
ErrorClass: abstract new (...args: any[]) => E,
|
|
53
|
+
msgIncludes?: string,
|
|
54
|
+
msg?: string,
|
|
55
|
+
): Promise<E>;
|
|
56
|
+
export async function assertRejects<E extends Error = Error>(
|
|
57
|
+
fn: () => PromiseLike<unknown>,
|
|
58
|
+
errorClassOrMsg?:
|
|
59
|
+
// deno-lint-ignore no-explicit-any
|
|
60
|
+
| (abstract new (...args: any[]) => E)
|
|
61
|
+
| string,
|
|
62
|
+
msgIncludesOrMsg?: string,
|
|
63
|
+
msg?: string,
|
|
64
|
+
): Promise<E | Error | unknown> {
|
|
65
|
+
// deno-lint-ignore no-explicit-any
|
|
66
|
+
let ErrorClass: (abstract new (...args: any[]) => E) | undefined;
|
|
67
|
+
let msgIncludes: string | undefined;
|
|
68
|
+
let err;
|
|
69
|
+
|
|
70
|
+
if (typeof errorClassOrMsg !== "string") {
|
|
71
|
+
if (
|
|
72
|
+
errorClassOrMsg === undefined ||
|
|
73
|
+
errorClassOrMsg.prototype instanceof Error ||
|
|
74
|
+
errorClassOrMsg.prototype === Error.prototype
|
|
75
|
+
) {
|
|
76
|
+
ErrorClass = errorClassOrMsg;
|
|
77
|
+
msgIncludes = msgIncludesOrMsg;
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
msg = errorClassOrMsg;
|
|
81
|
+
}
|
|
82
|
+
let doesThrow = false;
|
|
83
|
+
let isPromiseReturned = false;
|
|
84
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
|
85
|
+
try {
|
|
86
|
+
const possiblePromise = fn();
|
|
87
|
+
if (
|
|
88
|
+
possiblePromise &&
|
|
89
|
+
typeof possiblePromise === "object" &&
|
|
90
|
+
typeof possiblePromise.then === "function"
|
|
91
|
+
) {
|
|
92
|
+
isPromiseReturned = true;
|
|
93
|
+
await possiblePromise;
|
|
94
|
+
} else {
|
|
95
|
+
throw new Error();
|
|
96
|
+
}
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (!isPromiseReturned) {
|
|
99
|
+
throw new AssertionError(
|
|
100
|
+
`Function throws when expected to reject${msgSuffix}`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (ErrorClass) {
|
|
104
|
+
if (!(error instanceof Error)) {
|
|
105
|
+
throw new AssertionError(`A non-Error object was rejected${msgSuffix}`);
|
|
106
|
+
}
|
|
107
|
+
assertIsError(
|
|
108
|
+
error,
|
|
109
|
+
ErrorClass,
|
|
110
|
+
msgIncludes,
|
|
111
|
+
msg,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
err = error;
|
|
115
|
+
doesThrow = true;
|
|
116
|
+
}
|
|
117
|
+
if (!doesThrow) {
|
|
118
|
+
throw new AssertionError(
|
|
119
|
+
`Expected function to reject${msgSuffix}`,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return err;
|
|
123
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { buildMessage } from "../../internal/1.0.5/build_message.js";
|
|
4
|
+
import { diff } from "../../internal/1.0.5/diff.js";
|
|
5
|
+
import { diffStr } from "../../internal/1.0.5/diff_str.js";
|
|
6
|
+
import { format } from "../../internal/1.0.5/format.js";
|
|
7
|
+
import { red } from "../../internal/1.0.5/styles.js";
|
|
8
|
+
import { AssertionError } from "./assertion_error.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Make an assertion that `actual` and `expected` are strictly equal, using
|
|
12
|
+
* {@linkcode Object.is} for equality comparison. If not, then throw.
|
|
13
|
+
*
|
|
14
|
+
* @example Usage
|
|
15
|
+
* ```ts ignore
|
|
16
|
+
* import { assertStrictEquals } from "@std/assert";
|
|
17
|
+
*
|
|
18
|
+
* const a = {};
|
|
19
|
+
* const b = a;
|
|
20
|
+
* assertStrictEquals(a, b); // Doesn't throw
|
|
21
|
+
*
|
|
22
|
+
* const c = {};
|
|
23
|
+
* const d = {};
|
|
24
|
+
* assertStrictEquals(c, d); // Throws
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @typeParam T The type of the expected value.
|
|
28
|
+
* @param actual The actual value to compare.
|
|
29
|
+
* @param expected The expected value to compare.
|
|
30
|
+
* @param msg The optional message to display if the assertion fails.
|
|
31
|
+
*/
|
|
32
|
+
export function assertStrictEquals<T>(
|
|
33
|
+
actual: unknown,
|
|
34
|
+
expected: T,
|
|
35
|
+
msg?: string,
|
|
36
|
+
): asserts actual is T {
|
|
37
|
+
if (Object.is(actual, expected)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
|
42
|
+
let message: string;
|
|
43
|
+
|
|
44
|
+
const actualString = format(actual);
|
|
45
|
+
const expectedString = format(expected);
|
|
46
|
+
|
|
47
|
+
if (actualString === expectedString) {
|
|
48
|
+
const withOffset = actualString
|
|
49
|
+
.split("\n")
|
|
50
|
+
.map((l) => ` ${l}`)
|
|
51
|
+
.join("\n");
|
|
52
|
+
message =
|
|
53
|
+
`Values have the same structure but are not reference-equal${msgSuffix}\n\n${
|
|
54
|
+
red(withOffset)
|
|
55
|
+
}\n`;
|
|
56
|
+
} else {
|
|
57
|
+
const stringDiff = (typeof actual === "string") &&
|
|
58
|
+
(typeof expected === "string");
|
|
59
|
+
const diffResult = stringDiff
|
|
60
|
+
? diffStr(actual as string, expected as string)
|
|
61
|
+
: diff(actualString.split("\n"), expectedString.split("\n"));
|
|
62
|
+
const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n");
|
|
63
|
+
message = `Values are not strictly equal${msgSuffix}\n${diffMsg}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
throw new AssertionError(message);
|
|
67
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { AssertionError } from "./assertion_error.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Make an assertion that actual includes expected. If not
|
|
7
|
+
* then throw.
|
|
8
|
+
*
|
|
9
|
+
* @example Usage
|
|
10
|
+
* ```ts ignore
|
|
11
|
+
* import { assertStringIncludes } from "@std/assert";
|
|
12
|
+
*
|
|
13
|
+
* assertStringIncludes("Hello", "ello"); // Doesn't throw
|
|
14
|
+
* assertStringIncludes("Hello", "world"); // Throws
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param actual The actual string to check for inclusion.
|
|
18
|
+
* @param expected The expected string to check for inclusion.
|
|
19
|
+
* @param msg The optional message to display if the assertion fails.
|
|
20
|
+
*/
|
|
21
|
+
export function assertStringIncludes(
|
|
22
|
+
actual: string,
|
|
23
|
+
expected: string,
|
|
24
|
+
msg?: string,
|
|
25
|
+
) {
|
|
26
|
+
if (actual.includes(expected)) return;
|
|
27
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
|
28
|
+
msg = `Expected actual: "${actual}" to contain: "${expected}"${msgSuffix}`;
|
|
29
|
+
throw new AssertionError(msg);
|
|
30
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { assertIsError } from "./is_error.js";
|
|
4
|
+
import { AssertionError } from "./assertion_error.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Executes a function, expecting it to throw. If it does not, then it
|
|
8
|
+
* throws.
|
|
9
|
+
*
|
|
10
|
+
* To assert that an asynchronous function rejects, use
|
|
11
|
+
* {@linkcode assertRejects}.
|
|
12
|
+
*
|
|
13
|
+
* @example Usage
|
|
14
|
+
* ```ts ignore
|
|
15
|
+
* import { assertThrows } from "@std/assert";
|
|
16
|
+
*
|
|
17
|
+
* assertThrows(() => { throw new TypeError("hello world!"); }); // Doesn't throw
|
|
18
|
+
* assertThrows(() => console.log("hello world!")); // Throws
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param fn The function to execute.
|
|
22
|
+
* @param msg The optional message to display if the assertion fails.
|
|
23
|
+
* @returns The error that was thrown.
|
|
24
|
+
*/
|
|
25
|
+
export function assertThrows(
|
|
26
|
+
fn: () => unknown,
|
|
27
|
+
msg?: string,
|
|
28
|
+
): unknown;
|
|
29
|
+
/**
|
|
30
|
+
* Executes a function, expecting it to throw. If it does not, then it
|
|
31
|
+
* throws. An error class and a string that should be included in the
|
|
32
|
+
* error message can also be asserted.
|
|
33
|
+
*
|
|
34
|
+
* To assert that an asynchronous function rejects, use
|
|
35
|
+
* {@linkcode assertRejects}.
|
|
36
|
+
*
|
|
37
|
+
* @example Usage
|
|
38
|
+
* ```ts ignore
|
|
39
|
+
* import { assertThrows } from "@std/assert";
|
|
40
|
+
*
|
|
41
|
+
* assertThrows(() => { throw new TypeError("hello world!"); }, TypeError); // Doesn't throw
|
|
42
|
+
* assertThrows(() => { throw new TypeError("hello world!"); }, RangeError); // Throws
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @typeParam E The error class to assert.
|
|
46
|
+
* @param fn The function to execute.
|
|
47
|
+
* @param ErrorClass The error class to assert.
|
|
48
|
+
* @param msgIncludes The string that should be included in the error message.
|
|
49
|
+
* @param msg The optional message to display if the assertion fails.
|
|
50
|
+
* @returns The error that was thrown.
|
|
51
|
+
*/
|
|
52
|
+
export function assertThrows<E extends Error = Error>(
|
|
53
|
+
fn: () => unknown,
|
|
54
|
+
// deno-lint-ignore no-explicit-any
|
|
55
|
+
ErrorClass: abstract new (...args: any[]) => E,
|
|
56
|
+
msgIncludes?: string,
|
|
57
|
+
msg?: string,
|
|
58
|
+
): E;
|
|
59
|
+
export function assertThrows<E extends Error = Error>(
|
|
60
|
+
fn: () => unknown,
|
|
61
|
+
errorClassOrMsg?:
|
|
62
|
+
// deno-lint-ignore no-explicit-any
|
|
63
|
+
| (abstract new (...args: any[]) => E)
|
|
64
|
+
| string,
|
|
65
|
+
msgIncludesOrMsg?: string,
|
|
66
|
+
msg?: string,
|
|
67
|
+
): E | Error | unknown {
|
|
68
|
+
// deno-lint-ignore no-explicit-any
|
|
69
|
+
let ErrorClass: (abstract new (...args: any[]) => E) | undefined;
|
|
70
|
+
let msgIncludes: string | undefined;
|
|
71
|
+
let err;
|
|
72
|
+
|
|
73
|
+
if (typeof errorClassOrMsg !== "string") {
|
|
74
|
+
if (
|
|
75
|
+
errorClassOrMsg === undefined ||
|
|
76
|
+
errorClassOrMsg?.prototype instanceof Error ||
|
|
77
|
+
errorClassOrMsg?.prototype === Error.prototype
|
|
78
|
+
) {
|
|
79
|
+
ErrorClass = errorClassOrMsg;
|
|
80
|
+
msgIncludes = msgIncludesOrMsg;
|
|
81
|
+
} else {
|
|
82
|
+
msg = msgIncludesOrMsg;
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
msg = errorClassOrMsg;
|
|
86
|
+
}
|
|
87
|
+
let doesThrow = false;
|
|
88
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
|
89
|
+
try {
|
|
90
|
+
fn();
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (ErrorClass) {
|
|
93
|
+
if (error instanceof Error === false) {
|
|
94
|
+
throw new AssertionError(`A non-Error object was thrown${msgSuffix}`);
|
|
95
|
+
}
|
|
96
|
+
assertIsError(
|
|
97
|
+
error,
|
|
98
|
+
ErrorClass,
|
|
99
|
+
msgIncludes,
|
|
100
|
+
msg,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
err = error;
|
|
104
|
+
doesThrow = true;
|
|
105
|
+
}
|
|
106
|
+
if (!doesThrow) {
|
|
107
|
+
msg = `Expected function to throw${msgSuffix}`;
|
|
108
|
+
throw new AssertionError(msg);
|
|
109
|
+
}
|
|
110
|
+
return err;
|
|
111
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { AssertionError } from "./assertion_error.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Use this to stub out methods that will throw when invoked.
|
|
7
|
+
*
|
|
8
|
+
* @example Usage
|
|
9
|
+
* ```ts ignore
|
|
10
|
+
* import { unimplemented } from "@std/assert";
|
|
11
|
+
*
|
|
12
|
+
* unimplemented(); // Throws
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param msg Optional message to include in the error.
|
|
16
|
+
* @returns Never returns, always throws.
|
|
17
|
+
*/
|
|
18
|
+
export function unimplemented(msg?: string): never {
|
|
19
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
|
20
|
+
throw new AssertionError(`Unimplemented${msgSuffix}`);
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { AssertionError } from "./assertion_error.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Use this to assert unreachable code.
|
|
7
|
+
*
|
|
8
|
+
* @example Usage
|
|
9
|
+
* ```ts ignore
|
|
10
|
+
* import { unreachable } from "@std/assert";
|
|
11
|
+
*
|
|
12
|
+
* unreachable(); // Throws
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param msg Optional message to include in the error.
|
|
16
|
+
* @returns Never returns, always throws.
|
|
17
|
+
*/
|
|
18
|
+
export function unreachable(msg?: string): never {
|
|
19
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
|
20
|
+
throw new AssertionError(`Unreachable${msgSuffix}`);
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Filters the given array, removing all elements that do not match the given predicate
|
|
6
|
+
* **in place. This means `array` will be modified!**.
|
|
7
|
+
*/
|
|
8
|
+
export function filterInPlace<T>(
|
|
9
|
+
array: Array<T>,
|
|
10
|
+
predicate: (el: T) => boolean,
|
|
11
|
+
): Array<T> {
|
|
12
|
+
let outputIndex = 0;
|
|
13
|
+
|
|
14
|
+
for (const cur of array) {
|
|
15
|
+
if (!predicate(cur)) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
array[outputIndex] = cur;
|
|
20
|
+
outputIndex += 1;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
array.splice(outputIndex);
|
|
24
|
+
|
|
25
|
+
return array;
|
|
26
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
import { mapEntries } from "./map_entries.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Applies the given aggregator to each group in the given grouping, returning the
|
|
8
|
+
* results together with the respective group keys
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T Type of the values in the input record.
|
|
11
|
+
* @typeParam A Type of the accumulator value, which will match the returned
|
|
12
|
+
* record's values.
|
|
13
|
+
*
|
|
14
|
+
* @param record The grouping to aggregate.
|
|
15
|
+
* @param aggregator The function to apply to each group.
|
|
16
|
+
*
|
|
17
|
+
* @returns A record with the same keys as the input record, but with the values
|
|
18
|
+
* being the result of applying the aggregator to each group.
|
|
19
|
+
*
|
|
20
|
+
* @example Basic usage
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { aggregateGroups } from "@std/collections/aggregate-groups";
|
|
23
|
+
* import { assertEquals } from "@std/assert";
|
|
24
|
+
*
|
|
25
|
+
* const foodProperties = {
|
|
26
|
+
* Curry: ["spicy", "vegan"],
|
|
27
|
+
* Omelette: ["creamy", "vegetarian"],
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* const descriptions = aggregateGroups(
|
|
31
|
+
* foodProperties,
|
|
32
|
+
* (current, key, first, acc) => {
|
|
33
|
+
* return first
|
|
34
|
+
* ? `${key} is ${current}`
|
|
35
|
+
* : `${acc} and ${current}`;
|
|
36
|
+
* },
|
|
37
|
+
* );
|
|
38
|
+
*
|
|
39
|
+
* assertEquals(descriptions, {
|
|
40
|
+
* Curry: "Curry is spicy and vegan",
|
|
41
|
+
* Omelette: "Omelette is creamy and vegetarian",
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function aggregateGroups<T, A>(
|
|
46
|
+
record: Readonly<Record<string, ReadonlyArray<T>>>,
|
|
47
|
+
aggregator: (current: T, key: string, first: boolean, accumulator?: A) => A,
|
|
48
|
+
): Record<string, A> {
|
|
49
|
+
return mapEntries(
|
|
50
|
+
record,
|
|
51
|
+
([key, values]) => [
|
|
52
|
+
key,
|
|
53
|
+
// Need the type assertions here because the reduce type does not support
|
|
54
|
+
// the type transition we need
|
|
55
|
+
values.reduce(
|
|
56
|
+
(accumulator, current, currentIndex) =>
|
|
57
|
+
aggregator(current, key, currentIndex === 0, accumulator),
|
|
58
|
+
undefined as A | undefined,
|
|
59
|
+
) as A,
|
|
60
|
+
],
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a record by associating each element of the input array with a key
|
|
6
|
+
* generated by the selector function.
|
|
7
|
+
*
|
|
8
|
+
* If the selector produces the same key for multiple elements, the latest one
|
|
9
|
+
* will be used (overriding the ones before it).
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T Type of the elements in the input array.
|
|
12
|
+
*
|
|
13
|
+
* @param array The array to transform.
|
|
14
|
+
* @param selector The function to extract the key from each element.
|
|
15
|
+
*
|
|
16
|
+
* @returns A record with the keys produced by the selector and the elements as
|
|
17
|
+
* values.
|
|
18
|
+
*
|
|
19
|
+
* @example Basic usage
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { associateBy } from "@std/collections/associate-by";
|
|
22
|
+
* import { assertEquals } from "@std/assert";
|
|
23
|
+
*
|
|
24
|
+
* const users = [
|
|
25
|
+
* { id: "a2e", userName: "Anna" },
|
|
26
|
+
* { id: "5f8", userName: "Arnold" },
|
|
27
|
+
* { id: "d2c", userName: "Kim" },
|
|
28
|
+
* ];
|
|
29
|
+
*
|
|
30
|
+
* const usersById = associateBy(users, (user) => user.id);
|
|
31
|
+
*
|
|
32
|
+
* assertEquals(usersById, {
|
|
33
|
+
* "a2e": { id: "a2e", userName: "Anna" },
|
|
34
|
+
* "5f8": { id: "5f8", userName: "Arnold" },
|
|
35
|
+
* "d2c": { id: "d2c", userName: "Kim" },
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function associateBy<T>(
|
|
40
|
+
array: Iterable<T>,
|
|
41
|
+
selector: (el: T) => string,
|
|
42
|
+
): Record<string, T> {
|
|
43
|
+
const result: Record<string, T> = {};
|
|
44
|
+
|
|
45
|
+
for (const element of array) {
|
|
46
|
+
result[selector(element)] = element;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Associates each string element of an array with a value returned by a selector
|
|
6
|
+
* function.
|
|
7
|
+
*
|
|
8
|
+
* If any of two pairs would have the same value, the latest one will be used
|
|
9
|
+
* (overriding the ones before it).
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T The type of the values returned by the selector function.
|
|
12
|
+
*
|
|
13
|
+
* @param array The array of elements to associate with values.
|
|
14
|
+
* @param selector The selector function that returns a value for each element.
|
|
15
|
+
*
|
|
16
|
+
* @returns An object where each element of the array is associated with a value
|
|
17
|
+
* returned by the selector function.
|
|
18
|
+
*
|
|
19
|
+
* @example Basic usage
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { associateWith } from "@std/collections/associate-with";
|
|
22
|
+
* import { assertEquals } from "@std/assert";
|
|
23
|
+
*
|
|
24
|
+
* const names = ["Kim", "Lara", "Jonathan"];
|
|
25
|
+
*
|
|
26
|
+
* const namesToLength = associateWith(names, (person) => person.length);
|
|
27
|
+
*
|
|
28
|
+
* assertEquals(namesToLength, {
|
|
29
|
+
* "Kim": 3,
|
|
30
|
+
* "Lara": 4,
|
|
31
|
+
* "Jonathan": 8,
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function associateWith<T>(
|
|
36
|
+
array: Iterable<string>,
|
|
37
|
+
selector: (key: string) => T,
|
|
38
|
+
): Record<string, T> {
|
|
39
|
+
const result: Record<string, T> = {};
|
|
40
|
+
|
|
41
|
+
for (const element of array) {
|
|
42
|
+
result[element] = selector(element);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Splits the given array into chunks of the given size and returns them.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T Type of the elements in the input array.
|
|
8
|
+
*
|
|
9
|
+
* @param array The array to split into chunks.
|
|
10
|
+
* @param size The size of the chunks. This must be a positive integer.
|
|
11
|
+
*
|
|
12
|
+
* @returns An array of chunks of the given size.
|
|
13
|
+
*
|
|
14
|
+
* @example Basic usage
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { chunk } from "@std/collections/chunk";
|
|
17
|
+
* import { assertEquals } from "@std/assert";
|
|
18
|
+
*
|
|
19
|
+
* const words = [
|
|
20
|
+
* "lorem",
|
|
21
|
+
* "ipsum",
|
|
22
|
+
* "dolor",
|
|
23
|
+
* "sit",
|
|
24
|
+
* "amet",
|
|
25
|
+
* "consetetur",
|
|
26
|
+
* "sadipscing",
|
|
27
|
+
* ];
|
|
28
|
+
* const chunks = chunk(words, 3);
|
|
29
|
+
*
|
|
30
|
+
* assertEquals(
|
|
31
|
+
* chunks,
|
|
32
|
+
* [
|
|
33
|
+
* ["lorem", "ipsum", "dolor"],
|
|
34
|
+
* ["sit", "amet", "consetetur"],
|
|
35
|
+
* ["sadipscing"],
|
|
36
|
+
* ],
|
|
37
|
+
* );
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function chunk<T>(array: readonly T[], size: number): T[][] {
|
|
41
|
+
if (size <= 0 || !Number.isInteger(size)) {
|
|
42
|
+
throw new RangeError(
|
|
43
|
+
`Expected size to be an integer greater than 0 but found ${size}`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const result: T[][] = [];
|
|
48
|
+
let index = 0;
|
|
49
|
+
|
|
50
|
+
while (index < array.length) {
|
|
51
|
+
result.push(array.slice(index, index + size));
|
|
52
|
+
index += size;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return result;
|
|
56
|
+
}
|