shelving 1.236.0 → 1.236.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/cache/APICache.d.ts +69 -6
- package/api/cache/APICache.js +61 -5
- package/api/cache/EndpointCache.d.ts +75 -7
- package/api/cache/EndpointCache.js +75 -7
- package/api/endpoint/Endpoint.d.ts +141 -25
- package/api/endpoint/Endpoint.js +55 -9
- package/api/endpoint/util.d.ts +28 -6
- package/api/provider/APIProvider.d.ts +58 -14
- package/api/provider/APIProvider.js +24 -2
- package/api/provider/CachedAPIProvider.d.ts +58 -5
- package/api/provider/CachedAPIProvider.js +58 -6
- package/api/provider/ClientAPIProvider.d.ts +80 -4
- package/api/provider/ClientAPIProvider.js +75 -4
- package/api/provider/DebugAPIProvider.d.ts +40 -1
- package/api/provider/DebugAPIProvider.js +40 -1
- package/api/provider/JSONAPIProvider.d.ts +18 -2
- package/api/provider/JSONAPIProvider.js +18 -2
- package/api/provider/LoggingAPIProvider.d.ts +25 -2
- package/api/provider/LoggingAPIProvider.js +25 -2
- package/api/provider/MockAPIProvider.d.ts +72 -1
- package/api/provider/MockAPIProvider.js +60 -4
- package/api/provider/MockEndpointAPIProvider.d.ts +9 -0
- package/api/provider/MockEndpointAPIProvider.js +9 -0
- package/api/provider/ThroughAPIProvider.d.ts +67 -1
- package/api/provider/ThroughAPIProvider.js +67 -1
- package/api/provider/ValidationAPIProvider.d.ts +32 -1
- package/api/provider/ValidationAPIProvider.js +32 -1
- package/api/provider/XMLAPIProvider.d.ts +18 -2
- package/api/provider/XMLAPIProvider.js +18 -2
- package/api/store/EndpointStore.d.ts +24 -1
- package/api/store/EndpointStore.js +24 -1
- package/bun/BunPostgreSQLProvider.d.ts +38 -0
- package/bun/BunPostgreSQLProvider.js +38 -2
- package/cloudflare/CloudflareD1Provider.d.ts +29 -2
- package/cloudflare/CloudflareD1Provider.js +29 -2
- package/cloudflare/CloudflareKVProvider.d.ts +115 -0
- package/cloudflare/CloudflareKVProvider.js +115 -0
- package/cloudflare/types.d.ts +41 -7
- package/db/cache/CollectionCache.d.ts +83 -7
- package/db/cache/CollectionCache.js +83 -7
- package/db/cache/DBCache.d.ts +93 -8
- package/db/cache/DBCache.js +85 -7
- package/db/collection/Collection.d.ts +103 -15
- package/db/collection/Collection.js +58 -6
- package/db/migrate/DBMigrator.d.ts +29 -1
- package/db/migrate/DBMigrator.js +20 -1
- package/db/migrate/PostgreSQLMigrator.d.ts +8 -1
- package/db/migrate/PostgreSQLMigrator.js +8 -1
- package/db/migrate/SQLMigrator.d.ts +63 -4
- package/db/migrate/SQLMigrator.js +51 -1
- package/db/migrate/SQLiteMigrator.d.ts +8 -1
- package/db/migrate/SQLiteMigrator.js +8 -1
- package/db/provider/CacheDBProvider.d.ts +135 -1
- package/db/provider/CacheDBProvider.js +135 -1
- package/db/provider/ChangesDBProvider.d.ts +84 -3
- package/db/provider/ChangesDBProvider.js +77 -2
- package/db/provider/DBProvider.d.ts +148 -1
- package/db/provider/DBProvider.js +51 -1
- package/db/provider/DebugDBProvider.d.ts +118 -1
- package/db/provider/DebugDBProvider.js +118 -1
- package/db/provider/MemoryDBProvider.d.ts +262 -7
- package/db/provider/MemoryDBProvider.js +262 -7
- package/db/provider/MockDBProvider.d.ts +113 -2
- package/db/provider/MockDBProvider.js +106 -1
- package/db/provider/PostgreSQLProvider.d.ts +34 -2
- package/db/provider/PostgreSQLProvider.js +34 -4
- package/db/provider/SQLProvider.d.ts +250 -14
- package/db/provider/SQLProvider.js +237 -13
- package/db/provider/SQLiteProvider.d.ts +41 -1
- package/db/provider/SQLiteProvider.js +41 -4
- package/db/provider/ThroughDBProvider.d.ts +156 -1
- package/db/provider/ThroughDBProvider.js +156 -1
- package/db/provider/ValidationDBProvider.d.ts +120 -1
- package/db/provider/ValidationDBProvider.js +120 -1
- package/db/store/ItemStore.d.ts +38 -2
- package/db/store/ItemStore.js +38 -2
- package/db/store/QueryStore.d.ts +64 -6
- package/db/store/QueryStore.js +64 -6
- package/error/BaseError.d.ts +27 -2
- package/error/BaseError.js +14 -0
- package/error/Errors.d.ts +12 -1
- package/error/Errors.js +12 -1
- package/error/NetworkError.d.ts +13 -1
- package/error/NetworkError.js +13 -1
- package/error/RequestError.d.ts +90 -7
- package/error/RequestError.js +90 -7
- package/error/RequiredError.d.ts +11 -1
- package/error/RequiredError.js +11 -1
- package/error/ResponseError.d.ts +19 -2
- package/error/ResponseError.js +19 -2
- package/error/UnexpectedError.d.ts +14 -1
- package/error/UnexpectedError.js +14 -1
- package/error/UnimplementedError.d.ts +13 -1
- package/error/UnimplementedError.js +13 -1
- package/error/ValueError.d.ts +14 -1
- package/error/ValueError.js +14 -1
- package/extract/DirectoryExtractor.d.ts +35 -1
- package/extract/DirectoryExtractor.js +30 -0
- package/extract/Extractor.d.ts +21 -2
- package/extract/Extractor.js +7 -1
- package/extract/FileExtractor.d.ts +18 -0
- package/extract/FileExtractor.js +18 -0
- package/extract/IndexExtractor.d.ts +36 -1
- package/extract/IndexExtractor.js +31 -0
- package/extract/MarkupExtractor.d.ts +15 -0
- package/extract/MarkupExtractor.js +15 -0
- package/extract/MergingExtractor.d.ts +36 -1
- package/extract/MergingExtractor.js +31 -0
- package/extract/ModuleExtractor.d.ts +25 -1
- package/extract/ModuleExtractor.js +20 -0
- package/extract/PackageExtractor.d.ts +36 -1
- package/extract/PackageExtractor.js +31 -0
- package/extract/ThroughExtractor.d.ts +22 -1
- package/extract/ThroughExtractor.js +22 -1
- package/extract/TypescriptExtractor.d.ts +21 -0
- package/extract/TypescriptExtractor.js +28 -3
- package/firestore/client/FirestoreClientProvider.d.ts +129 -4
- package/firestore/client/FirestoreClientProvider.js +129 -4
- package/firestore/lite/FirestoreLiteProvider.d.ts +128 -3
- package/firestore/lite/FirestoreLiteProvider.js +128 -3
- package/firestore/server/FirestoreServerProvider.d.ts +129 -2
- package/firestore/server/FirestoreServerProvider.js +129 -2
- package/markup/MarkupParser.d.ts +57 -10
- package/markup/MarkupParser.js +50 -9
- package/markup/MarkupRule.d.ts +34 -1
- package/markup/Parser.d.ts +18 -0
- package/markup/Parser.js +11 -0
- package/markup/rule/blockquote.d.ts +3 -0
- package/markup/rule/blockquote.js +3 -0
- package/markup/rule/code.d.ts +3 -0
- package/markup/rule/code.js +3 -0
- package/markup/rule/fenced.d.ts +3 -0
- package/markup/rule/fenced.js +3 -0
- package/markup/rule/heading.d.ts +3 -0
- package/markup/rule/heading.js +3 -0
- package/markup/rule/index.d.ts +16 -3
- package/markup/rule/index.js +16 -3
- package/markup/rule/inline.d.ts +4 -1
- package/markup/rule/inline.js +5 -2
- package/markup/rule/linebreak.d.ts +3 -0
- package/markup/rule/linebreak.js +3 -0
- package/markup/rule/link.d.ts +6 -0
- package/markup/rule/link.js +6 -0
- package/markup/rule/ordered.d.ts +3 -0
- package/markup/rule/ordered.js +3 -0
- package/markup/rule/paragraph.d.ts +3 -0
- package/markup/rule/paragraph.js +3 -0
- package/markup/rule/separator.d.ts +3 -0
- package/markup/rule/separator.js +3 -0
- package/markup/rule/table.d.ts +3 -0
- package/markup/rule/table.js +3 -0
- package/markup/rule/unordered.d.ts +3 -0
- package/markup/rule/unordered.js +3 -0
- package/markup/util/regexp.d.ts +80 -3
- package/markup/util/regexp.js +44 -0
- package/package.json +1 -1
- package/react/createAPIContext.d.ts +15 -0
- package/react/createAPIContext.js +10 -0
- package/react/createDBContext.d.ts +15 -0
- package/react/createDBContext.js +10 -0
- package/react/useInstance.d.ts +11 -0
- package/react/useInstance.js +11 -0
- package/react/useLazy.d.ts +11 -0
- package/react/useMap.d.ts +14 -1
- package/react/useMap.js +14 -1
- package/react/useReduce.d.ts +12 -0
- package/react/useSequence.d.ts +10 -0
- package/react/useSequence.js +10 -0
- package/react/useStore.d.ts +16 -1
- package/schema/AddressSchema.d.ts +41 -4
- package/schema/AddressSchema.js +36 -3
- package/schema/ArraySchema.d.ts +48 -6
- package/schema/ArraySchema.js +40 -5
- package/schema/BooleanSchema.d.ts +59 -3
- package/schema/BooleanSchema.js +51 -2
- package/schema/ChoiceSchema.d.ts +61 -7
- package/schema/ChoiceSchema.js +44 -2
- package/schema/ColorSchema.d.ts +41 -8
- package/schema/ColorSchema.js +36 -7
- package/schema/CountrySchema.d.ts +44 -4
- package/schema/CountrySchema.js +39 -3
- package/schema/CurrencyAmountSchema.d.ts +104 -8
- package/schema/CurrencyAmountSchema.js +91 -4
- package/schema/CurrencyCodeSchema.d.ts +56 -4
- package/schema/CurrencyCodeSchema.js +49 -3
- package/schema/DataSchema.d.ts +101 -10
- package/schema/DataSchema.js +87 -8
- package/schema/DateSchema.d.ts +73 -4
- package/schema/DateSchema.js +57 -2
- package/schema/DateTimeSchema.d.ts +40 -3
- package/schema/DateTimeSchema.js +40 -3
- package/schema/DictionarySchema.d.ts +54 -4
- package/schema/DictionarySchema.js +47 -3
- package/schema/EmailSchema.d.ts +34 -3
- package/schema/EmailSchema.js +34 -3
- package/schema/EntitySchema.d.ts +45 -4
- package/schema/EntitySchema.js +38 -3
- package/schema/FileSchema.d.ts +45 -4
- package/schema/FileSchema.js +39 -3
- package/schema/KeySchema.d.ts +32 -3
- package/schema/KeySchema.js +32 -3
- package/schema/NullableSchema.d.ts +64 -4
- package/schema/NullableSchema.js +59 -3
- package/schema/NumberSchema.d.ts +137 -12
- package/schema/NumberSchema.js +127 -11
- package/schema/OptionalSchema.d.ts +61 -4
- package/schema/OptionalSchema.js +56 -4
- package/schema/PasswordSchema.d.ts +37 -1
- package/schema/PasswordSchema.js +32 -1
- package/schema/PhoneSchema.d.ts +40 -4
- package/schema/PhoneSchema.js +35 -3
- package/schema/RequiredSchema.d.ts +39 -3
- package/schema/RequiredSchema.js +41 -3
- package/schema/Schema.d.ts +67 -7
- package/schema/Schema.js +42 -6
- package/schema/SlugSchema.d.ts +37 -5
- package/schema/SlugSchema.js +37 -5
- package/schema/StringSchema.d.ts +124 -19
- package/schema/StringSchema.js +107 -17
- package/schema/ThroughSchema.d.ts +35 -2
- package/schema/ThroughSchema.js +30 -1
- package/schema/TimeSchema.d.ts +43 -3
- package/schema/TimeSchema.js +43 -3
- package/schema/URISchema.d.ts +67 -6
- package/schema/URISchema.js +60 -6
- package/schema/URLSchema.d.ts +69 -6
- package/schema/URLSchema.js +61 -6
- package/schema/UUIDSchema.d.ts +37 -4
- package/schema/UUIDSchema.js +37 -4
- package/sequence/DeferredSequence.d.ts +49 -3
- package/sequence/DeferredSequence.js +39 -3
- package/sequence/InspectSequence.d.ts +59 -5
- package/sequence/InspectSequence.js +59 -5
- package/sequence/LazySequence.d.ts +30 -2
- package/sequence/LazySequence.js +30 -2
- package/sequence/Sequence.d.ts +11 -0
- package/sequence/Sequence.js +10 -0
- package/sequence/ThroughSequence.d.ts +15 -0
- package/sequence/ThroughSequence.js +15 -0
- package/store/ArrayStore.d.ts +74 -11
- package/store/ArrayStore.js +74 -11
- package/store/BooleanStore.d.ts +19 -2
- package/store/BooleanStore.js +19 -2
- package/store/BusyStore.d.ts +13 -1
- package/store/BusyStore.js +13 -1
- package/store/DataStore.d.ts +118 -15
- package/store/DataStore.js +118 -15
- package/store/DictionaryStore.d.ts +66 -8
- package/store/DictionaryStore.js +66 -8
- package/store/FetchStore.d.ts +43 -6
- package/store/FetchStore.js +36 -5
- package/store/PathStore.d.ts +44 -5
- package/store/PathStore.js +44 -5
- package/store/PayloadFetchStore.d.ts +16 -1
- package/store/PayloadFetchStore.js +9 -1
- package/store/Store.d.ts +85 -16
- package/store/Store.js +52 -10
- package/store/URLStore.d.ts +173 -15
- package/store/URLStore.js +173 -15
- package/test/basics.d.ts +70 -0
- package/test/basics.js +60 -0
- package/test/people.d.ts +45 -0
- package/test/people.js +35 -0
- package/test/util.d.ts +30 -3
- package/test/util.js +30 -3
- package/ui/app/App.d.ts +14 -2
- package/ui/app/App.js +9 -2
- package/ui/app/App.tsx +14 -2
- package/ui/block/Address.d.ts +45 -3
- package/ui/block/Address.js +30 -3
- package/ui/block/Address.tsx +46 -3
- package/ui/block/Block.d.ts +23 -1
- package/ui/block/Block.js +13 -1
- package/ui/block/Block.tsx +23 -1
- package/ui/block/Blockquote.d.ts +21 -0
- package/ui/block/Blockquote.js +16 -0
- package/ui/block/Blockquote.tsx +22 -0
- package/ui/block/Caption.d.ts +21 -1
- package/ui/block/Caption.js +16 -1
- package/ui/block/Caption.tsx +22 -1
- package/ui/block/Card.d.ts +6 -0
- package/ui/block/Card.js +1 -0
- package/ui/block/Card.tsx +6 -0
- package/ui/block/Definitions.d.ts +18 -0
- package/ui/block/Definitions.js +13 -0
- package/ui/block/Definitions.tsx +19 -0
- package/ui/block/Divider.d.ts +21 -0
- package/ui/block/Divider.js +16 -0
- package/ui/block/Divider.tsx +22 -0
- package/ui/block/Heading.d.ts +20 -1
- package/ui/block/Heading.js +15 -0
- package/ui/block/Heading.tsx +21 -1
- package/ui/block/Image.d.ts +23 -0
- package/ui/block/Image.js +18 -0
- package/ui/block/Image.tsx +24 -0
- package/ui/block/Label.d.ts +18 -3
- package/ui/block/Label.js +13 -3
- package/ui/block/Label.tsx +18 -3
- package/ui/block/List.d.ts +30 -0
- package/ui/block/List.js +25 -0
- package/ui/block/List.tsx +32 -0
- package/ui/block/Panel.d.ts +13 -1
- package/ui/block/Panel.js +3 -0
- package/ui/block/Panel.tsx +13 -1
- package/ui/block/Paragraph.d.ts +23 -0
- package/ui/block/Paragraph.js +18 -0
- package/ui/block/Paragraph.tsx +24 -0
- package/ui/block/Preformatted.d.ts +20 -0
- package/ui/block/Preformatted.js +15 -0
- package/ui/block/Preformatted.tsx +21 -0
- package/ui/block/Prose.d.ts +14 -1
- package/ui/block/Prose.js +9 -1
- package/ui/block/Prose.tsx +14 -1
- package/ui/block/Section.d.ts +69 -6
- package/ui/block/Section.js +59 -6
- package/ui/block/Section.tsx +70 -6
- package/ui/block/Subheading.d.ts +20 -1
- package/ui/block/Subheading.js +15 -0
- package/ui/block/Subheading.tsx +21 -1
- package/ui/block/Table.d.ts +20 -0
- package/ui/block/Table.js +15 -0
- package/ui/block/Table.tsx +21 -0
- package/ui/block/Title.d.ts +20 -1
- package/ui/block/Title.js +15 -0
- package/ui/block/Title.tsx +21 -1
- package/ui/block/Video.d.ts +50 -3
- package/ui/block/Video.js +30 -3
- package/ui/block/Video.tsx +50 -3
- package/ui/dialog/Dialog.d.ts +28 -1
- package/ui/dialog/Dialog.js +18 -1
- package/ui/dialog/Dialog.tsx +28 -1
- package/ui/dialog/Dialogs.d.ts +53 -6
- package/ui/dialog/Dialogs.js +43 -6
- package/ui/dialog/Dialogs.tsx +53 -6
- package/ui/dialog/Modal.d.ts +13 -0
- package/ui/dialog/Modal.js +8 -0
- package/ui/dialog/Modal.tsx +13 -0
- package/ui/docs/DocumentationButtons.d.ts +5 -1
- package/ui/docs/DocumentationButtons.tsx +5 -1
- package/ui/docs/DocumentationCard.d.ts +6 -1
- package/ui/docs/DocumentationCard.js +6 -1
- package/ui/docs/DocumentationCard.tsx +6 -1
- package/ui/docs/DocumentationKind.d.ts +13 -1
- package/ui/docs/DocumentationKind.js +8 -0
- package/ui/docs/DocumentationKind.tsx +13 -1
- package/ui/docs/DocumentationPage.d.ts +6 -1
- package/ui/docs/DocumentationPage.js +6 -1
- package/ui/docs/DocumentationPage.tsx +6 -1
- package/ui/docs/DocumentationSignatures.d.ts +10 -1
- package/ui/docs/DocumentationSignatures.js +5 -0
- package/ui/docs/DocumentationSignatures.tsx +10 -1
- package/ui/form/ArrayInput.d.ts +15 -0
- package/ui/form/ArrayInput.tsx +15 -0
- package/ui/form/ArrayRadioInputs.d.ts +10 -0
- package/ui/form/ArrayRadioInputs.js +5 -0
- package/ui/form/ArrayRadioInputs.tsx +10 -0
- package/ui/form/Button.d.ts +19 -3
- package/ui/form/Button.js +14 -2
- package/ui/form/Button.tsx +19 -3
- package/ui/form/ButtonInput.d.ts +14 -1
- package/ui/form/ButtonInput.js +9 -1
- package/ui/form/ButtonInput.tsx +14 -1
- package/ui/form/ButtonInputPopover.d.ts +10 -0
- package/ui/form/ButtonInputPopover.js +5 -0
- package/ui/form/ButtonInputPopover.tsx +10 -0
- package/ui/form/ButtonPopover.d.ts +11 -1
- package/ui/form/ButtonPopover.js +6 -1
- package/ui/form/ButtonPopover.tsx +11 -1
- package/ui/form/CheckboxInput.d.ts +14 -1
- package/ui/form/CheckboxInput.js +9 -1
- package/ui/form/CheckboxInput.tsx +14 -1
- package/ui/form/ChoiceRadioInputs.d.ts +10 -0
- package/ui/form/ChoiceRadioInputs.tsx +10 -0
- package/ui/form/Clickable.d.ts +45 -5
- package/ui/form/Clickable.js +30 -3
- package/ui/form/Clickable.tsx +45 -5
- package/ui/form/DataInput.d.ts +14 -0
- package/ui/form/DataInput.tsx +14 -0
- package/ui/form/DateInput.d.ts +14 -0
- package/ui/form/DateInput.js +9 -0
- package/ui/form/DateInput.tsx +14 -0
- package/ui/form/DictionaryInput.d.ts +15 -0
- package/ui/form/DictionaryInput.tsx +15 -0
- package/ui/form/Field.d.ts +5 -0
- package/ui/form/Field.tsx +5 -0
- package/ui/form/FileInput.d.ts +14 -0
- package/ui/form/FileInput.js +9 -0
- package/ui/form/FileInput.tsx +14 -0
- package/ui/form/Form.d.ts +55 -6
- package/ui/form/Form.js +35 -3
- package/ui/form/Form.tsx +55 -6
- package/ui/form/FormContext.d.ts +24 -3
- package/ui/form/FormContext.js +5 -1
- package/ui/form/FormContext.tsx +24 -3
- package/ui/form/FormFields.d.ts +15 -2
- package/ui/form/FormFields.js +15 -2
- package/ui/form/FormFields.tsx +15 -2
- package/ui/form/FormFooter.d.ts +13 -3
- package/ui/form/FormFooter.js +8 -3
- package/ui/form/FormFooter.tsx +13 -3
- package/ui/form/FormInput.d.ts +21 -2
- package/ui/form/FormInput.js +16 -2
- package/ui/form/FormInput.tsx +21 -2
- package/ui/form/FormMessage.d.ts +8 -1
- package/ui/form/FormMessage.js +8 -1
- package/ui/form/FormMessage.tsx +8 -2
- package/ui/form/FormNotice.d.ts +8 -1
- package/ui/form/FormNotice.js +8 -1
- package/ui/form/FormNotice.tsx +8 -2
- package/ui/form/FormNotify.d.ts +8 -1
- package/ui/form/FormNotify.js +8 -1
- package/ui/form/FormNotify.tsx +8 -2
- package/ui/form/FormStore.d.ts +50 -6
- package/ui/form/FormStore.js +50 -6
- package/ui/form/FormStore.tsx +50 -6
- package/ui/form/Input.d.ts +65 -1
- package/ui/form/Input.js +60 -0
- package/ui/form/Input.tsx +77 -1
- package/ui/form/NumberInput.d.ts +14 -0
- package/ui/form/NumberInput.js +9 -0
- package/ui/form/NumberInput.tsx +14 -0
- package/ui/form/OutputInput.d.ts +13 -1
- package/ui/form/OutputInput.js +8 -1
- package/ui/form/OutputInput.tsx +13 -1
- package/ui/form/Popover.d.ts +18 -2
- package/ui/form/Popover.js +8 -2
- package/ui/form/Popover.tsx +18 -2
- package/ui/form/Progress.d.ts +26 -2
- package/ui/form/Progress.js +16 -2
- package/ui/form/Progress.tsx +26 -2
- package/ui/form/QueryInput.d.ts +14 -5
- package/ui/form/QueryInput.js +9 -5
- package/ui/form/QueryInput.tsx +14 -5
- package/ui/form/RadioInput.d.ts +14 -1
- package/ui/form/RadioInput.js +9 -1
- package/ui/form/RadioInput.tsx +14 -1
- package/ui/form/SchemaInput.d.ts +138 -7
- package/ui/form/SchemaInput.js +79 -4
- package/ui/form/SchemaInput.tsx +138 -7
- package/ui/form/SelectInput.d.ts +14 -0
- package/ui/form/SelectInput.tsx +14 -0
- package/ui/form/SubmitButton.d.ts +14 -1
- package/ui/form/SubmitButton.js +9 -1
- package/ui/form/SubmitButton.tsx +14 -1
- package/ui/form/TextInput.d.ts +15 -0
- package/ui/form/TextInput.js +10 -0
- package/ui/form/TextInput.tsx +15 -0
- package/ui/inline/Code.d.ts +29 -0
- package/ui/inline/Code.js +24 -0
- package/ui/inline/Code.tsx +31 -0
- package/ui/inline/Deleted.d.ts +23 -0
- package/ui/inline/Deleted.js +18 -0
- package/ui/inline/Deleted.tsx +24 -0
- package/ui/inline/Emphasis.d.ts +23 -0
- package/ui/inline/Emphasis.js +18 -0
- package/ui/inline/Emphasis.tsx +24 -0
- package/ui/inline/Inserted.d.ts +23 -0
- package/ui/inline/Inserted.js +18 -0
- package/ui/inline/Inserted.tsx +24 -0
- package/ui/inline/Link.d.ts +23 -0
- package/ui/inline/Link.js +18 -0
- package/ui/inline/Link.tsx +24 -0
- package/ui/inline/Mark.d.ts +23 -0
- package/ui/inline/Mark.js +18 -0
- package/ui/inline/Mark.tsx +24 -0
- package/ui/inline/Small.d.ts +23 -0
- package/ui/inline/Small.js +18 -0
- package/ui/inline/Small.tsx +24 -0
- package/ui/inline/Strong.d.ts +23 -0
- package/ui/inline/Strong.js +18 -0
- package/ui/inline/Strong.tsx +24 -0
- package/ui/inline/Subscript.d.ts +23 -0
- package/ui/inline/Subscript.js +18 -0
- package/ui/inline/Subscript.tsx +24 -0
- package/ui/inline/Superscript.d.ts +23 -0
- package/ui/inline/Superscript.js +18 -0
- package/ui/inline/Superscript.tsx +24 -0
- package/ui/inline/When.d.ts +42 -3
- package/ui/inline/When.js +27 -3
- package/ui/inline/When.tsx +42 -3
- package/ui/layout/CenteredLayout.d.ts +12 -1
- package/ui/layout/CenteredLayout.js +7 -1
- package/ui/layout/CenteredLayout.tsx +12 -1
- package/ui/layout/Layout.d.ts +12 -3
- package/ui/layout/Layout.js +12 -3
- package/ui/layout/Layout.ts +12 -3
- package/ui/layout/SidebarLayout.d.ts +12 -0
- package/ui/layout/SidebarLayout.js +7 -0
- package/ui/layout/SidebarLayout.tsx +12 -0
- package/ui/menu/Menu.d.ts +22 -0
- package/ui/menu/Menu.js +12 -0
- package/ui/menu/Menu.tsx +22 -0
- package/ui/misc/Catcher.d.ts +77 -5
- package/ui/misc/Catcher.js +47 -5
- package/ui/misc/Catcher.tsx +77 -5
- package/ui/misc/Loading.d.ts +20 -0
- package/ui/misc/Loading.js +15 -0
- package/ui/misc/Loading.tsx +20 -0
- package/ui/misc/Mapper.d.ts +13 -1
- package/ui/misc/Mapper.js +4 -0
- package/ui/misc/Mapper.tsx +13 -1
- package/ui/misc/Markup.d.ts +9 -1
- package/ui/misc/Markup.js +4 -0
- package/ui/misc/Markup.tsx +9 -1
- package/ui/misc/MetaContext.d.ts +24 -7
- package/ui/misc/MetaContext.js +19 -6
- package/ui/misc/MetaContext.tsx +24 -7
- package/ui/misc/StatusIcon.d.ts +16 -1
- package/ui/misc/StatusIcon.js +11 -1
- package/ui/misc/StatusIcon.tsx +16 -1
- package/ui/misc/Tag.d.ts +21 -0
- package/ui/misc/Tag.js +11 -0
- package/ui/misc/Tag.tsx +21 -0
- package/ui/notice/Message.d.ts +27 -1
- package/ui/notice/Message.js +22 -1
- package/ui/notice/Message.tsx +27 -1
- package/ui/notice/Notice.d.ts +24 -0
- package/ui/notice/Notice.js +19 -0
- package/ui/notice/Notice.tsx +24 -0
- package/ui/notice/NoticeStore.d.ts +30 -2
- package/ui/notice/NoticeStore.js +30 -2
- package/ui/notice/NoticeStore.ts +30 -2
- package/ui/notice/Notices.d.ts +11 -1
- package/ui/notice/Notices.js +6 -1
- package/ui/notice/Notices.tsx +11 -1
- package/ui/notice/NoticesStore.d.ts +23 -3
- package/ui/notice/NoticesStore.js +23 -3
- package/ui/notice/NoticesStore.ts +23 -3
- package/ui/page/HTML.d.ts +13 -2
- package/ui/page/HTML.js +8 -2
- package/ui/page/HTML.tsx +13 -2
- package/ui/page/Head.d.ts +5 -1
- package/ui/page/Head.js +5 -1
- package/ui/page/Head.tsx +5 -1
- package/ui/page/Page.d.ts +12 -1
- package/ui/page/Page.js +7 -1
- package/ui/page/Page.tsx +12 -1
- package/ui/router/Navigation.d.ts +11 -0
- package/ui/router/Navigation.js +6 -0
- package/ui/router/Navigation.tsx +11 -0
- package/ui/router/NavigationContext.d.ts +14 -2
- package/ui/router/NavigationContext.js +14 -2
- package/ui/router/NavigationContext.tsx +14 -2
- package/ui/router/NavigationStore.d.ts +29 -1
- package/ui/router/NavigationStore.js +29 -1
- package/ui/router/NavigationStore.tsx +29 -1
- package/ui/router/Router.d.ts +12 -1
- package/ui/router/Router.js +7 -1
- package/ui/router/Router.tsx +12 -1
- package/ui/router/Routes.d.ts +14 -4
- package/ui/router/Routes.tsx +14 -4
- package/ui/style/Color.d.ts +15 -2
- package/ui/style/Color.js +5 -0
- package/ui/style/Color.tsx +15 -2
- package/ui/style/Flex.d.ts +41 -4
- package/ui/style/Flex.js +26 -3
- package/ui/style/Flex.tsx +41 -4
- package/ui/style/Gap.d.ts +18 -3
- package/ui/style/Gap.js +8 -1
- package/ui/style/Gap.tsx +18 -3
- package/ui/style/Padding.d.ts +18 -3
- package/ui/style/Padding.js +8 -1
- package/ui/style/Padding.tsx +18 -3
- package/ui/style/Scroll.d.ts +36 -1
- package/ui/style/Scroll.js +26 -1
- package/ui/style/Scroll.tsx +37 -1
- package/ui/style/Space.d.ts +18 -3
- package/ui/style/Space.js +8 -1
- package/ui/style/Space.tsx +18 -3
- package/ui/style/Status.d.ts +23 -7
- package/ui/style/Status.js +13 -5
- package/ui/style/Status.tsx +23 -7
- package/ui/style/Tint.d.ts +7 -1
- package/ui/style/Tint.js +7 -1
- package/ui/style/Tint.tsx +7 -1
- package/ui/style/Typography.d.ts +38 -6
- package/ui/style/Typography.js +8 -0
- package/ui/style/Typography.tsx +38 -6
- package/ui/style/Width.d.ts +18 -1
- package/ui/style/Width.js +8 -0
- package/ui/style/Width.tsx +18 -1
- package/ui/transition/CollapseTransition.d.ts +13 -0
- package/ui/transition/CollapseTransition.js +8 -0
- package/ui/transition/CollapseTransition.tsx +13 -0
- package/ui/transition/FadeTransition.d.ts +13 -0
- package/ui/transition/FadeTransition.js +8 -0
- package/ui/transition/FadeTransition.tsx +13 -0
- package/ui/transition/HorizontalTransition.d.ts +13 -0
- package/ui/transition/HorizontalTransition.js +8 -0
- package/ui/transition/HorizontalTransition.tsx +13 -0
- package/ui/transition/Transition.d.ts +12 -4
- package/ui/transition/Transition.js +7 -3
- package/ui/transition/Transition.tsx +12 -4
- package/ui/transition/VerticalTransition.d.ts +13 -0
- package/ui/transition/VerticalTransition.js +8 -0
- package/ui/transition/VerticalTransition.tsx +13 -0
- package/ui/transition/util.d.ts +16 -6
- package/ui/transition/util.js +7 -1
- package/ui/transition/util.tsx +16 -6
- package/ui/tree/TreeApp.d.ts +11 -0
- package/ui/tree/TreeApp.js +6 -0
- package/ui/tree/TreeApp.tsx +11 -0
- package/ui/tree/TreeBreadcrumbs.d.ts +11 -0
- package/ui/tree/TreeBreadcrumbs.js +6 -0
- package/ui/tree/TreeBreadcrumbs.tsx +11 -0
- package/ui/tree/TreeButton.d.ts +9 -1
- package/ui/tree/TreeButton.js +4 -0
- package/ui/tree/TreeButton.tsx +9 -1
- package/ui/tree/TreeCard.d.ts +8 -1
- package/ui/tree/TreeCard.js +8 -1
- package/ui/tree/TreeCard.tsx +8 -1
- package/ui/tree/TreeCards.d.ts +16 -1
- package/ui/tree/TreeCards.js +11 -1
- package/ui/tree/TreeCards.tsx +16 -1
- package/ui/tree/TreeContext.d.ts +18 -1
- package/ui/tree/TreeContext.js +18 -1
- package/ui/tree/TreeContext.tsx +18 -1
- package/ui/tree/TreeMenu.d.ts +28 -1
- package/ui/tree/TreeMenu.js +23 -1
- package/ui/tree/TreeMenu.tsx +28 -1
- package/ui/tree/TreePage.d.ts +6 -0
- package/ui/tree/TreePage.js +6 -0
- package/ui/tree/TreePage.tsx +6 -0
- package/ui/tree/TreeRouter.d.ts +17 -2
- package/ui/tree/TreeRouter.js +12 -2
- package/ui/tree/TreeRouter.tsx +17 -2
- package/ui/tree/TreeSidebar.d.ts +11 -0
- package/ui/tree/TreeSidebar.js +6 -0
- package/ui/tree/TreeSidebar.tsx +11 -0
- package/ui/util/context.d.ts +13 -1
- package/ui/util/context.ts +13 -1
- package/ui/util/css.d.ts +17 -4
- package/ui/util/css.js +5 -1
- package/ui/util/css.ts +17 -4
- package/ui/util/event.d.ts +9 -1
- package/ui/util/event.js +9 -1
- package/ui/util/event.ts +9 -1
- package/ui/util/focus.d.ts +24 -5
- package/ui/util/focus.js +24 -5
- package/ui/util/focus.ts +24 -5
- package/ui/util/meta.d.ts +113 -21
- package/ui/util/meta.js +73 -13
- package/ui/util/meta.ts +113 -21
- package/ui/util/notice.d.ts +98 -10
- package/ui/util/notice.js +93 -9
- package/ui/util/notice.ts +98 -10
- package/ui/util/props.d.ts +10 -2
- package/ui/util/props.ts +10 -2
- package/ui/util/refresh.d.ts +10 -1
- package/ui/util/refresh.js +10 -1
- package/ui/util/refresh.ts +10 -1
- package/ui/util/scroll.d.ts +20 -4
- package/ui/util/scroll.js +20 -4
- package/ui/util/scroll.ts +20 -4
- package/ui/util/state.d.ts +19 -5
- package/ui/util/state.js +19 -5
- package/ui/util/state.ts +19 -5
- package/util/ansi.d.ts +118 -0
- package/util/ansi.js +116 -0
- package/util/array.d.ts +349 -33
- package/util/array.js +284 -27
- package/util/async.d.ts +87 -9
- package/util/async.js +80 -8
- package/util/base64.d.ts +56 -6
- package/util/base64.js +56 -6
- package/util/boolean.d.ts +75 -10
- package/util/boolean.js +75 -10
- package/util/buffer.d.ts +26 -3
- package/util/buffer.js +21 -3
- package/util/bytes.d.ts +42 -4
- package/util/bytes.js +32 -2
- package/util/class.d.ts +59 -8
- package/util/class.js +44 -5
- package/util/color.d.ts +131 -13
- package/util/color.js +126 -12
- package/util/constants.d.ts +132 -19
- package/util/constants.js +132 -19
- package/util/crypto.d.ts +17 -1
- package/util/crypto.js +17 -1
- package/util/currency.d.ts +38 -4
- package/util/currency.js +33 -3
- package/util/data.d.ts +139 -24
- package/util/data.js +39 -5
- package/util/date.d.ts +152 -18
- package/util/date.js +147 -17
- package/util/debug.d.ts +112 -11
- package/util/debug.js +114 -11
- package/util/dictionary.d.ts +205 -24
- package/util/dictionary.js +162 -17
- package/util/diff.d.ts +22 -3
- package/util/diff.js +11 -1
- package/util/dispose.d.ts +74 -2
- package/util/dispose.js +74 -2
- package/util/duration.d.ts +278 -16
- package/util/duration.js +267 -15
- package/util/element.d.ts +59 -6
- package/util/element.js +32 -3
- package/util/entity.d.ts +39 -6
- package/util/entity.js +5 -1
- package/util/entry.d.ts +56 -9
- package/util/entry.js +32 -4
- package/util/env.d.ts +26 -4
- package/util/env.js +26 -4
- package/util/equal.d.ts +181 -17
- package/util/equal.js +181 -17
- package/util/error.d.ts +57 -5
- package/util/error.js +52 -4
- package/util/file.d.ts +30 -7
- package/util/file.js +25 -6
- package/util/filter.d.ts +36 -4
- package/util/filter.js +31 -3
- package/util/focus.d.ts +9 -1
- package/util/focus.js +9 -1
- package/util/format.d.ts +186 -22
- package/util/format.js +135 -14
- package/util/function.d.ts +66 -11
- package/util/function.js +31 -4
- package/util/geo.d.ts +60 -8
- package/util/geo.js +45 -5
- package/util/hash.d.ts +21 -2
- package/util/hash.js +21 -2
- package/util/http.d.ts +134 -19
- package/util/http.js +94 -11
- package/util/hydrate.d.ts +19 -2
- package/util/hydrate.js +12 -1
- package/util/item.d.ts +70 -11
- package/util/item.js +35 -4
- package/util/iterate.d.ts +109 -13
- package/util/iterate.js +86 -10
- package/util/jwt.d.ts +47 -13
- package/util/jwt.js +36 -12
- package/util/lazy.d.ts +9 -6
- package/util/link.d.ts +10 -3
- package/util/link.js +5 -2
- package/util/log.d.ts +26 -3
- package/util/log.js +26 -3
- package/util/map.d.ts +144 -19
- package/util/map.js +101 -11
- package/util/merge.d.ts +23 -1
- package/util/merge.js +6 -0
- package/util/null.d.ts +102 -13
- package/util/null.js +92 -11
- package/util/number.d.ts +125 -8
- package/util/number.js +120 -7
- package/util/object.d.ts +263 -31
- package/util/object.js +154 -17
- package/util/path.d.ts +91 -15
- package/util/path.js +60 -9
- package/util/query.d.ts +78 -9
- package/util/query.js +58 -6
- package/util/random.d.ts +67 -4
- package/util/random.js +67 -4
- package/util/regexp.d.ts +201 -24
- package/util/regexp.js +106 -11
- package/util/sequence.d.ts +66 -8
- package/util/sequence.js +52 -7
- package/util/serialise.d.ts +7 -1
- package/util/serialise.js +7 -1
- package/util/set.d.ts +103 -13
- package/util/set.js +83 -9
- package/util/sort.d.ts +32 -7
- package/util/sort.js +26 -6
- package/util/source.d.ts +28 -3
- package/util/source.js +22 -2
- package/util/start.d.ts +62 -5
- package/util/start.js +47 -2
- package/util/string.d.ts +209 -25
- package/util/string.js +188 -21
- package/util/template.d.ts +58 -9
- package/util/template.js +45 -6
- package/util/timeout.d.ts +35 -11
- package/util/timeout.js +35 -11
- package/util/transform.d.ts +87 -8
- package/util/transform.js +75 -7
- package/util/tree.d.ts +39 -6
- package/util/tree.js +3 -0
- package/util/types.d.ts +8 -2
- package/util/undefined.d.ts +47 -6
- package/util/undefined.js +47 -6
- package/util/units.d.ts +107 -12
- package/util/units.js +97 -12
- package/util/update.d.ts +36 -4
- package/util/update.js +24 -2
- package/util/uri.d.ts +138 -6
- package/util/uri.js +44 -3
- package/util/url.d.ts +152 -7
- package/util/url.js +136 -5
- package/util/uuid.d.ts +28 -3
- package/util/uuid.js +28 -3
- package/util/validate.d.ts +85 -20
- package/util/validate.js +61 -12
- package/util/xml.d.ts +9 -10
- package/util/xml.js +9 -10
package/util/null.js
CHANGED
|
@@ -1,50 +1,131 @@
|
|
|
1
1
|
import { RequiredError } from "../error/RequiredError.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Function that always returns `null`.
|
|
4
|
+
* - Useful as a default callback or placeholder.
|
|
5
|
+
*
|
|
6
|
+
* @returns `null`, always.
|
|
7
|
+
* @example getNull() // null
|
|
8
|
+
* @see https://dhoulb.github.io/shelving/util/null/getNull
|
|
9
|
+
*/
|
|
3
10
|
export function getNull() {
|
|
4
11
|
return null;
|
|
5
12
|
}
|
|
6
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Is a value `null`?
|
|
15
|
+
*
|
|
16
|
+
* @param value The value to test.
|
|
17
|
+
* @returns `true` if `value` is `null`, otherwise `false`.
|
|
18
|
+
* @see https://dhoulb.github.io/shelving/util/null/isNull
|
|
19
|
+
*/
|
|
7
20
|
export function isNull(value) {
|
|
8
21
|
return value === null;
|
|
9
22
|
}
|
|
10
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Assert that a value is `null`.
|
|
25
|
+
*
|
|
26
|
+
* @param value The value to assert.
|
|
27
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
28
|
+
* @returns Nothing; narrows `value` to `T`.
|
|
29
|
+
* @throws RequiredError if `value` is not `null`.
|
|
30
|
+
* @see https://dhoulb.github.io/shelving/util/null/assertNull
|
|
31
|
+
*/
|
|
11
32
|
export function assertNull(value, caller = assertNull) {
|
|
12
33
|
if (value !== null)
|
|
13
34
|
throw new RequiredError("Must be null", { received: value, caller });
|
|
14
35
|
}
|
|
15
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Is a value not `null`?
|
|
38
|
+
*
|
|
39
|
+
* @param value The value to test.
|
|
40
|
+
* @returns `true` if `value` is not `null`, otherwise `false`.
|
|
41
|
+
* @see https://dhoulb.github.io/shelving/util/null/notNull
|
|
42
|
+
*/
|
|
16
43
|
export function notNull(value) {
|
|
17
44
|
return value !== null;
|
|
18
45
|
}
|
|
19
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Assert that a value is not `null`.
|
|
48
|
+
*
|
|
49
|
+
* @param value The value to assert.
|
|
50
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
51
|
+
* @returns Nothing; narrows `value` to `T`.
|
|
52
|
+
* @throws RequiredError if `value` is `null`.
|
|
53
|
+
* @see https://dhoulb.github.io/shelving/util/null/assertNotNull
|
|
54
|
+
*/
|
|
20
55
|
export function assertNotNull(value, caller = assertNotNull) {
|
|
21
56
|
if (value === null)
|
|
22
57
|
throw new RequiredError("Must not be null", { received: value, caller });
|
|
23
58
|
}
|
|
24
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Get the not-null version of a value, or throw `RequiredError` if it is `null`.
|
|
61
|
+
*
|
|
62
|
+
* @param value The value to require.
|
|
63
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
64
|
+
* @returns The value, narrowed to `T`.
|
|
65
|
+
* @throws RequiredError if `value` is `null`.
|
|
66
|
+
* @example requireNotNull("a") // "a"
|
|
67
|
+
* @see https://dhoulb.github.io/shelving/util/null/requireNotNull
|
|
68
|
+
*/
|
|
25
69
|
export function requireNotNull(value, caller = requireNotNull) {
|
|
26
70
|
assertNotNull(value, caller);
|
|
27
71
|
return value;
|
|
28
72
|
}
|
|
29
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Is a value nullish (`null` or `undefined`)?
|
|
75
|
+
*
|
|
76
|
+
* @param value The value to test.
|
|
77
|
+
* @returns `true` if `value` is `null` or `undefined`, otherwise `false`.
|
|
78
|
+
* @see https://dhoulb.github.io/shelving/util/null/isNullish
|
|
79
|
+
*/
|
|
30
80
|
export function isNullish(value) {
|
|
31
81
|
return value === null || value === undefined;
|
|
32
82
|
}
|
|
33
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Assert that a value is nullish (`null` or `undefined`).
|
|
85
|
+
*
|
|
86
|
+
* @param value The value to assert.
|
|
87
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
88
|
+
* @returns Nothing; narrows `value` to `T`.
|
|
89
|
+
* @throws RequiredError if `value` is not `null` or `undefined`.
|
|
90
|
+
* @see https://dhoulb.github.io/shelving/util/null/assertNullish
|
|
91
|
+
*/
|
|
34
92
|
export function assertNullish(value, caller = assertNullish) {
|
|
35
93
|
if (value !== null && value !== undefined)
|
|
36
94
|
throw new RequiredError("Must be null or undefined", { received: value, caller });
|
|
37
95
|
}
|
|
38
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Is a value not nullish (not `null` and not `undefined`)?
|
|
98
|
+
*
|
|
99
|
+
* @param value The value to test.
|
|
100
|
+
* @returns `true` if `value` is not `null` and not `undefined`, otherwise `false`.
|
|
101
|
+
* @see https://dhoulb.github.io/shelving/util/null/notNullish
|
|
102
|
+
*/
|
|
39
103
|
export function notNullish(value) {
|
|
40
104
|
return value !== null && value !== undefined;
|
|
41
105
|
}
|
|
42
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Assert that a value is not nullish (not `null` and not `undefined`).
|
|
108
|
+
*
|
|
109
|
+
* @param value The value to assert.
|
|
110
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
111
|
+
* @returns Nothing; narrows `value` to `T`.
|
|
112
|
+
* @throws RequiredError if `value` is `null` or `undefined`.
|
|
113
|
+
* @see https://dhoulb.github.io/shelving/util/null/assertNotNullish
|
|
114
|
+
*/
|
|
43
115
|
export function assertNotNullish(value, caller = assertNotNullish) {
|
|
44
116
|
if (value === null || value === undefined)
|
|
45
117
|
throw new RequiredError("Must not be null or undefined", { received: value, caller });
|
|
46
118
|
}
|
|
47
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* Get the not-nullish version of a value, or throw `RequiredError` if it is `null` or `undefined`.
|
|
121
|
+
*
|
|
122
|
+
* @param value The value to require.
|
|
123
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
124
|
+
* @returns The value, narrowed to `T`.
|
|
125
|
+
* @throws RequiredError if `value` is `null` or `undefined`.
|
|
126
|
+
* @example requireNotNullish("a") // "a"
|
|
127
|
+
* @see https://dhoulb.github.io/shelving/util/null/requireNotNullish
|
|
128
|
+
*/
|
|
48
129
|
export function requireNotNullish(value, caller = requireNotNullish) {
|
|
49
130
|
assertNotNullish(value, caller);
|
|
50
131
|
return value;
|
package/util/number.d.ts
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
import type { AnyCaller } from "./function.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Values that can be converted to a number.
|
|
4
|
+
*
|
|
5
|
+
* @see https://dhoulb.github.io/shelving/util/number/PossibleNumber
|
|
6
|
+
*/
|
|
3
7
|
export type PossibleNumber = number | string | Date;
|
|
4
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Is a value a finite number (optionally within a specified min/max range)?
|
|
10
|
+
*
|
|
11
|
+
* @param value The value to test.
|
|
12
|
+
* @param min Minimum allowed value, inclusive (defaults to `-Infinity`).
|
|
13
|
+
* @param max Maximum allowed value, inclusive (defaults to `+Infinity`).
|
|
14
|
+
* @returns `true` if `value` is a finite number within range, otherwise `false`.
|
|
15
|
+
* @example isNumber(17, 10, 20) // true
|
|
16
|
+
* @see https://dhoulb.github.io/shelving/util/number/isNumber
|
|
17
|
+
*/
|
|
5
18
|
export declare function isNumber(value: unknown, min?: number, max?: number): value is number;
|
|
6
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Assert that a value is a finite number (optionally within a specified min/max range).
|
|
21
|
+
*
|
|
22
|
+
* @param value The value to assert.
|
|
23
|
+
* @param min Minimum allowed value, inclusive.
|
|
24
|
+
* @param max Maximum allowed value, inclusive.
|
|
25
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
26
|
+
* @returns Nothing; narrows `value` to `number`.
|
|
27
|
+
* @throws RequiredError if `value` is not a finite number within range.
|
|
28
|
+
* @example assertNumber(5, 0, 10); // passes
|
|
29
|
+
* @see https://dhoulb.github.io/shelving/util/number/assertNumber
|
|
30
|
+
*/
|
|
7
31
|
export declare function assertNumber(value: unknown, min?: number, max?: number, caller?: AnyCaller): asserts value is number;
|
|
8
32
|
/**
|
|
9
33
|
* Convert an unknown value to a finite number, or return `undefined` if it cannot be converted.
|
|
@@ -15,15 +39,49 @@ export declare function assertNumber(value: unknown, min?: number, max?: number,
|
|
|
15
39
|
* - Strings are parsed as numbers using `Number.parseFloat()` after removing all non-numeric characters.
|
|
16
40
|
* - Dates return their milliseconds (e.g. `date.getTime()`).
|
|
17
41
|
* - Everything else returns `undefined`
|
|
42
|
+
*
|
|
43
|
+
* @param value The value to convert.
|
|
44
|
+
* @returns The finite number, or `undefined` if `value` cannot be converted.
|
|
45
|
+
* @example getNumber("1.5kg") // 1.5
|
|
46
|
+
* @see https://dhoulb.github.io/shelving/util/number/getNumber
|
|
18
47
|
*/
|
|
19
48
|
export declare function getNumber(value: unknown): number | undefined;
|
|
20
49
|
/**
|
|
21
50
|
* Convert a possible number to a finite number, or throw `ValueError` if the value cannot be converted.
|
|
51
|
+
*
|
|
52
|
+
* @param value The value to convert.
|
|
53
|
+
* @param min Minimum allowed value, inclusive.
|
|
54
|
+
* @param max Maximum allowed value, inclusive.
|
|
55
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
56
|
+
* @returns The finite number.
|
|
57
|
+
* @throws RequiredError if `value` cannot be converted to a finite number within range.
|
|
58
|
+
* @example requireNumber("42") // 42
|
|
59
|
+
* @see https://dhoulb.github.io/shelving/util/number/requireNumber
|
|
22
60
|
*/
|
|
23
61
|
export declare function requireNumber(value: PossibleNumber, min?: number, max?: number, caller?: AnyCaller): number;
|
|
24
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Is an unknown value an integer (optionally within specified min/max values)?
|
|
64
|
+
*
|
|
65
|
+
* @param value The value to test.
|
|
66
|
+
* @param min Minimum allowed value, inclusive (defaults to `Number.MIN_SAFE_INTEGER`).
|
|
67
|
+
* @param max Maximum allowed value, inclusive (defaults to `Number.MAX_SAFE_INTEGER`).
|
|
68
|
+
* @returns `true` if `value` is an integer within range, otherwise `false`.
|
|
69
|
+
* @example isInteger(5, 0, 10) // true
|
|
70
|
+
* @see https://dhoulb.github.io/shelving/util/number/isInteger
|
|
71
|
+
*/
|
|
25
72
|
export declare function isInteger(value: unknown, min?: number, max?: number): value is number;
|
|
26
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Assert that a value is an integer (optionally within specified min/max values).
|
|
75
|
+
*
|
|
76
|
+
* @param value The value to assert.
|
|
77
|
+
* @param min Minimum allowed value, inclusive.
|
|
78
|
+
* @param max Maximum allowed value, inclusive.
|
|
79
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
80
|
+
* @returns Nothing; narrows `value` to `number`.
|
|
81
|
+
* @throws RequiredError if `value` is not an integer within range.
|
|
82
|
+
* @example assertInteger(5, 0, 10); // passes
|
|
83
|
+
* @see https://dhoulb.github.io/shelving/util/number/assertInteger
|
|
84
|
+
*/
|
|
27
85
|
export declare function assertInteger(value: unknown, min?: number, max?: number, caller?: AnyCaller): asserts value is number;
|
|
28
86
|
/**
|
|
29
87
|
* Convert an unknown value to an integer, or return `undefined` if it cannot be converted.
|
|
@@ -34,9 +92,25 @@ export declare function assertInteger(value: unknown, min?: number, max?: number
|
|
|
34
92
|
* - Strings are parsed as integers using `parseInt()` after removing non-numeric characters.
|
|
35
93
|
* - Dates return their milliseconds (e.g. `date.getTime()`).
|
|
36
94
|
* - Everything else returns `undefined`
|
|
95
|
+
*
|
|
96
|
+
* @param value The value to convert.
|
|
97
|
+
* @returns The integer, or `undefined` if `value` cannot be converted.
|
|
98
|
+
* @example getInteger("42px") // 42
|
|
99
|
+
* @see https://dhoulb.github.io/shelving/util/number/getInteger
|
|
37
100
|
*/
|
|
38
101
|
export declare function getInteger(value: unknown): number | undefined;
|
|
39
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Convert a possible number to an integer, or throw `ValueError` if the value cannot be converted.
|
|
104
|
+
*
|
|
105
|
+
* @param value The value to convert.
|
|
106
|
+
* @param min Minimum allowed value, inclusive.
|
|
107
|
+
* @param max Maximum allowed value, inclusive.
|
|
108
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
109
|
+
* @returns The integer.
|
|
110
|
+
* @throws RequiredError if `value` cannot be converted to an integer within range.
|
|
111
|
+
* @example requireInteger("42") // 42
|
|
112
|
+
* @see https://dhoulb.github.io/shelving/util/number/requireInteger
|
|
113
|
+
*/
|
|
40
114
|
export declare function requireInteger(value: PossibleNumber, min?: number, max?: number, caller?: AnyCaller): number;
|
|
41
115
|
/**
|
|
42
116
|
* Is a number within a specified range?
|
|
@@ -44,6 +118,9 @@ export declare function requireInteger(value: PossibleNumber, min?: number, max?
|
|
|
44
118
|
* @param num The number to test, e.g. `17`
|
|
45
119
|
* @param min The start of the range, e.g. `10`
|
|
46
120
|
* @param max The end of the range, e.g. `20`
|
|
121
|
+
* @returns `true` if `num` is between `min` and `max` (inclusive), otherwise `false`.
|
|
122
|
+
* @example isBetween(17, 10, 20) // true
|
|
123
|
+
* @see https://dhoulb.github.io/shelving/util/number/isBetween
|
|
47
124
|
*/
|
|
48
125
|
export declare function isBetween(num: number, min: number, max: number): boolean;
|
|
49
126
|
/**
|
|
@@ -53,6 +130,8 @@ export declare function isBetween(num: number, min: number, max: number): boolea
|
|
|
53
130
|
* @param step The rounding to round to, e.g. `2` or `0.1` (defaults to `1`, i.e. round numbers).
|
|
54
131
|
*
|
|
55
132
|
* @returns The number rounded to the specified step.
|
|
133
|
+
* @example roundStep(17, 5) // 15
|
|
134
|
+
* @see https://dhoulb.github.io/shelving/util/number/roundStep
|
|
56
135
|
*/
|
|
57
136
|
export declare function roundStep(num: number, step?: number): number;
|
|
58
137
|
/**
|
|
@@ -64,6 +143,8 @@ export declare function roundStep(num: number, step?: number): number;
|
|
|
64
143
|
* @param precision Maximum number of digits shown after the decimal point (defaults to 10).
|
|
65
144
|
*
|
|
66
145
|
* @returns The number rounded to the specified precision.
|
|
146
|
+
* @example roundNumber(1.2345, 2) // 1.23
|
|
147
|
+
* @see https://dhoulb.github.io/shelving/util/number/roundNumber
|
|
67
148
|
*/
|
|
68
149
|
export declare function roundNumber(num: number, precision?: number): number;
|
|
69
150
|
/**
|
|
@@ -73,11 +154,21 @@ export declare function roundNumber(num: number, precision?: number): number;
|
|
|
73
154
|
* @param num The number to truncate.
|
|
74
155
|
* @param precision Maximum number of digits shown after the decimal point (defaults to 0).
|
|
75
156
|
* @returns The number truncated to the specified precision.
|
|
157
|
+
* @example truncateNumber(1.2999, 2) // 1.29
|
|
158
|
+
* @see https://dhoulb.github.io/shelving/util/number/truncateNumber
|
|
76
159
|
*/
|
|
77
160
|
export declare function truncateNumber(num: number, precision?: number): number;
|
|
78
161
|
/**
|
|
79
162
|
* Bound a number between two values.
|
|
80
163
|
* - e.g. `12` bounded by `2` and `8` is `8`
|
|
164
|
+
*
|
|
165
|
+
* @param num The number to bound.
|
|
166
|
+
* @param min The minimum bound, inclusive.
|
|
167
|
+
* @param max The maximum bound, inclusive.
|
|
168
|
+
* @returns `num` clamped to lie between `min` and `max`.
|
|
169
|
+
* @throws ValueError if `max` is less than `min`.
|
|
170
|
+
* @example boundNumber(12, 2, 8) // 8
|
|
171
|
+
* @see https://dhoulb.github.io/shelving/util/number/boundNumber
|
|
81
172
|
*/
|
|
82
173
|
export declare function boundNumber(num: number, min: number, max: number): number;
|
|
83
174
|
/**
|
|
@@ -86,6 +177,14 @@ export declare function boundNumber(num: number, min: number, max: number): numb
|
|
|
86
177
|
* - e.g. `12` bounded by `2` and `8` is `6`
|
|
87
178
|
* - Words in both directions.
|
|
88
179
|
* - e.g. `-2` bounded by `2` and `8` is `4`
|
|
180
|
+
*
|
|
181
|
+
* @param num The number to wrap.
|
|
182
|
+
* @param min The minimum bound, inclusive.
|
|
183
|
+
* @param max The maximum bound, exclusive (values wrap back to `min`).
|
|
184
|
+
* @returns `num` wrapped to lie between `min` and `max`.
|
|
185
|
+
* @throws ValueError if `max` is less than `min`.
|
|
186
|
+
* @example wrapNumber(12, 2, 8) // 6
|
|
187
|
+
* @see https://dhoulb.github.io/shelving/util/number/wrapNumber
|
|
89
188
|
*/
|
|
90
189
|
export declare function wrapNumber(num: number, min: number, max: number): number;
|
|
91
190
|
/**
|
|
@@ -93,9 +192,27 @@ export declare function wrapNumber(num: number, min: number, max: number): numbe
|
|
|
93
192
|
*
|
|
94
193
|
* @param numerator Number representing the amount of progress.
|
|
95
194
|
* @param denumerator The number representing the whole amount (defaults to 100).
|
|
195
|
+
* @returns `numerator` expressed as a percentage of `denumerator`.
|
|
196
|
+
* @example getPercent(1, 4) // 25
|
|
197
|
+
* @see https://dhoulb.github.io/shelving/util/number/getPercent
|
|
96
198
|
*/
|
|
97
199
|
export declare function getPercent(numerator: number, denumerator?: number): number;
|
|
98
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* Sum an iterable set of numbers and return the total.
|
|
202
|
+
*
|
|
203
|
+
* @param nums The iterable of numbers to sum.
|
|
204
|
+
* @returns The total of all the numbers (`0` if `nums` is empty).
|
|
205
|
+
* @example sumNumbers([1, 2, 3]) // 6
|
|
206
|
+
* @see https://dhoulb.github.io/shelving/util/number/sumNumbers
|
|
207
|
+
*/
|
|
99
208
|
export declare function sumNumbers(nums: Iterable<number>): number;
|
|
100
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* Find the number that's closest to a target in an iterable set of numbers.
|
|
211
|
+
*
|
|
212
|
+
* @param nums The iterable of numbers to search.
|
|
213
|
+
* @param target The target number to find the closest match for.
|
|
214
|
+
* @returns The number closest to `target`, or `undefined` if `nums` is empty.
|
|
215
|
+
* @example getClosestNumber([1, 5, 10], 6) // 5
|
|
216
|
+
* @see https://dhoulb.github.io/shelving/util/number/getClosestNumber
|
|
217
|
+
*/
|
|
101
218
|
export declare function getClosestNumber<T extends number>(nums: Iterable<T>, target: number): T | undefined;
|
package/util/number.js
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import { RequiredError } from "../error/RequiredError.js";
|
|
2
2
|
import { ValueError } from "../error/ValueError.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Is a value a finite number (optionally within a specified min/max range)?
|
|
5
|
+
*
|
|
6
|
+
* @param value The value to test.
|
|
7
|
+
* @param min Minimum allowed value, inclusive (defaults to `-Infinity`).
|
|
8
|
+
* @param max Maximum allowed value, inclusive (defaults to `+Infinity`).
|
|
9
|
+
* @returns `true` if `value` is a finite number within range, otherwise `false`.
|
|
10
|
+
* @example isNumber(17, 10, 20) // true
|
|
11
|
+
* @see https://dhoulb.github.io/shelving/util/number/isNumber
|
|
12
|
+
*/
|
|
4
13
|
export function isNumber(value, min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY) {
|
|
5
14
|
return Number.isFinite(value) && value >= min && value <= max;
|
|
6
15
|
}
|
|
7
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Assert that a value is a finite number (optionally within a specified min/max range).
|
|
18
|
+
*
|
|
19
|
+
* @param value The value to assert.
|
|
20
|
+
* @param min Minimum allowed value, inclusive.
|
|
21
|
+
* @param max Maximum allowed value, inclusive.
|
|
22
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
23
|
+
* @returns Nothing; narrows `value` to `number`.
|
|
24
|
+
* @throws RequiredError if `value` is not a finite number within range.
|
|
25
|
+
* @example assertNumber(5, 0, 10); // passes
|
|
26
|
+
* @see https://dhoulb.github.io/shelving/util/number/assertNumber
|
|
27
|
+
*/
|
|
8
28
|
export function assertNumber(value, min, max, caller = assertNumber) {
|
|
9
29
|
if (!isNumber(value, min, max))
|
|
10
30
|
throw new RequiredError(`Must be finite number${max !== undefined ? ` between ${min ?? 0} and ${max}` : min !== undefined ? ` above ${min}` : ""}`, { received: value, caller });
|
|
@@ -19,6 +39,11 @@ export function assertNumber(value, min, max, caller = assertNumber) {
|
|
|
19
39
|
* - Strings are parsed as numbers using `Number.parseFloat()` after removing all non-numeric characters.
|
|
20
40
|
* - Dates return their milliseconds (e.g. `date.getTime()`).
|
|
21
41
|
* - Everything else returns `undefined`
|
|
42
|
+
*
|
|
43
|
+
* @param value The value to convert.
|
|
44
|
+
* @returns The finite number, or `undefined` if `value` cannot be converted.
|
|
45
|
+
* @example getNumber("1.5kg") // 1.5
|
|
46
|
+
* @see https://dhoulb.github.io/shelving/util/number/getNumber
|
|
22
47
|
*/
|
|
23
48
|
export function getNumber(value) {
|
|
24
49
|
if (typeof value === "number" && Number.isFinite(value))
|
|
@@ -31,17 +56,46 @@ export function getNumber(value) {
|
|
|
31
56
|
const NOT_NUMERIC_REGEXP = /[^0-9-.]/g;
|
|
32
57
|
/**
|
|
33
58
|
* Convert a possible number to a finite number, or throw `ValueError` if the value cannot be converted.
|
|
59
|
+
*
|
|
60
|
+
* @param value The value to convert.
|
|
61
|
+
* @param min Minimum allowed value, inclusive.
|
|
62
|
+
* @param max Maximum allowed value, inclusive.
|
|
63
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
64
|
+
* @returns The finite number.
|
|
65
|
+
* @throws RequiredError if `value` cannot be converted to a finite number within range.
|
|
66
|
+
* @example requireNumber("42") // 42
|
|
67
|
+
* @see https://dhoulb.github.io/shelving/util/number/requireNumber
|
|
34
68
|
*/
|
|
35
69
|
export function requireNumber(value, min, max, caller) {
|
|
36
70
|
const num = getNumber(value);
|
|
37
71
|
assertNumber(num, min, max, caller);
|
|
38
72
|
return num;
|
|
39
73
|
}
|
|
40
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Is an unknown value an integer (optionally within specified min/max values)?
|
|
76
|
+
*
|
|
77
|
+
* @param value The value to test.
|
|
78
|
+
* @param min Minimum allowed value, inclusive (defaults to `Number.MIN_SAFE_INTEGER`).
|
|
79
|
+
* @param max Maximum allowed value, inclusive (defaults to `Number.MAX_SAFE_INTEGER`).
|
|
80
|
+
* @returns `true` if `value` is an integer within range, otherwise `false`.
|
|
81
|
+
* @example isInteger(5, 0, 10) // true
|
|
82
|
+
* @see https://dhoulb.github.io/shelving/util/number/isInteger
|
|
83
|
+
*/
|
|
41
84
|
export function isInteger(value, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
|
|
42
85
|
return Number.isInteger(value) && value >= min && value <= max;
|
|
43
86
|
}
|
|
44
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Assert that a value is an integer (optionally within specified min/max values).
|
|
89
|
+
*
|
|
90
|
+
* @param value The value to assert.
|
|
91
|
+
* @param min Minimum allowed value, inclusive.
|
|
92
|
+
* @param max Maximum allowed value, inclusive.
|
|
93
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
94
|
+
* @returns Nothing; narrows `value` to `number`.
|
|
95
|
+
* @throws RequiredError if `value` is not an integer within range.
|
|
96
|
+
* @example assertInteger(5, 0, 10); // passes
|
|
97
|
+
* @see https://dhoulb.github.io/shelving/util/number/assertInteger
|
|
98
|
+
*/
|
|
45
99
|
export function assertInteger(value, min, max, caller = assertInteger) {
|
|
46
100
|
if (!isInteger(value, min, max))
|
|
47
101
|
throw new RequiredError(`Must be integer${max !== undefined ? ` between ${min ?? 0} and ${max}` : min !== undefined ? ` above ${min}` : ""}`, { received: value, caller });
|
|
@@ -55,6 +109,11 @@ export function assertInteger(value, min, max, caller = assertInteger) {
|
|
|
55
109
|
* - Strings are parsed as integers using `parseInt()` after removing non-numeric characters.
|
|
56
110
|
* - Dates return their milliseconds (e.g. `date.getTime()`).
|
|
57
111
|
* - Everything else returns `undefined`
|
|
112
|
+
*
|
|
113
|
+
* @param value The value to convert.
|
|
114
|
+
* @returns The integer, or `undefined` if `value` cannot be converted.
|
|
115
|
+
* @example getInteger("42px") // 42
|
|
116
|
+
* @see https://dhoulb.github.io/shelving/util/number/getInteger
|
|
58
117
|
*/
|
|
59
118
|
export function getInteger(value) {
|
|
60
119
|
if (typeof value === "number" && Number.isInteger(value))
|
|
@@ -64,7 +123,18 @@ export function getInteger(value) {
|
|
|
64
123
|
if (value instanceof Date)
|
|
65
124
|
return getInteger(value.getTime());
|
|
66
125
|
}
|
|
67
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* Convert a possible number to an integer, or throw `ValueError` if the value cannot be converted.
|
|
128
|
+
*
|
|
129
|
+
* @param value The value to convert.
|
|
130
|
+
* @param min Minimum allowed value, inclusive.
|
|
131
|
+
* @param max Maximum allowed value, inclusive.
|
|
132
|
+
* @param caller Function used to attribute a thrown error to the calling site.
|
|
133
|
+
* @returns The integer.
|
|
134
|
+
* @throws RequiredError if `value` cannot be converted to an integer within range.
|
|
135
|
+
* @example requireInteger("42") // 42
|
|
136
|
+
* @see https://dhoulb.github.io/shelving/util/number/requireInteger
|
|
137
|
+
*/
|
|
68
138
|
export function requireInteger(value, min, max, caller = requireInteger) {
|
|
69
139
|
const num = getNumber(value);
|
|
70
140
|
assertInteger(num, min, max, caller);
|
|
@@ -76,6 +146,9 @@ export function requireInteger(value, min, max, caller = requireInteger) {
|
|
|
76
146
|
* @param num The number to test, e.g. `17`
|
|
77
147
|
* @param min The start of the range, e.g. `10`
|
|
78
148
|
* @param max The end of the range, e.g. `20`
|
|
149
|
+
* @returns `true` if `num` is between `min` and `max` (inclusive), otherwise `false`.
|
|
150
|
+
* @example isBetween(17, 10, 20) // true
|
|
151
|
+
* @see https://dhoulb.github.io/shelving/util/number/isBetween
|
|
79
152
|
*/
|
|
80
153
|
export function isBetween(num, min, max) {
|
|
81
154
|
return num >= min && num <= max;
|
|
@@ -87,6 +160,8 @@ export function isBetween(num, min, max) {
|
|
|
87
160
|
* @param step The rounding to round to, e.g. `2` or `0.1` (defaults to `1`, i.e. round numbers).
|
|
88
161
|
*
|
|
89
162
|
* @returns The number rounded to the specified step.
|
|
163
|
+
* @example roundStep(17, 5) // 15
|
|
164
|
+
* @see https://dhoulb.github.io/shelving/util/number/roundStep
|
|
90
165
|
*/
|
|
91
166
|
export function roundStep(num, step = 1) {
|
|
92
167
|
return Math.round(num / step) * step;
|
|
@@ -100,6 +175,8 @@ export function roundStep(num, step = 1) {
|
|
|
100
175
|
* @param precision Maximum number of digits shown after the decimal point (defaults to 10).
|
|
101
176
|
*
|
|
102
177
|
* @returns The number rounded to the specified precision.
|
|
178
|
+
* @example roundNumber(1.2345, 2) // 1.23
|
|
179
|
+
* @see https://dhoulb.github.io/shelving/util/number/roundNumber
|
|
103
180
|
*/
|
|
104
181
|
export function roundNumber(num, precision = 0) {
|
|
105
182
|
return Math.round(num * 10 ** precision) / 10 ** precision;
|
|
@@ -111,6 +188,8 @@ export function roundNumber(num, precision = 0) {
|
|
|
111
188
|
* @param num The number to truncate.
|
|
112
189
|
* @param precision Maximum number of digits shown after the decimal point (defaults to 0).
|
|
113
190
|
* @returns The number truncated to the specified precision.
|
|
191
|
+
* @example truncateNumber(1.2999, 2) // 1.29
|
|
192
|
+
* @see https://dhoulb.github.io/shelving/util/number/truncateNumber
|
|
114
193
|
*/
|
|
115
194
|
export function truncateNumber(num, precision = 0) {
|
|
116
195
|
return Math.trunc(num * 10 ** precision) / 10 ** precision;
|
|
@@ -118,6 +197,14 @@ export function truncateNumber(num, precision = 0) {
|
|
|
118
197
|
/**
|
|
119
198
|
* Bound a number between two values.
|
|
120
199
|
* - e.g. `12` bounded by `2` and `8` is `8`
|
|
200
|
+
*
|
|
201
|
+
* @param num The number to bound.
|
|
202
|
+
* @param min The minimum bound, inclusive.
|
|
203
|
+
* @param max The maximum bound, inclusive.
|
|
204
|
+
* @returns `num` clamped to lie between `min` and `max`.
|
|
205
|
+
* @throws ValueError if `max` is less than `min`.
|
|
206
|
+
* @example boundNumber(12, 2, 8) // 8
|
|
207
|
+
* @see https://dhoulb.github.io/shelving/util/number/boundNumber
|
|
121
208
|
*/
|
|
122
209
|
export function boundNumber(num, min, max) {
|
|
123
210
|
if (max < min)
|
|
@@ -130,6 +217,14 @@ export function boundNumber(num, min, max) {
|
|
|
130
217
|
* - e.g. `12` bounded by `2` and `8` is `6`
|
|
131
218
|
* - Words in both directions.
|
|
132
219
|
* - e.g. `-2` bounded by `2` and `8` is `4`
|
|
220
|
+
*
|
|
221
|
+
* @param num The number to wrap.
|
|
222
|
+
* @param min The minimum bound, inclusive.
|
|
223
|
+
* @param max The maximum bound, exclusive (values wrap back to `min`).
|
|
224
|
+
* @returns `num` wrapped to lie between `min` and `max`.
|
|
225
|
+
* @throws ValueError if `max` is less than `min`.
|
|
226
|
+
* @example wrapNumber(12, 2, 8) // 6
|
|
227
|
+
* @see https://dhoulb.github.io/shelving/util/number/wrapNumber
|
|
133
228
|
*/
|
|
134
229
|
export function wrapNumber(num, min, max) {
|
|
135
230
|
if (max < min)
|
|
@@ -145,18 +240,36 @@ export function wrapNumber(num, min, max) {
|
|
|
145
240
|
*
|
|
146
241
|
* @param numerator Number representing the amount of progress.
|
|
147
242
|
* @param denumerator The number representing the whole amount (defaults to 100).
|
|
243
|
+
* @returns `numerator` expressed as a percentage of `denumerator`.
|
|
244
|
+
* @example getPercent(1, 4) // 25
|
|
245
|
+
* @see https://dhoulb.github.io/shelving/util/number/getPercent
|
|
148
246
|
*/
|
|
149
247
|
export function getPercent(numerator, denumerator = 100) {
|
|
150
248
|
return denumerator === 100 ? numerator : (100 / denumerator) * numerator;
|
|
151
249
|
}
|
|
152
|
-
/**
|
|
250
|
+
/**
|
|
251
|
+
* Sum an iterable set of numbers and return the total.
|
|
252
|
+
*
|
|
253
|
+
* @param nums The iterable of numbers to sum.
|
|
254
|
+
* @returns The total of all the numbers (`0` if `nums` is empty).
|
|
255
|
+
* @example sumNumbers([1, 2, 3]) // 6
|
|
256
|
+
* @see https://dhoulb.github.io/shelving/util/number/sumNumbers
|
|
257
|
+
*/
|
|
153
258
|
export function sumNumbers(nums) {
|
|
154
259
|
let sum = 0;
|
|
155
260
|
for (const num of nums)
|
|
156
261
|
sum += num;
|
|
157
262
|
return sum;
|
|
158
263
|
}
|
|
159
|
-
/**
|
|
264
|
+
/**
|
|
265
|
+
* Find the number that's closest to a target in an iterable set of numbers.
|
|
266
|
+
*
|
|
267
|
+
* @param nums The iterable of numbers to search.
|
|
268
|
+
* @param target The target number to find the closest match for.
|
|
269
|
+
* @returns The number closest to `target`, or `undefined` if `nums` is empty.
|
|
270
|
+
* @example getClosestNumber([1, 5, 10], 6) // 5
|
|
271
|
+
* @see https://dhoulb.github.io/shelving/util/number/getClosestNumber
|
|
272
|
+
*/
|
|
160
273
|
export function getClosestNumber(nums, target) {
|
|
161
274
|
let closest;
|
|
162
275
|
for (const item of nums)
|