Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
js-accessor
Advanced tools
Readme
Provides accessors like get
, set
, assertGet
, clone
, and toObject
for a JS object.
For npm
npm install js-accessor
For yarn
yarn add js-accessor
import {construct} from 'js-accessor';
interface DataType {
resourceId: string;
resourceType: string;
}
const data = construct<DataType>();
const resourceId = data
.setResourceId('id')
.setResourceType('data')
.clone()
.getResourceId();
construct(target, options)
Provides accessors for a target object, see below for accessors provided. Accessors will not be provided if a property with the accessor name already exists, allowing you to specify custom handling for certain properties. E.g. target.getField
will not use the accessor flow if getField
already exists in target. A known downside is set accessors, where you want to chain setters but can't. If this is a bummer, you can create a PR to address the issue or create an issue and I can look into it.
target
- Optional, target object for accessor functions.options.getter(target, field, originalField, params)
- Optional, Function for what a field's value.
target
- Target object.field
- Field whose value is to be returned. It is data
in getData
.originalField
- Field with accessor prefix. It is getData
in getData
.params
- Array of arguments passed to the accessor function. It is ["some param"]
in getData("some param")
.unknown
- field value.options.setter(target, field, value)
- Optional, Function for customizing what a field name is resolved to.
target
- Target object.field
- Field whose value is to be set. It is data
in setData
.originalField
- Field with accessor prefix. It is setData
in setData
.params
- Array of arguments passed to the accessor function. It is ["value", "some param"]
in setData("value", "some param")
.void
options.cloneResolver(target)
- Optional, Function for customizing what a field name is resolved to.
target
- Target object.params
- Array of arguments passed to the accessor function. It is ["some param"]
in clone("some param")
.object & WithAccessor<object>
- Should return target object cloned with accessors.options.toObjectResolver(target)
- Optional, Function for customizing what a field name is resolved to.
target
- Target object.params
- Array of arguments passed to the accessor function. It is ["some param"]
in toObject("some param")
.object
- Should return cloned target object.An object with accessor function described below.
get
- Getter function that retrieves the property indexed by the camel-cased name followed by get
. For example, getResourceId()
will return resourceId
.set
- Setter function for storing the property indexed by the camel-cased name followed by set
. For example, setResourceId("id")
will set resourceId
to id
, and setResourceId(undefined)
will set it to undefined
.assertGet
- Getter function that retrieves and asserts the property indexed by the camel-cased name followed by assertGet
. For example, assertGetResourceId()
will return resourceId
or throw an error if there is no resourceId
.clone
- Clone function that returns a copy of the data stored in an accessor's target, with accessor functions targeting the new copied target.toObject
- Copy function that returns a JS object copy of the accessor's target.FAQs
Provides accessors like get, set, assertGet, clone, and toObject for a JS object
We found that js-accessor demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).