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.
esrefactor
Advanced tools
Readme
esrefactor (BSD licensed) is a little helper library for ECMAScript refactoring.
With Node.js:
npm install esrefactor
In a browser, include first all the dependents:
<!-- esrefactor depends on these libraries -->
<script src="esprima.js"></src>
<script src="estraverse.js"></src>
<script src="escope.js"></src>
<script src="esrefactor.js"></src>
Before using the API, a context needs to be created:
var ctx = new esrefactor.Context(code);
where code
is the source code.
An identifier, whether it is a variable, a function name, or a function
parameter, can be identified using identify()
. Example:
var ctx = new esrefactor.Context('var x = 42; y = x * 2; z = x / 2');
var id = ctx.identify(4);
The only argument to identify
is the zero-based position index.
The return object has 3 (three) properties:
identifier
: the syntax node associated with the positiondeclaration
: the declaration syntax node for the identifierreferences
: an array of all identical referencesIf there is no declaration for the identifier (e.g. x = 42
, global
leak), then declaration
will be null.
The resolution of the declaration syntax node and the references array take into account the identifier scope as defined in the official ECMAScript 5.1 Specification (ECMA-262).
Note that if there is no identifier in the given position index,
identify()
will return undefined.
An identifier can be renamed using rename()
. All other identical references
associated with that identifier will be renamed as well, again taking into
account the proper identifier scope. Renaming works for variable declaration,
function name, and function parameter.
For rename()
to work, it needs to have the identification result
(via identify
) and the new name for the identifier.
var ctx = new esrefactor.Context('var x; x = 42');
var id = ctx.identify(4);
var code = ctx.rename(id, 'answer');
In the above example, code
is var answer; answer = 42
.
FAQs
ECMAScript refactoring helper
The npm package esrefactor receives a total of 9,625 weekly downloads. As such, esrefactor popularity was classified as popular.
We found that esrefactor 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.