Socket
Book a DemoInstallSign in
Socket

is-generator-function

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-generator-function - npm Package Compare versions

Comparing version

to
1.1.0

index.d.ts

@@ -8,2 +8,23 @@ # Changelog

## [v1.1.0](https://github.com/inspect-js/is-generator-function/compare/v1.0.10...v1.1.0) - 2025-01-02
### Commits
- [actions] reuse common workflows [`7301651`](https://github.com/inspect-js/is-generator-function/commit/7301651ad24468ab17aee7a86a2dd2a6fcd58637)
- [actions] split out node 10-20, and 20+ [`40f30a5`](https://github.com/inspect-js/is-generator-function/commit/40f30a5dee3e26cad236ce0afbd0567b6075af54)
- [meta] use `npmignore` to autogenerate an npmignore file [`ec843a4`](https://github.com/inspect-js/is-generator-function/commit/ec843a4501d238fcde254c7e33c137ec997abfaa)
- [New] add types [`6dd27c4`](https://github.com/inspect-js/is-generator-function/commit/6dd27c4b6a3ebaa42ddbf4e93c20e2b4d90bad07)
- [actions] update codecov uploader [`717f85e`](https://github.com/inspect-js/is-generator-function/commit/717f85e8b080cdbdb160558b289ec9f043410bd2)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `safe-publish-latest`, `tape` [`4280e62`](https://github.com/inspect-js/is-generator-function/commit/4280e6260029ccdae8b299faadacafd0f8a2de78)
- [actions] update rebase action to use reusable workflow [`895c2d0`](https://github.com/inspect-js/is-generator-function/commit/895c2d06a914b82913d3fae2df3071bde72cb584)
- [Tests] use `for-each` [`3caee87`](https://github.com/inspect-js/is-generator-function/commit/3caee870b0509b91ad37e6a0562f261d7b5f4523)
- [Robustness] use `call-bound` [`1eb55de`](https://github.com/inspect-js/is-generator-function/commit/1eb55def663c335222d970c5e62459f73aee20db)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `object-inspect`, `tape` [`5bbd4cd`](https://github.com/inspect-js/is-generator-function/commit/5bbd4cd8bcbd167a05ddf1cd285fd1fd2802801a)
- [Robustness] use `safe-regex-test` [`5f8b992`](https://github.com/inspect-js/is-generator-function/commit/5f8b9921e4cf53c3cb4185a0f30a170fa2e0722f)
- [Dev Deps] update `@ljharb/eslint-config`, `auto-changelog`, `npmignore`, `tape` [`c730f4c`](https://github.com/inspect-js/is-generator-function/commit/c730f4c056697653ba935b37b44bf9bfe1017331)
- [Robustness] use `get-proto` [`6dfff38`](https://github.com/inspect-js/is-generator-function/commit/6dfff3821b8a42d0b0f70651abfe1d2e90afbb10)
- [Tests] replace `aud` with `npm audit` [`725db70`](https://github.com/inspect-js/is-generator-function/commit/725db703352200f7400fa4b2b2058e2220a4c42b)
- [Deps] update `has-tostringtag` [`5cc3c2d`](https://github.com/inspect-js/is-generator-function/commit/5cc3c2d34b77c3d7d50588225d4d4afa20aa3df2)
- [Dev Deps] add missing peer dep [`869a507`](https://github.com/inspect-js/is-generator-function/commit/869a507790e8cf1452b355719a6c00efadbe4965)
## [v1.0.10](https://github.com/inspect-js/is-generator-function/compare/v1.0.9...v1.0.10) - 2021-08-05

@@ -10,0 +31,0 @@

23

index.js
'use strict';
var toStr = Object.prototype.toString;
var fnToStr = Function.prototype.toString;
var isFnRegex = /^\s*(?:function)?\*/;
var callBound = require('call-bound');
var safeRegexTest = require('safe-regex-test');
var isFnRegex = safeRegexTest(/^\s*(?:function)?\*/);
var hasToStringTag = require('has-tostringtag/shams')();
var getProto = Object.getPrototypeOf;
var getProto = require('get-proto');
var toStr = callBound('Object.prototype.toString');
var fnToStr = callBound('Function.prototype.toString');
var getGeneratorFunc = function () { // eslint-disable-line consistent-return

@@ -17,4 +21,6 @@ if (!hasToStringTag) {

};
/** @type {undefined | false | null | GeneratorFunctionConstructor} */
var GeneratorFunction;
/** @type {import('.')} */
module.exports = function isGeneratorFunction(fn) {

@@ -24,7 +30,7 @@ if (typeof fn !== 'function') {

}
if (isFnRegex.test(fnToStr.call(fn))) {
if (isFnRegex(fnToStr(fn))) {
return true;
}
if (!hasToStringTag) {
var str = toStr.call(fn);
var str = toStr(fn);
return str === '[object GeneratorFunction]';

@@ -37,5 +43,8 @@ }

var generatorFunc = getGeneratorFunc();
GeneratorFunction = generatorFunc ? getProto(generatorFunc) : false;
GeneratorFunction = generatorFunc
// eslint-disable-next-line no-extra-parens
? /** @type {GeneratorFunctionConstructor} */ (getProto(generatorFunc))
: false;
}
return getProto(fn) === GeneratorFunction;
};
{
"name": "is-generator-function",
"version": "1.0.10",
"version": "1.1.0",
"description": "Determine if a function is a native generator function.",
"main": "index.js",
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublishOnly": "safe-publish-latest",

@@ -17,4 +18,5 @@ "prepublish": "not-in-publish || npm run prepublishOnly",

"test:uglified": "node test/uglified",
"posttest": "aud --production",
"lint": "eslint .",
"posttest": "npx npm@\">= 10.2\" audit --production",
"lint": "eslint --ext=js,mjs .",
"postlint": "tsc && attw -P",
"version": "auto-changelog && git add CHANGELOG.md",

@@ -45,14 +47,26 @@ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""

"dependencies": {
"has-tostringtag": "^1.0.0"
"call-bound": "^1.0.3",
"get-proto": "^1.0.0",
"has-tostringtag": "^1.0.2",
"safe-regex-test": "^1.1.0"
},
"devDependencies": {
"@ljharb/eslint-config": "^17.6.0",
"aud": "^1.1.5",
"auto-changelog": "^2.3.0",
"core-js": "^2.6.5 || ^3.16.0",
"eslint": "^7.32.0",
"@arethetypeswrong/cli": "^0.17.2",
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.3",
"@types/for-each": "^0.3.3",
"@types/make-generator-function": "^2.0.3",
"@types/tape": "^5.8.0",
"auto-changelog": "^2.5.0",
"core-js": "^2.6.5 || ^3.20.0",
"encoding": "^0.1.13",
"eslint": "=8.8.0",
"for-each": "^0.3.3",
"in-publish": "^2.0.1",
"make-generator-function": "^2.0.0",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"safe-publish-latest": "^1.1.4",
"tape": "^5.3.0",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0",
"typescript": "next",
"uglify-register": "^1.0.1"

@@ -88,3 +102,8 @@ },

"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
'use strict';
// @ts-ignore
require('core-js');
require('./');

@@ -6,12 +6,8 @@ 'use strict';

var test = require('tape');
var isGeneratorFunction = require('../index');
var generatorFuncs = require('make-generator-function')();
var hasToStringTag = require('has-tostringtag/shams')();
var forEach = require('for-each');
var forEach = function (arr, func) {
var i;
for (i = 0; i < arr.length; ++i) {
func(arr[i], i, arr);
}
};
var isGeneratorFunction = require('../index');

@@ -66,2 +62,3 @@ test('returns false for non-functions', function (t) {

var generatorFunc = generatorFuncs[0];
/** @type {{ toString(): unknown; valueOf(): unknown; [Symbol.toStringTag]?: unknown; }} */
var fakeGenFunction = {

@@ -68,0 +65,0 @@ toString: function () { return String(generatorFunc); },

'use strict';
// @ts-ignore
require('uglify-register/api').register({

@@ -4,0 +5,0 @@ exclude: [/\/node_modules\//, /\/test\//],

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.