Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
exist-utils
Advanced tools
This package is a collection of util functions that emulate CoffeeScript existence operator. While waiting that some of them are integrated in the next version of JavaScript, you can use this package while porting from CoffeeScript, etc.
npm install exist-utils
You can then ExistUtils = require('exist-utils')
or import * as ExistUtils from 'exist-utils'
.
Use the minified UMD build in the dist
folder: here.
It exports a global window.ExistUtils
when imported as a <script>
tag.
Each function as a full name (i.e. exists
) and a shorthand (i.e. ex
), both are specified in the title of their description.
You can check the equivalence with CoffeeScript operators in the following section.
exists
(ex
)Example:
if (!exists(arg)) {
error('missing arg');
}
This is the equivalent to CoffeeScript val?
, it checks if a value "exists" (is neither null
nor undefined
).
existsChained
(exc
)Example:
if (!existsChained(arg, 'callback')) {
error('no callback specified');
}
This is the equivalent to CoffeeScript obj?.prop?
, it checks if a whole chain "exists".
existsChainedValue
(excv
)Example:
const callback = existsChainedValue(arg, 'callback');
if (!exists(callback)) {
error('no callback specified');
return;
}
callback();
This is the equivalent to CoffeeScript obj?.prop
, it checks if a whole chain "exists" and returns the final value.
elvis
(el
)Example:
val = elvis(arg, 42);
This is the equivalent to CoffeeScript val ? default
and a safer version to val || default
.
It returns the second value if the first one doesn't "exist".
callsIfExist
(fnex
)Example:
callsIfExist(func, 1, 2);
This is the equivalent to CoffeeScript func?(1, 2)
, it checks the existence of the function and calls it with the provided arguments.
callsIfExistObj
(fnexo
)Example:
callsIfExistObj(obj, 'func', 1, 2);
This is the equivalent to CoffeeScript obj?.func?(1, 2)
, it checks the existence of the function and calls it with the provided arguments while providing the right value for this
.
CoffeeScript | exist-utils | exist-utils shorthand |
---|---|---|
val? | exists(val) | ex(val) |
obj?.prop? | existsChained(obj, 'prop') | exc(obj, 'prop') |
obj?.prop | existsChainedValue(obj, 'prop') | excv(obj, 'prop') |
val = arg ? 3 | val = elvis(arg, 3) | val = el(arg, 3) |
func?(a, b) | callsIfExist(func, a, b) | fnex(func, a, b) |
obj.func?(a, b) | callsIfExistObj(obj, func, a, b) | fnexo(obj, func, a, b) |
MIT, Copyright (c) 2017-2020 Louis Brunner
FAQs
Utility functions that emulate CoffeeScript existence operator
The npm package exist-utils receives a total of 1 weekly downloads. As such, exist-utils popularity was classified as not popular.
We found that exist-utils 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.