2022-09-29 19:01:10 +02:00
|
|
|
---
|
|
|
|
title: Attributes.asPropsIfPrefixIs()
|
|
|
|
---
|
|
|
|
|
|
|
|
The `Attributes.asPropsIfPrefixIs()` method will return attribute values as a
|
2022-12-14 12:52:37 -08:00
|
|
|
props object (a plain JavaScript object) but only for those keys who start with
|
2022-09-29 19:01:10 +02:00
|
|
|
`prefix`.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
|
|
|
```js
|
|
|
|
Object attributes.asPropsIfPrefixIs(string prefix)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```js
|
|
|
|
const attr = new Attributes()
|
|
|
|
.add('class', 'various')
|
|
|
|
.add('stroke', 'red')
|
|
|
|
.add('stroke-width', 2)
|
|
|
|
|
|
|
|
const props = attr.asPropsIfPrefixIs('stroke')
|
|
|
|
/* Props holds:
|
|
|
|
{
|
|
|
|
stroke: 'red',
|
|
|
|
stroke-width: 2
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
```
|