1.1.4 • Published 2 years ago

is-cloud-function v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

ProviderEnabledType
AWS LambdasAWS
Google cloud functionsGOOGLE
Azure functionsAZURE
IBM Cloud Functions-
Cloudflare workers-
Apex-

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) {
  // ... 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.

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago