is-cloud-function
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

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 GOOGLE
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)

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.

Package Sidebar

Install

npm i is-cloud-function

Weekly Downloads

1

Version

1.1.4

License

MIT

Unpacked Size

13.4 kB

Total Files

30

Last publish

Collaborators

  • sebastien-abbal