New:Socket for Asana Is Now Available.Learn more
Get Started

@socketregistry/is-async-function

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@socketregistry/is-async-function - npm Package Compare versions

Comparing version
0.0.0
to
1.0.0
+2
index.d.ts
declare function isAsyncFunction(fn: unknown): boolean
export = isAsyncFunction
'use strict'
const { toString: fnToStr } = Function.prototype
const asyncFuncProto = Object.getPrototypeOf(async function () {})
const { apply: ReflectApply, getPrototypeOf: ReflectGetPrototypeOf } = Reflect
const { test: RegExpProtoTest } = RegExp.prototype
// Source text of an async function, as `Function.prototype.toString` renders
// it. Two shapes reach here: an arrow or method, `async (`, where the space is
// optional; and a declaration or expression, `async function (`, where at
// least one space separates the keywords and the name is optional. Alternation
// branches are sorted alphanumerically (socket/sort-regex-alternations); the
// order is behaviour-neutral because the two branches cannot both match, `\s*\(`
// requires a paren where `\s+function` requires the keyword.
const isFnRegExp = /^\s*async(?:\s*\(|\s+function(?:\(|\s+))/
module.exports = function isAsyncFunction(fn) {
return (
typeof fn === 'function' &&
(ReflectApply(RegExpProtoTest, isFnRegExp, [
ReflectApply(fnToStr, fn, []),
]) ||
ReflectGetPrototypeOf(fn) === asyncFuncProto)
)
}
MIT License
Copyright (c) 2024 Socket Inc
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Sorry, the diff of this file is not supported yet

+36
-5
{
"name": "@socketregistry/is-async-function",
"version": "0.0.0",
"private": false,
"version": "1.0.0",
"description": "Socket.dev optimized package override for is-async-function",
"keywords": [
"Socket.dev",
"package-overrides"
],
"homepage": "https://github.com/SocketDev/socket-registry/tree/main/packages/npm/is-async-function",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/SocketDev/socket-registry.git",
"directory": "packages/npm/is-async-function"
},
"files": [
"*.d.ts",
"*.js"
],
"sideEffects": false,
"exports": {
".": {
"types": "./index.d.ts",
"default": "./index.js"
},
"./package.json": "./package.json"
},
"publishConfig": {
"access": "public"
"access": "public",
"provenance": true
},
"files": []
}
"engines": {
"node": ">=24"
},
"socket": {
"categories": [
"cleanup"
]
}
}
# @socketregistry/is-async-function
Placeholder to reserve the name for npm trusted publishing. Real releases publish via CI (OIDC/provenance).
[![Socket Badge](https://socket.dev/api/badge/npm/package/@socketregistry/is-async-function)](https://socket.dev/npm/package/@socketregistry/is-async-function)
[![CI - @socketregistry/is-async-function](https://github.com/SocketDev/socket-registry/actions/workflows/ci.yml/badge.svg)](https://github.com/SocketDev/socket-registry/actions/workflows/ci.yml)
[![Follow @SocketSecurity](https://img.shields.io/twitter/follow/SocketSecurity?style=social)](https://twitter.com/SocketSecurity)
[![Follow @socket.dev on Bluesky](https://img.shields.io/badge/Follow-@socket.dev-1DA1F2?style=social&logo=bluesky)](https://bsky.app/profile/socket.dev)
> A tested zero dependency drop-in replacement of [`is-async-function`](https://socket.dev/npm/package/is-async-function) complete with TypeScript types.
## Installation
### Install as a package override
[`socket`](https://socket.dev/npm/package/socket)
CLI will automagically ✨ populate
[overrides](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides)
and [resolutions](https://yarnpkg.com/configuration/manifest#resolutions)
of your `package.json`.
```sh
pnpm install -g socket@1.1.147
socket optimize
```
Prefer to do it yourself? Add `@socketregistry/is-async-function`
to your `package.json`.
```json
{
"overrides": {
"is-async-function": "npm:@socketregistry/is-async-function@^1"
},
"resolutions": {
"is-async-function": "npm:@socketregistry/is-async-function@^1"
}
}
```
### Install as a plain dependency
Install with your favorite package manager.
```sh
pnpm install @socketregistry/is-async-function
```
## Requirements
Node >= `24`