1.0.2 • Published 7 years ago

sush-plugin-trim-id v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

sush-plugin-trim-id

NPM

standard-readme compliant npm

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