---
title: Path
project: jComponent V20
version: 20.015
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v20/20-015/reference/path/
updated: 2026-11-18T13:58:14.460Z
---

# Path

> The properties and the methods of a parsed path.

A Path object holds a parsed path with its flags. It is available as `component.path` and `plugin.path`, and `new jComponent.Path(path)` creates one. The syntax of paths is explained in [Paths](../../guides/paths/) and [Flags and path modifiers](../../guides/flags/).

## API

### path

Type: `property`

The clean path without flags.

Returns: `String` The clean path without flags.

Example: Parse a path
```js
var path = new jComponent.Path('form.user.name @touched #countries');
console.log(path.path);
// logs: form.user.name
console.log(JSON.stringify(path.flags));
// logs: {"touched":1}
console.log(path.cl);
// logs: countries
```

### raw

Type: `property`

The path with its flags, without code lists.

Returns: `String` The path with its flags, without code lists.

### flags

Type: `property`

The flags of the path as an object.

Returns: `Object` The flags of the path as an object.

A flag without a value has the value `1`. The form `@key:value` keeps the value.

### split

Type: `property`

The path divided into its levels, from the first to the whole path.

Returns: `Array` The path divided into its levels, from the first to the whole path.

### cl

Type: `property`

The names of the code lists written with `#`, separated with a comma.

Returns: `String` The names of the code lists written with `#`, separated with a comma.

### cache

Type: `property`

The text written between `<` and `>`.

Returns: `String` The text written between `<` and `>`.

### ERROR

Type: `property`

Is `true` when the path contains the keyword `ERROR`.

Returns: `Boolean` Is `true` when the path contains the keyword `ERROR`.

### SYNC

Type: `property`

Is `true` when the path contains the keyword `SYNC`.

Returns: `Boolean` Is `true` when the path contains the keyword `SYNC`.

### toString()

Type: `method`

Returns the clean path.

Returns: `String` The path.

Example: Convert to a string
```js
var path = new jComponent.Path('form.name @touched');
console.log(path.toString());
// logs: form.name
```

### get(scope)

Type: `method`

Reads the value at the path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | The object that the path is resolved against, usually `window`. |

Returns: `Object` The value.

Example: Read and write in your own object
```js
var path = new jComponent.Path('user.name');
var scope = {};
path.set(scope, 'Anna');
console.log(JSON.stringify(scope), path.get(scope));
// logs: {"user":{"name":"Anna"}} Anna
```

### set(scope, value)

Type: `method`

Writes a value at the path, without notifying anything.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | The object that the path is resolved against, usually `window`. |
| `value` | `Object` | yes |  | The value to write. |

Missing parent objects are created.

### notify(scope, [flags])

Type: `method`

Notifies the components, watchers and binders bound to the path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | The object that the path is resolved against, usually `window`. |
| `flags` | `String` | no |  | Flags as a string such as `@touched`, or as an object such as `{ touched: 1 }`. |

Example: Notify the watchers
```js
var path = new jComponent.Path('common.count');
WATCH('common.count', (value, flags) => console.log(value, JSON.stringify(flags)));
path.set(window, 5);
path.notify(window, '@touched');
// logs: 5 {"touched":1}
```

### assign(path)

Type: `method`

Creates a path relative to this one.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The relative path. |

Returns: `Path` The new path.

The result depends on the first character of the argument:

| Argument | Result for `form.user` |
| --- | --- |
| `name` | `form.user.name` |
| `@touched` | `form.user` with the flag |
| `?suffix` | `form.usersuffix` |
| `*name` | `common.name` |
| `#name` | `DEF.cl.name` |
| `%name` | `DEF.tmp.name` |

Without an argument, the method returns the same object.

Example: Build relative paths
```js
var path = new jComponent.Path('form.user');
console.log(path.assign('name').path);
// logs: form.user.name
console.log(path.assign('*name').path);
// logs: common.name
```

### includes(path, [partially])

Type: `method`

Tells whether two paths lie on the same branch.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path to compare. |
| `partially` | `Boolean` | no | `false` | Compares the last level of the argument. |

Returns: `Boolean` The result of the comparison.

The result is `true` when one path is a parent of the other or both are the same. With `partially`, it is also `true` when a level of this path ends with the last level of the argument.

Example: Compare paths
```js
var path = new jComponent.Path('form.user');
console.log(path.includes('form'), path.includes('form.user.name'), path.includes('form.other'));
// logs: true true false
console.log(new jComponent.Path('form.user.name').includes('name', true));
// logs: true
```

### exec(callback)

Type: `method`

Emits the flags of the path, loads its code lists and calls a function.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | yes |  | The function to call. |

Each flag is emitted as the event `@flag name`, with the path as the argument.

Example: Run the flags of a path
```js
ON('@flag saved', path => console.log('flag', path));
new jComponent.Path('form.user @saved').exec(() => console.log('done'));
// logs: flag form.user
// logs: done
```

### find(scope, callback)

Type: `method`

Finds the ready components bound to the path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | The object that the path is resolved against, usually `window`. |
| `callback` | `Function` | yes |  | A function `(components)`. |

The flags `@visible`, `@touched`, `@modified`, `@required`, `@invalid`, `@disabled` and `@enabled` limit the result.

Example: Find components in a form
```html
<ui-component name="field" path="form.name"></ui-component>
<ui-component name="field" path="form.email"></ui-component>

<script>
COMPONENT('field', function(self) {});

new jComponent.Path('form').find(window, function(components) {
    console.log(components.map(m => m.path.toString()).join());
});
// logs: form.name,form.email
</script>
```
