https://github.com/jonathanong/fn-getter
Simple, lazyily evaluated values
https://github.com/jonathanong/fn-getter
Last synced: 2 months ago
JSON representation
Simple, lazyily evaluated values
- Host: GitHub
- URL: https://github.com/jonathanong/fn-getter
- Owner: jonathanong
- License: mit
- Created: 2015-12-25T07:19:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-24T16:36:50.000Z (about 8 years ago)
- Last Synced: 2025-04-09T10:17:28.204Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 9
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fn-getter
[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![Dependency Status][david-image]][david-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]Simple, lazyily evaluated values.
If a value takes too long to calculate,
but you don't need it right away (ex. on startup),
then evaluate lazily.```js
const createGetter = require('fn-getter')const createS3Client = createGetter(() => {
const AWS = require('aws-sdk')
return new AWS.S3()
})
```Maybe you want to evaluate it after the first time:
```js
setImmediate(createS3Client)
```Then, when you need to use it:
```js
app.use((req, res, next) => {
createS3Client().putObject(...)
})
```[npm-image]: https://img.shields.io/npm/v/fn-getter.svg?style=flat-square
[npm-url]: https://npmjs.org/package/fn-getter
[travis-image]: https://img.shields.io/travis/jonathanong/fn-getter.svg?style=flat-square
[travis-url]: https://travis-ci.org/jonathanong/fn-getter
[codecov-image]: https://img.shields.io/codecov/c/github/jonathanong/fn-getter/master.svg?style=flat-square
[codecov-url]: https://codecov.io/github/jonathanong/fn-getter
[david-image]: http://img.shields.io/david/jonathanong/fn-getter.svg?style=flat-square
[david-url]: https://david-dm.org/jonathanong/fn-getter
[license-image]: http://img.shields.io/npm/l/fn-getter.svg?style=flat-square
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/fn-getter.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/fn-getter