Skip to content

Commit

Permalink
feat(version): bump
Browse files Browse the repository at this point in the history
  • Loading branch information
MathRobin committed Jun 28, 2024
1 parent 9a20898 commit a6d5e40
Show file tree
Hide file tree
Showing 7 changed files with 2,125 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ out

# Nuxt.js build / generate output
.nuxt
dist
#dist

# Gatsby files
.cache/
Expand Down
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![Static Badge](https://img.shields.io/badge/coverage-99.4-brightgreen)
![Static Badge](https://img.shields.io/badge/release-4.1.0-blue)
![Static Badge](https://img.shields.io/badge/release-4.2.0-blue)
[![test](https://github.com/mathrobin/lambda-returns/actions/workflows/test.yml/badge.svg)](https://github.com/mathrobin/lambda-returns/actions/workflows/test.yml)

# lambda-returns
Expand All @@ -9,6 +9,8 @@ Provides shorthand to manage AWS lambda result. And provides test helper methods

Native TS. Typings included. 0 prod dependencies.

Tested with Node.js **18**, **20** and **22**.

## Usage

Deadly simple
Expand Down Expand Up @@ -58,6 +60,7 @@ Or this incorrect but possible code:
```typescript
export default async () => {
return {
isBase64Encoded: false,
statusCode: 201, // no content code
body: JSON.stringify({
hello: "i'm anomaly",
Expand All @@ -76,6 +79,27 @@ export default async (): NoContentLambdaResponse => {
};
```

### Handling binary response

Want to return a pdf file or any other file ? Easy :)

```typescript
import { ok, OkLambdaResponse } from 'lambda-returns';
import { lookup } from 'mime-types'; // we strongly recommend usage

const yourFile = '...';

export default async (): OkLambdaResponse => {
return ok(
Buffer.from(yourFile.body).toString('base64'), // only base64 content is supported. Like on native AWS way.
{
'Content-Type': lookup('filename.pdf'), // can be any other kind of file: xlsx, doc, png, svg, zip, ...
},
true // just add flag at end of call
);
};
```

### Test helpers methods

Not enough for you? For me too. This package provides a simple way to test your return result from your AWS lambda
Expand All @@ -92,7 +116,7 @@ expect(isBadRequest(result)).toBeTruthy();

- No prod dependency
- Typings provided
- nearly 15kB unpacked, less than 2kB gzipped
- nearly 20kB unpacked, less than 2kB gzipped

### Stop remember codes

Expand Down
Loading

0 comments on commit a6d5e40

Please sign in to comment.