alpine-magic-helpers - npm explorer
`
You may also pass a third argument to change the string that will be appended to the end:
`html
x-data="{ characters: 50, string: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'}"
x-text="$truncate(string, characters, ' (...)')">


`
Demo

Optionally pass in options

By default, $truncate will return take characters as a parameter. Instead you can pass in an object and trim by words. You may also update the ellipsis.

Example:

`html
x-data="{ count: 5, string: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'}"
x-text="$truncate(string, { words: words, ellipsis: ' ...read more' })"
@click="count = 0">


`
Demo (same as above)
> Behind the scenes, for words, this uses
sentence.split(" ").splice(0, words).join(" ") which does not define a word in all languages.

---

$3


Example:
`html




`
Demo

The $undo helper actually involves three helpers in one. First, add the $track() helper to the x-init directive to start tracking the component state. Next, add a button to $undo() changes as needed. And finally, you can access whether changes have occurred by using $history.length.

Optionally pass in options

By default, $undo will track all properties. Optionally you may limit the properties by passing in a string with the property name, or an array of property names.

Example:

`html






`
> Use
$track(['prop1', 'prop2']) to track multiple properties

Demo

---

$3


Example:
`html




``

> :warning: Only use on trusted content. :warning:
>
> Dynamically rendering HTML from third parties can easily lead to XSS vulnerabilities.

Demo

---

License

Copyright (c) 2020 Alpine Collective

Licensed under the MIT license, see LICENSE.md for details.