# Utils

Parse data-attribute strings into typed values.

Source: https://www.zazz.sh/api/javascript/utils/

`base/utils.js` is the parser the kit's own scripts use for `data-<name>-*` configuration. Use it in your elements so your attributes behave exactly like the kit's.

```js
import { Utils } from "@zazz-ui/core/base/utils.js";
```

## parseValue

Converts an attribute string to a boolean, number, JSON array or object, or leaves it a string:

```js
Utils.parseValue("true"); // true
Utils.parseValue("42"); // 42
Utils.parseValue("[1,2,3]"); // [1, 2, 3]
Utils.parseValue("hello"); // "hello"
```

## parseDataAttributes

Collects every attribute under a prefix, camel-cases the names, and parses the values:

```js
// <ui-carousel data-carousel-loop="true" data-carousel-start-snap="2">
Utils.parseDataAttributes(element, "data-carousel-");
// { loop: true, startSnap: 2 }
```

The result is untyped; narrow it yourself when you need a typed shape.
