Socket
Book a DemoInstallSign in
Socket

is-cloud-function

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-cloud-function

A package who returns if your code is running on a cloud function (AWS, Google, Azure)

latest
Source
npmnpm
Version
1.1.4
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

google

FAQs

Package last updated on 31 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts