sush-plugin-trim-id
v1.0.2
Published
SUSH Plugin for trimming head or tail from ID
Downloads
1
Maintainers
Readme
sush-plugin-trim-id
Trim head or tail from ID
Table of Contents
Install
For HTML
Insert script tags in your HTML.
<script src="https://unpkg.com/sush"></script>
<script src="https://unpkg.com/sush-plugin-trim-id"></script>
<!-- Add script tags of SUSH Plugins -->
Via Node.js
npm install --save sush sush-plugin-trim-id [...SUSH_PLUGINS]
Usage
Via HTML
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/sush"></script>
<script src="https://unpkg.com/sush-plugin-trim-id"></script>
<script>
console.log(location.hash); // `#/example.view`
var sush = new SUSH();
sush.flow([
({ id, store }) => {
console.log(id); // `/example.view`
return { id, store };
},
SUSH.$trimId({ head: 1, tail: 5 })
])
.then(({ id, store }) => {
console.log(id); // `example`
})
.catch((err) => {
console.error(err.stack || err);
});
</script>
</head>
</html>
Via Node.js (e.g. Browserify, Webpack)
import SUSH from 'sush';
import trimId from 'sush-plugin-trim-id';
console.log(location.hash); // `#/example.view``
const sush = new SUSH();
sush.flow([
({ id, store }) => {
console.log(id); // `/example.view`
return { id, store };
},
trimId({ head: 1, tail: 5 })
])
.then(({ id, store }) => {
console.log(id); // `example`
})
.catch((err) => {
console.error(err.stack || err);
});
Contribute
PRs accepted.
License
MIT © 3846masa