
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
coerce-property
Advanced tools
Utility decorator functions for coercing Angular component @Inputs into specific types
Utility decorator functions for coercing Angular component @Inputs into specific types.
Used by Angular CDK coercions.
Support Angular >=15.
# Do not forget to check if Angular CDK is installed
npm i -S @angular/cdk
# And install this package
npm i -S coerce-property
@coerce - decorator factory
@coerceBoolean- coerces a data-bound value (typically a string) to a boolean
For example:
<app-component disabled></app-component>
@Input()
@coerceBoolean
disabled: boolean; // true
@coerceArray- wraps the provided value in an array, unless the provided value is an array
For example:
<app-component items="item"></app-component>
@Input()
@coerceArray
items: string[]; // ['item']
@coercePixel - coerces a value to a CSS pixel value
For example:
<app-component [width]="200"></app-component>
@Input()
@coercePixel
width: string; // '200px'
@coerceElement - coerces an ElementRef or an Element into an element
@coerceNumber - coerces a data-bound value (typically a string) to a number
For example:
<app-component age="19"></app-component>
@Input()
@coerceNumber
age: number; // 19
import { Component, Input } from "@angular/core";
import { coerceBoolean } from "coerce-property";
@Component({
selector: "app-component",
template: ``,
})
export class SampleComponent {
@Input()
@coerceBoolean
disabled: boolean;
}
You can use:
<app-sample [disabled]="true"></app-sample>
and
<app-sample disabled></app-sample>
import { Component, Input } from "@angular/core";
import { coerceBooleanProperty } from "@angular/cdk/coercion";
@Component({
selector: "app-component",
template: ``,
})
export class SampleComponent {
private _dsiabled: boolean;
@Input()
get disabled() {
return this._dsiabled;
}
set disabled(disabled) {
this._disabled = coerceBooleanProperty(disabled);
}
}
// @angular/cdk/coercion/boolean-property.ts
export function coerceBooleanProperty(value: any): boolean {
return value != null && `${value}` !== "false";
}
FAQs
Utility decorator functions for coercing Angular component @Inputs into specific types
The npm package coerce-property receives a total of 347 weekly downloads. As such, coerce-property popularity was classified as not popular.
We found that coerce-property 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.