Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nwylynko/versioned-function
a simple function to handler multiple versions of the same function, eg for versioning sql queries
https://github.com/nwylynko/versioned-function
Last synced: about 1 month ago
JSON representation
a simple function to handler multiple versions of the same function, eg for versioning sql queries
- Host: GitHub
- URL: https://github.com/nwylynko/versioned-function
- Owner: NWylynko
- License: mit
- Created: 2022-10-19T02:56:51.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-19T08:34:16.000Z (over 2 years ago)
- Last Synced: 2024-10-25T23:10:02.577Z (3 months ago)
- Language: TypeScript
- Size: 94.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## versioned-function
```typescript
import { versioned } from "versioned-function";// --- define our functions ---
const { matcher } = versioned({
"0.0.0": () => ({ crazy: "world" }),
"1.0.0": () => ({ yea: "nah" }),
"2.0.0": (name: string) => ({ hello: name }),
});// export it out for others to use
export const MyFunction = matcher// --- consumer ---
// here we pass in the version that we want
const oldFunction = MyFunction("0.0.0")
const latestFunction = MyFunction("1.0.0")
const nextFunction = MyFunction("2.0.0")oldFunction() // { crazy: "world" }
latestFunction() // { yea: "nah" }
nextFunction("nick") // { hello: "nick" }
```