
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
deca-method-lister
Advanced tools
A utility to extract and list all methods from JavaScript objects, including inherited methods from the prototype chain
A lightweight utility to extract and list all methods from JavaScript objects, including inherited methods from the prototype chain. Now with CLI support for analyzing JavaScript files!
npm install deca-method-lister
const { getMethods } = require('deca-method-lister');
// Example with a simple object
const myObject = {
name: 'John',
age: 30,
greet() {
return `Hello, I'm ${this.name}`;
},
getAge() {
return this.age;
}
};
const methods = getMethods(myObject);
console.log(methods);
// Output: ['greet', 'getAge', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toString', 'valueOf', 'toLocaleString']
Analyze JavaScript files and generate method documentation:
# Analyze a JavaScript file
npx deca-method-lister myfile.js
# Specify output file (default: methods.js)
npx deca-method-lister myfile.js output.js
Example CLI Output:
$ npx deca-method-lister index.js
✅ Successfully analyzed index.js
📄 Found 1 methods
💾 Generated methods.js
📋 Methods found:
1. getMethods (line 27)
└─ Extracts and returns all method names from a JavaScript object, including inherited methods from the prototype chain.
Generated File Structure:
// Auto-generated method information for index.js
// Generated on 2024-01-15T10:30:00.000Z
const methods = [
{
"name": "getMethods",
"description": "Extracts and returns all method names from a JavaScript object, including inherited methods from the prototype chain.",
"parameters": [
{
"type": "Object",
"name": "obj",
"description": "The object to extract methods from"
}
],
"returnType": "string[]",
"file": "index.js",
"line": 27
}
];
module.exports = {
methods,
count: methods.length,
file: 'index.js',
generatedAt: '2024-01-15T10:30:00.000Z'
};
const { getMethods } = require('deca-method-lister');
// Array methods
const arr = [];
const arrayMethods = getMethods(arr);
console.log(arrayMethods);
// Output: ['push', 'pop', 'shift', 'unshift', 'slice', 'splice', 'concat', 'join', 'reverse', 'sort', 'filter', 'map', 'reduce', 'forEach', ...]
// String methods
const str = "hello";
const stringMethods = getMethods(str);
console.log(stringMethods);
// Output: ['charAt', 'charCodeAt', 'concat', 'indexOf', 'lastIndexOf', 'slice', 'substring', 'substr', 'toLowerCase', 'toUpperCase', ...]
// Date methods
const date = new Date();
const dateMethods = getMethods(date);
console.log(dateMethods);
// Output: ['getTime', 'getFullYear', 'getMonth', 'getDate', 'getHours', 'getMinutes', 'getSeconds', 'setTime', 'setFullYear', ...]
const { getMethods } = require('deca-method-lister');
class Animal {
constructor(name) {
this.name = name;
}
speak() {
return `${this.name} makes a sound`;
}
move() {
return `${this.name} moves`;
}
}
class Dog extends Animal {
constructor(name, breed) {
super(name);
this.breed = breed;
}
bark() {
return `${this.name} barks`;
}
fetch() {
return `${this.name} fetches the ball`;
}
}
const dog = new Dog('Buddy', 'Golden Retriever');
const dogMethods = getMethods(dog);
console.log(dogMethods);
// Output: ['bark', 'fetch', 'speak', 'move', 'constructor', 'hasOwnProperty', 'isPrototypeOf', ...]
const { getMethods } = require('deca-method-lister');
const myObject = {
customMethod1() { return 'one'; },
customMethod2() { return 'two'; }
};
const allMethods = getMethods(myObject);
const customMethods = allMethods.filter(method =>
!['constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toString', 'valueOf', 'toLocaleString'].includes(method)
);
console.log(customMethods);
// Output: ['customMethod1', 'customMethod2']
getMethods(obj)Returns an array of all method names (functions) available on the given object, including inherited methods from the prototype chain.
obj (Object): The object to extract methods fromArray<string>: An array of method namesconst { getMethods } = require('deca-method-lister');
const methods = getMethods(someObject);
console.log(methods); // ['method1', 'method2', 'inheritedMethod', ...]
The CLI tool analyzes JavaScript files and extracts:
function methodName() {}const methodName = () => {}methodName() {}methodName() {}async methodName() {}The CLI automatically extracts JSDoc comments and parses:
@param tags with types and descriptions@returns tags with return typesThe getMethods function traverses the entire prototype chain of the given object using Object.getPrototypeOf() and collects all property names using Object.getOwnPropertyNames(). It then filters the results to include only properties that are functions (methods).
This approach ensures that:
SetMIT
Tom Tarpey
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
A utility to extract and list all methods from JavaScript objects, including inherited methods from the prototype chain
We found that deca-method-lister demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.