
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
hash-accessor
Advanced tools
Defines accessors to map class properties to a hash / object.
Creates getter and setter for given properties to map against a given hash.
You can use HashAccessor when using data objects (like from an API) within classes without the hassle of synchronizing classes' properties with data hashes.
You can define a mapping for each property in each class that is automatically applied every time you access the decorated properties.
@DeclareHash({
setter: (instance: User, key: string, value: any) => {
instance.data[key] = value;
},
getter: (instance: User, key: string) => {
return instance.data[key];
}
})
class User {
public data: {[key: string]: any};
@Accessor() public id: number;
@Accessor('full_name') public fullName: string;
@Accessor('email_address') public email: string;
public constructor(data?: {[key: string]: any}) {
this.data = data;
}
}
let user1: User = new User({
id: 1,
full_name: 'John Smith',
email_address: 'john@conclurer.com'
});
console.log(user1.email); // => 'john@conclurer.com'
user1.fullName = 'The Doctor';
console.log(user1.data['full_name']); // => 'The Doctor'
@DeclareHash()
to decorate an object and define setters and getters for the properties hash@Accessor()
for each property withing the decorated object to store in the object's hash. You can also supply a custom key for each @Accessor()
to synchronize the property with.@Accessor() protected prop1: any; // will be linked with key 'prop1'
@Accessor('otherKey') protected prop2: any; // will be linked with key 'otherKey'
Run
npm install --save hash-accessor
FAQs
Typescript Hash Accessor Decorator
We found that hash-accessor 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
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.