New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

composable-functions

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

composable-functions - npm Package Compare versions

Comparing version 1.0.0-beta-20240523-2 to 1.0.0-beta-20240523-3

API.md

2

package.json
{
"name": "composable-functions",
"version": "1.0.0-beta-20240523-2",
"version": "1.0.0-beta-20240523-3",
"description": "Types and functions to make composition easy and safe",

@@ -5,0 +5,0 @@ "author": "Seasoned",

@@ -163,2 +163,25 @@ <p align="center">

You can throw anything derived from `Error`. Check [this documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#custom_error_types) on how to define your custom errors. The library will also wrap anything that does not extends `Error`, just to keep compatibility with code-bases that throw strings or objects.
```typescript
import { composable } from 'composable-functions'
class NotFoundError extends Error {
constructor(message) {
super(message);
this.name = 'NotFoundError';
}
}
const getUser = composable((userId: string, users: Array<string>) => {
// ^? Composable<(userId: string, users: Array<string>) => string>
const result = users.find(({id}) => id === userId)
if(result == undefined) throw new NotFoundError(`userId ${userId} was not found`)
return result
})
```
The library defines a few custom errors out of the box but these will be more important later on, whend dealing with external input and schemas.
See [the errors module](./src/errors.ts) for more details.
### Catching

@@ -170,4 +193,3 @@ You can catch an error in a `Composable`, using `catchFailure` which is similar to `map` but will run whenever the first composable fails:

const getUser = composable((id: string) => fetchUser(id))
// ^? Composable<(id: string) => User>
// assuming we have the definitions from the previous example
const getOptionalUser = catchFailure(getUser, (errors, id) => {

@@ -177,3 +199,3 @@ console.log(`Failed to fetch user with id ${id}`, errors)

})
// ^? Composable<(id: string) => User | null>
// ^? Composable<(id: string) => string | null>
```

@@ -180,0 +202,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc