
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
ember-computed-enum
Advanced tools
ember-computed-enum
translates an field containing a "magic number" into
it's human-readable analogue, and provides named properties to easily check
for any given state.
ember install ember-computed-enum
The addon can be used in two different ways.
For full functionality, use the addon...
enumNameIsValue
properties)import { computedEnumMixin } from 'ember-computed-enum';
myEnumValues = ['foo', 'bar', 'baz'];
MyClassWithAnEnum = Ember.Object.extend(
computedEnumMixin('myEnum', 'enumValRaw', myEnumValues),
{
// ... your other properties
}
);
o = MyClassWithAnEnum.create({ enumValRaw: 0 });
o.get('enumValRaw'); // -> 0
o.get('myEnum'); // -> 'foo'
o.get('myEnumIsFoo'); // -> true
o.get('myEnumIsBar'); // -> false
o.get('myEnumIsBaz'); // -> false
In cases where the 'enumNameIsValue` properties aren't needed, the addon can also be used...
enumNameIsValue
properties)import { computedEnum } from 'ember-computed-enum';
myEnumValues = ['foo', 'bar', 'baz'];
MyClassWithAnEnum = Ember.Object.extend({
myEnum: computedEnum('enumValRaw', myEnumValues)
});
o = MyClassWithAnEnum.create({ enumValRaw: 0 });
o.get('enumValRaw'); // -> 0
o.get('myEnum'); // -> 'foo'
o.get('myEnumIsFoo'); // -> undefined
o.get('myEnumIsBar'); // -> undefined
o.get('myEnumIsBaz'); // -> undefined
The addon works with any Ember Objects, including ember-data models. To use with Ember models, store the raw value of the enum in one field:
// app/models/person.js
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
genderCode: DS.attr('number')
});
Then add a computed enum that references the raw value:
// app/models/person.js
import DS from 'ember-data';
import { computedEnumMixin } from 'ember-computed-enum';
export default DS.Model.extend(
computedEnumMixin('gender', 'genderCode', ['male', 'female', 'other']),
{
name: DS.attr('string'),
genderCode: DS.attr('number')
}
);
If you want to assign the raw value to a different fieldname than
that assigned by the API, you can create a simple Serializer. For
example, if our API returns a gender code in a field named gender
,
we could make Person.gender
contain the decoded value and store
the raw, coded version by creating a serializer like this:
app/serializers/person.js
import DS from 'ember-data';
export default DS.JSONAPISerializer.extend({
attrs: {
genderCode: 'gender' // map the API's "gender" field to the "genderCode" field on the model
}
});
By default, ember-computed-enum
assumes enum values are zero-indexed integers (0, 1, 2...),
but other values can be used by passing in an object mapping enum names to values.
For example, if "gender" were coded as 'm', 'f', and 'o', your model might look like:
// app/models/person.js
import DS from 'ember-data';
import { computedEnumMixin } from 'ember-computed-enum';
genderEnum = {'male': 'm', 'female', 'f', 'other': 'o'};
export default DS.Model.extend(
computedEnumMixin('gender', 'genderCode', genderEnum),
{
name: DS.attr('string'),
genderCode: DS.attr('number')
}
);
The rest of this README outlines the details of collaborating on this Ember addon.
git clone <repository-url>
this repositorycd ember-computed-enum
npm install
bower install
npm test
(Runs ember try:each
to test your addon against multiple Ember versions)ember test
ember test --server
ember build
For more information on using ember-cli, visit https://ember-cli.com/.
FAQs
Creates and manges Enums using Ember computed properties.
The npm package ember-computed-enum receives a total of 13 weekly downloads. As such, ember-computed-enum popularity was classified as not popular.
We found that ember-computed-enum 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
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.