Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
codemaker
Advanced tools
The codemaker npm package is a utility for generating code programmatically. It provides a set of tools to create and manipulate code structures in a structured and maintainable way.
Code Generation
This feature allows you to generate code files programmatically. In this example, a new JavaScript file named 'example.js' is created with a single line of code that logs 'Hello, World!' to the console.
const { CodeMaker } = require('codemaker');
const code = new CodeMaker();
code.openFile('example.js');
code.line('console.log("Hello, World!");');
code.closeFile('example.js');
code.save('./output');
Code Structuring
This feature helps in structuring the code with proper indentation. In this example, a function named 'greet' is created with an indented console log statement inside it.
const { CodeMaker } = require('codemaker');
const code = new CodeMaker();
code.openFile('example.js');
code.indent(() => {
code.line('function greet() {');
code.indent(() => {
code.line('console.log("Hello, World!");');
});
code.line('}');
});
code.closeFile('example.js');
code.save('./output');
Code Formatting
This feature ensures that the generated code is properly formatted. In this example, multiple lines of code are added to 'example.js' to declare variables and log their sum.
const { CodeMaker } = require('codemaker');
const code = new CodeMaker();
code.openFile('example.js');
code.line('const x = 10;');
code.line('const y = 20;');
code.line('const sum = x + y;');
code.line('console.log(sum);');
code.closeFile('example.js');
code.save('./output');
Escodegen is a package for generating JavaScript code from an abstract syntax tree (AST). It is more focused on transforming and generating code from ASTs, whereas codemaker provides a more straightforward API for generating code directly.
Prettier is an opinionated code formatter that supports many languages. While it is primarily used for formatting existing code, it can be used in conjunction with code generation tools like codemaker to ensure the generated code is well-formatted.
Babel Generator is part of the Babel toolchain and is used to generate code from Babel's AST. It is similar to escodegen but is part of the larger Babel ecosystem, which includes tools for parsing, transforming, and generating JavaScript code.
Makes code. Well.. just a simple text writer with support for:
import { CodeMaker } from 'codemaker'
let maker = new CodeMaker();
maker.openFile('myfile.js');
maker.line('first line');
maker.openBlock('open');
maker.line('second line');
maker.closeBlock();
maker.indent('generic open [');
maker.line('boom');
maker.line('bam');
maker.unindent(']');
maker.closeFile('myfile.js');
let yourfileRelativePath = './relative/subdirs/are/also/supported/yourfile.js';
maker.openFile(yourfileRelativePath);
maker.line('this is your file speaking');
// change indentation and block formatting
maker.indentation = 10;
maker.openBlockFormatter = s => `(--- ${s} ---`;
maker.closeBlockFormatter = s => `--- ${s} ---)`;
maker.openBlock('block1');
maker.line('block1.line1');
maker.line('block1.line2');
maker.openBlock('block2');
maker.line('block2.line1');
maker.closeBlock('block2 (close)');
maker.line('block1.line3');
maker.closeBlock('block1 (close)');
// closeFile will ensure that you are closing the same file.
maker.closeFile(yourfileRelativePath);
// files can also be excluded by adding their path to exclude()
maker.openFile('rel/excluded.txt');
maker.line('this file will not be emitted in save()');
maker.closeFile('rel/excluded.txt');
// later in the day
maker.exclude('rel/excluded.txt');
// this is javascript - you can customize openBlock to whatever
maker.openBlock = function(s) {
this.line(s);
this.open('{');
};
maker.openFile('custom-blocks.cpp');
maker.openBlock('Block1()');
maker.line('L1');
maker.openBlock('Block2()');
maker.line('L2');
maker.closeBlock();
maker.closeBlock();
maker.closeFile('custom-blocks.cpp');
// returns a sorted list of output files
let files = await maker.save('/tmp/source-files');
first line
open {
second line
}
generic open [
boom
bam
]
this is your file speaking
(--- block1 ---
block1.line1
block1.line2
(--- block2 ---
block2.line1
--- block2 (close) ---)
block1.line3
--- block1 (close) ---)
Block1()
{
L1
Block2()
{
L2
}
}
Neat.
Also bundles a couple of case utils from sindresorhus:
maker.toCamelCase(s, ...)
maker.toPascalCase(s, ...)
maker.toSnakCase(s, sep = '_')
1.14.0 (2020-10-29)
jsii/superchain
Docker image no longer includes ruby
and gcc
. Users who need those should install them as part of their initialization script.UnsafeCast<T>()
method (#2192) (5e22e81), closes aws/aws-cdk#3284 aws/aws-cdk-rfcs#193dotnet: abundant nullability warnings in generated code (#2061) (01a2951)
go: fix generation of readonly and static properties (#2133) (57b7d56), closes #2093
jsii: annotation '@internal' causes missing type declarations downstream (#2172) (e80a4f7), closes #1947 #1830
jsii: TypeError: Cannot read property 'getJsDocTags' of undefined (#2163) (5d87101), closes #2098
jsii-diff: external structs returned from methods cannot be changed (#2070) (11e9389), closes #2064
pacmak/python: escape character escapes in python docs (#2138) (1578899), closes #2137
python: leftover jsii-kernel-* directories in TMPDIR (#2100) (c119994)
removes unused software from superchain to reduce image size (#2092) (fe2c597)
FAQs
A tiny utility for generating source code
The npm package codemaker receives a total of 191,957 weekly downloads. As such, codemaker popularity was classified as popular.
We found that codemaker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.