Welcome to is-cloud-function package
This is a package who returns a boolean if your code is running on a cloud function (AWS, Google, Azure) made by Sébastien Abbal. It's working with node.js language and Typescript.
🚀 Get started
Installation
$ npm install is-cloud-function
// or
$ yarn add is-cloud-function
Example
import { isCloudFunction } from 'is-cloud-function';
console.log(isCloudFunction());
👾 Usage
Configuration
You can manage a specific configuration to the isCloudFunction
:
- Config
- type:
PROVIDER
| BOOLEAN
(default: BOOLEAN
)
Example n°1: Get boolean if your project is running in cloud function of any provider listed above.
import { isCloudFunction } from 'is-cloud-function';
if (isCloudFunction() === true) {
}
if (isCloudFunction({ type: 'BOOLEAN' }) === true) {
}
Example n°2: Get provider type if your project is running in cloud function of any provider listed above.
import { isCloudFunction } from 'is-cloud-function';
if (isCloudFunction({ type: 'PROVIDER' }) === 'AWS') {
}
Example n°3: Best practices
⚠️ Set the values from the enums represents a better practice than the "magic variables".
import { isCloudFunction, ICF_EnumConfigType } from 'is-cloud-function';
if (
isCloudFunction({ type: ICF_EnumConfigType.PROVIDER }) ===
ICF_EnumProviderType.AZURE
) {
}
🚦 Tests
To test all the app with jest (100% coverage), you need to run this command line:
$ yarn test
License
This package is MIT licensed.