1.1.4 • Published 2 years ago
is-cloud-function v1.1.4
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
Provider | Enabled | Type |
---|---|---|
AWS Lambdas | ✅ | AWS |
Google cloud functions | ✅ | |
Azure functions | ✅ | AZURE |
IBM Cloud Functions | ❌ | - |
Cloudflare workers | ❌ | - |
Apex | ❌ | - |
Configuration
You can manage a specific configuration to the isCloudFunction
:
- Config
- type:
PROVIDER
|BOOLEAN
(default:BOOLEAN
)
- type:
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) {
// ... your logic ...
}
// Same like example above
if (isCloudFunction({ type: 'BOOLEAN' }) === true) {
// ... your logic ...
}
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') {
// ... your logic ...
}
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
) {
// ... your logic ...
}
🚦 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.