Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
chiles
Advanced tools
Readme
Wrapper around esprima to modify javascript documents.
Modify inline comments and add content before each comment.
const _ = require('lodash');
const chiles = require('../dist/chiles.js');
const src = `
//i1
function abc(a, b) {
//i2
}
//i3
`;
const doc = chiles(src);
console.log(doc.repr());
console.log(doc.toString());
const newNodes = [];
doc.walkPostOrder(n => {
if (n.type === 'Line') {
doc.update('\n', n.range[0], n.range[0], null);
newNodes.push(doc.insert(`// ADDED: ${n.value}`, n.range[0] - 1));
n.setSource(`// -> (${n.value})`);
}
});
console.log(doc.repr());
console.log(doc.toString());
_.each(newNodes, n => {
console.log([n.getSource()]);
});
output:
[0 - 41]: Document
[0 - 41]: Program
[1 - 5]: Line
[6 - 35]: FunctionDeclaration
[15 - 18]: Identifier
[19 - 20]: Identifier
[22 - 23]: Identifier
[25 - 35]: BlockStatement
[29 - 33]: Line
[36 - 40]: Line
//i1
function abc(a, b) {
//i2
}
//i3
[0 - 98]: Document
[0 - 98]: Program
[1 - 13]: _Unknown
[14 - 24]: Line
[25 - 73]: FunctionDeclaration
[34 - 37]: Identifier
[38 - 39]: Identifier
[41 - 42]: Identifier
[44 - 73]: BlockStatement
[48 - 60]: _Unknown
[61 - 71]: Line
[74 - 86]: _Unknown
[87 - 97]: Line
// ADDED: i1
// -> (i1)
function abc(a, b) {
// ADDED: i2
// -> (i2)
}
// ADDED: i3
// -> (i3)
[ '// ADDED: i1' ]
[ '// ADDED: i2' ]
[ '// ADDED: i3' ]
const chiles = require('chiles');
Parse the string source src
with esprima, returns a single Document
object which can
be used to modify the original source.
A document object has the following methods:
str(start, end)
: returns a substring from the source with the specified endpoints.
repr()
: Utility function displaying all the ranges and the node types for the document.
walkPostOrder(fn)
: Walks through the document and executes the function fn
on a node only
after all its children have been visited. The function fn
takes in paramters node
and level
.
insert(text, start, type = 'Unknown')
: Inserts the text text
at the index spefied by start
.
We may optionally specified the type of node that corresponds to the inserted text.
update(text, start, end, type = 'Unknown')
: Replace a substring from the source with the specified
text. Usually useful when modifying a piece of text that has not yet been claimed by a node.
WARNING: At the moment there is no checks to make sure that the range we are modifying does not belong to another node.
toString()
: Obtain the current document as a string.
Each node in a Document has the following properties:
_prev
:
_next
:
_child
:
_parent
:
_owner
:
setSource
:
getSource
:
With npm:
npm install chiles
FAQs
esprima wrapper to manipulate javascript files
The npm package chiles receives a total of 8 weekly downloads. As such, chiles popularity was classified as not popular.
We found that chiles demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.