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.
symbols-collection
Advanced tools
Changelog
2.0.1
Bug fixes:
Refactor:
Deps:
is-it-type
dependencyNo code:
Tests:
Dev:
.npmignore
with files
list in package.json
.editorconfig
confignpm-debug.log
from .gitignore
Readme
Create a collection of Symbols named with common namespace.
Create Symbols with a namespace in the Symbol descriptions. The descriptions are helpful in debugging.
const makeSymbols = require('symbols-collection');
const symbols = makeSymbols(
'my-module',
['FOO', 'BAR', 'QUX']
);
...is just a shortcut for:
const symbols = {
FOO: Symbol('my-module.FOO'),
BAR: Symbol('my-module.BAR'),
QUX: Symbol('my-module.QUX')
};
Providing a namespace is optional. If no namespace is provided, symbol descriptions are same as symbol names.
const symbols = makeSymbols( ['FOO', 'BAR'] );
symbols.FOO // => Symbol(FOO)
symbols.BAR // => Symbol(BAR)
Names must only contain upper case letters (A-Z
), digits (0-9
), _
or $
. They must be valid JS identifiers (i.e. not start with a digit).
You can cache all Symbols by passing a store
option. store
should be a plain object.
Symbols are saved in the store as store[namespace][name]
.
const store = {};
const symbols = makeSymbols( 'my-module', ['FOO'], { store } );
const { FOO } = symbols;
FOO // => Symbol(my-module.FOO)
store['my-module'].FOO === FOO // => true
// Somewhere else, use same store
const symbols2 = makeSymbols( 'my-module', ['FOO'], { store } );
symbols2.FOO === FOO // => true
The main use case is:
Without using a store, each version will export different Symbols (with the same name), which may cause bugs.
So you need to store the Symbols globally.
Symbol.for()
would work, but it makes the Symbols completely global. There's a risk of conflict with other code you don't control which might call Symbol.for()
with the same name.
The solution:
makeSymbols()
with the store
option.// Publish to NPM as do-stuff-symbols-store.
// Publish once and never update.
module.exports = {};
// Publish to NPM as do-stuff
const store = require('do-stuff-symbols-store');
const { FOO } = makeSymbols(
'do-stuff',
['FOO'],
{ store }
);
function doStuff() { /* ... */ }
doStuff.FOO = FOO;
module.exports = doStuff;
// User code
const doStuff = require('do-stuff');
doStuff.FOO // => Symbol(do-stuff.FOO)
doStuff.FOO
will always be the exact same Symbol, no matter what version of the 'do-stuff' module is imported.
This module follows semver. Breaking changes will only be made in major version updates.
All active NodeJS release lines are supported (v10+ at time of writing). After a release line of NodeJS reaches end of life according to Node's LTS schedule, support for that version of Node may be dropped at any time, and this will not be considered a breaking change. Dropping support for a Node version will be made in a minor version update (e.g. 1.2.0 to 1.3.0). If you are using a Node version which is approaching end of life, pin your dependency of this module to patch updates only using tilde (~
) e.g. ~1.2.3
to avoid breakages.
Use npm test
to run the tests. Use npm run cover
to check coverage.
See changelog.md
If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/symbols-collection/issues
Pull requests are very welcome. Please:
FAQs
Create a collection of Symbols with namespaced labels
The npm package symbols-collection receives a total of 35 weekly downloads. As such, symbols-collection popularity was classified as not popular.
We found that symbols-collection 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.