Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
387 changes: 322 additions & 65 deletions docs/src/modules/is.md

Large diffs are not rendered by default.

83 changes: 64 additions & 19 deletions docs/src/modules/keyword.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,108 @@ kw.iskeyword("local")) --> true
kw.isidentifier("hello_world") --> true
```

## Dependencies
## Functions

Dependencies below are lazy-loaded 💤 on first access.
| Function | Description |
| ----------------------------------------------------- | ----------------------------------------------------------------------------------- |
| [`iskeyword(v)`](#fn-iskeyword) | Return `true` when `v` is a reserved Lua keyword. |
| [`isidentifier(v)`](#fn-isidentifier) | Return `true` when `v` is a valid non-keyword Lua identifier. |
| [`kwlist()`](#fn-kwlist) | Return Lua keywords as a [`mods.List`](https://luamod.github.io/mods/modules/list). |
| [`kwset()`](#fn-kwset) | Return Lua keywords as a [`mods.Set`](https://luamod.github.io/mods/modules/set). |
| [`normalize_identifier(s)`](#fn-normalize-identifier) | Normalize an input into a safe Lua identifier. |

- [`mods.Set`](https://luamod.github.io/mods/modules/set)
- [`mods.List`](https://luamod.github.io/mods/modules/list)
<a id="fn-iskeyword"></a>

## Functions
### `iskeyword(v)`

Return `true` when `v` is a reserved Lua keyword.

**Parameters**:

| Function | Description |
| ----------------------------------------------- | ----------------------------------------------------------------------------------- |
| [`iskeyword`](#iskeyword) | Return `true` when `s` is a reserved Lua keyword. |
| [`isidentifier`](#isidentifier) | Return `true` when `s` is a valid non-keyword Lua identifier. |
| [`kwlist`](#kwlist) | Return Lua keywords as a [`mods.List`](https://luamod.github.io/mods/modules/list). |
| [`kwset`](#kwset) | Return Lua keywords as a [`mods.Set`](https://luamod.github.io/mods/modules/set). |
| [`normalize_identifier`](#normalize-identifier) | Normalize an input into a safe Lua identifier. |
- `v` (`any`): Value to validate.

### `iskeyword`
**Return**:

Return `true` when `s` is a reserved Lua keyword.
- `ok` (`boolean`): Whether the check succeeds.

**Example**:

```lua
kw.iskeyword("function") --> true
kw.iskeyword("hello") --> false
```

### `isidentifier`
<a id="fn-isidentifier"></a>

### `isidentifier(v)`

Return `true` when `v` is a valid non-keyword Lua identifier.

Return `true` when `s` is a valid non-keyword Lua identifier.
**Parameters**:

- `v` (`any`): Value to validate.

**Return**:

- `ok` (`boolean`): Whether the check succeeds.

**Example**:

```lua
kw.isidentifier("hello_world") --> true
kw.isidentifier("local") --> false
```

### `kwlist`
<a id="fn-kwlist"></a>

### `kwlist()`

Return Lua keywords as a
[`mods.List`](https://luamod.github.io/mods/modules/list).

**Return**:

- `words` (`mods.List<string>`): List of Lua keywords.

**Example**:

```lua
kw.kwlist():contains("and") --> true
```

### `kwset`
<a id="fn-kwset"></a>

### `kwset()`

Return Lua keywords as a
[`mods.Set`](https://luamod.github.io/mods/modules/set).

**Return**:

- `words` (`mods.Set<string>`): Set of Lua keywords.

**Example**:

```lua
kw.kwlset():contains("and") --> true
```

### `normalize_identifier`
<a id="fn-normalize-identifier"></a>

### `normalize_identifier(s)`

Normalize an input into a safe Lua identifier.

**Parameters**:

- `s` (`string`): Input string.

**Return**:

- `ident` (`string`): Normalized Lua identifier.

**Example**:

```lua
kw.normalize_identifier(" 2 bad-name ") --> "_2_bad_name"
```
Loading