@igor.dvlpr/rawelement
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "@igor.dvlpr/rawelement", | ||
"version": "1.0.1", | ||
"description": "🐯 A wrapper-utility that lets you manipulate HTML elements, their attributes and innerHTML as strings, on the go and then render the modified HTML. Very useful in SSG projects. 💤", | ||
"version": "1.1.0", | ||
"description": "🐯 A utility that lets you manipulate HTML elements, their attributes and innerHTML as strings, on the go and then render the modified HTML. Very useful in SSG projects. 💤", | ||
"sideEffects": false, | ||
@@ -6,0 +6,0 @@ "engines": { |
112
README.md
@@ -1,2 +0,2 @@ | ||
<h1 align="center"><RawElement /></h1> | ||
<h1 align="center"><RawElement /></h1> | ||
@@ -6,5 +6,7 @@ <br> | ||
<div align="center"> | ||
🐯 A wrapper-utility that lets you manipulate HTML elements, their attributes | ||
🐯 A utility that lets you manipulate HTML elements, their attributes and | ||
<br> | ||
and innerHTML as strings, on the go and then render the modified HTML. Very useful in SSG projects. 💤 | ||
innerHTML as strings, on the go and then render the modified HTML. | ||
<br> | ||
<em>Very <strong>useful</strong> in SSG projects.</em> 💤 | ||
</div> | ||
@@ -46,2 +48,12 @@ | ||
- [API](#-api) | ||
- [`constructor()`](#rawelementoptions-irawelementoptions) | ||
- [`IRawElementOptions`](#irawelementoptions) | ||
- [`data`](#data-string) | ||
- [`tag`](#tag-string) | ||
- [`format`](#format-boolean) | ||
- [`wrapper`](#wrapper) | ||
- [`source`](#source) | ||
- [`hasAttribute()`](#hasattributename-string-boolean) | ||
- [`setAttribute()`](#setattributename-string-value-string--null-boolean) | ||
- [`removeAttribute()`](#removeattributename-string-boolean) | ||
- [Examples](#-examples) | ||
@@ -64,10 +76,2 @@ - [Changelog](#-changelog) | ||
or | ||
```shell | ||
npm i -D "@igor.dvlpr/rawelement" | ||
``` | ||
depending on the use case. | ||
<br> | ||
@@ -81,3 +85,3 @@ | ||
If no options are specified or the required `tag` and `data` properties are not passed, it will throw an error. | ||
If no options are specified or the required `data` property is not passed, it will throw an error. | ||
@@ -92,4 +96,4 @@ <br> | ||
interface IRawElementOptions { | ||
tag: keyof HTMLElementTagNameMap // = string | ||
data: string | ||
tag?: keyof HTMLElementTagNameMap // = string | ||
format?: boolean | ||
@@ -99,15 +103,30 @@ } | ||
`tag` - the wrapper HTML tag for the element that will contain the text content and optional attributes set by the [`setAttribute()`](#setattributename-string-value-string--null-boolean) method. | ||
#### `data: string` | ||
`data` - the actual HTML element to process, as a `String`. | ||
**`Required`**, the actual HTML element/data to process, as a `String`. | ||
The provided HTML element **MUST** have a matching start and an end tag that correspond to the `tag` property, otherwise an error is thrown. | ||
Data will be normalized, i.e. CRLF (`\r\n`) replaced with LF (`\n`). | ||
`format` - an optional property, whether to format the text content inside of the wrapper element. | ||
<br> | ||
#### `tag?: string` | ||
**`Optional`**, a wrapper HTML tag for the element that will contain the text content and optional attributes set by the [`setAttribute()`](#setattributename-string-value-string--null-boolean) method. | ||
The provided HTML element **MUST** have a matching start and an end tag that correspond to the value of the `tag` property, otherwise an error is thrown. | ||
<br> | ||
> [!NOTE] | ||
> [`setAttribute`](#setattributename-string-value-string--null-boolean) only works when the `tag` property is defined. | ||
> | ||
<br> | ||
#### `format?: boolean` | ||
**`Optional`**, indicates whether to format the text content inside of the element. | ||
<br> | ||
> [!TIP] | ||
@@ -121,7 +140,7 @@ > It is **highly** recommended to leave the property `format` to its default value of `true` otherwise the `source` property of an instance of `RawElement` might contain a lot of leading whitespace. | ||
The whole wrapper element made of: | ||
- a start tag, | ||
- attributes (if present), | ||
Gets the whole wrapper element made of: | ||
- a start tag (if [`tag`](#tag-string) was set), | ||
- attributes (if [`tag`](#tag-string) was set), | ||
- text content, | ||
- an end tag. | ||
- an end tag (if [`tag`](#tag-string) was set). | ||
@@ -132,3 +151,3 @@ --- | ||
The text content of the wrapper element. | ||
Gets the text content of the element. | ||
@@ -143,2 +162,18 @@ <br> | ||
### `hasAttribute(name: string): boolean` | ||
Checks whether the wrapper element has an attribute. | ||
<br> | ||
> [!CAUTION] | ||
> If the wrapper element is not set, i.e. [`tag`](#tag-string) is not defined, attributes cannot be used and this method will throw an Error. | ||
> | ||
<br> | ||
Returns a `Boolean` indicating whether the provided attribute exists. | ||
--- | ||
### `setAttribute(name: string, value: string | null): boolean` | ||
@@ -148,8 +183,35 @@ | ||
To remove an attribute, pass the `value` of `null`. | ||
<br> | ||
Returns a `Boolean` whether the action succeeded. | ||
> [!CAUTION] | ||
> If the wrapper element is not set, i.e. [`tag`](#tag-string) is not defined, attributes cannot be used and this method will throw an Error. | ||
> | ||
<br> | ||
Passing the `value` of `null` removes the attribute (see [`removeAttribute`](#removeattributename-string-boolean)) as well. | ||
Returns a `Boolean` indicating whether the action succeeded. | ||
--- | ||
### `removeAttribute(name: string): boolean` | ||
Removes an attribute and its value from the wrapper element. | ||
<br> | ||
> [!CAUTION] | ||
> If the wrapper element is not set, i.e. [`tag`](#tag-string) is not defined, attributes cannot be used and this method will throw an Error. | ||
> | ||
<br> | ||
Returns a `Boolean` with the value of: | ||
- `true` - if the attribute was found and removed, | ||
- `false` - if the attribute does not exist or there was an error in removing it. | ||
--- | ||
## ✨ Examples | ||
@@ -156,0 +218,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19957
215
299