# process-data-attr-as-func

> A plugin that takes the data attribute of HTML and executes a specific function.

Latest version **0.1.0** (published 2022-06-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install process-data-attr-as-func
pnpm add process-data-attr-as-func
yarn add process-data-attr-as-func
bun add process-data-attr-as-func
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-06-27 |
| First published | 2022-06-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 19.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | kamem |
| Maintainers | kamem |
| Keywords | data, attr, plugin |

## Links

- npm: https://www.npmjs.com/package/process-data-attr-as-func
- Repository: https://github.com/kamem/scroll-parallax-effect
- Homepage: https://github.com/kamem/scroll-parallax-effect#readme
- Issues: https://github.com/kamem/scroll-parallax-effect/issues
- npm.io page: https://npm.io/package/process-data-attr-as-func

## Dependencies (5)

- [jest](https://npm.io/package/jest.md) ^28.1.1
- [ts-jest](https://npm.io/package/ts-jest.md) ^28.0.5
- [@types/jest](https://npm.io/package/@types/jest.md) ^28.1.2
- [jest-environment-jsdom](https://npm.io/package/jest-environment-jsdom.md) ^28.1.1
- [scroll-parallax-effect](https://npm.io/package/scroll-parallax-effect.md) ^0.3.1

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2022-06-27

## README

# process-data-attr-as-func

HTMLのdata属性を取得して、特定の関数を実行するためのプラグイン。
同じプラグインで、複数オプションで使いたい場合にHTMLを修正するだけでプラグインに渡すオプションを変えることができます。

A plugin that takes the data attribute of HTML and executes a specific function.
If you want to use the same plugin with multiple options, you can simply modify the HTML to change the options passed to the plugin.

## Install

### npm 
```terminal
npm install process-data-attr-as-func
```

### yarn
```terminal
yarn add process-data-attr-as-func
```

## Example
* [es](http://github.develo.org/process-data-attr-as-func/docs/example/)
* [vanilla](http://github.develo.org/process-data-attr-as-func/docs/example/vanilla.html)

## Document

### HTML
```html
<ul class="menu">
  <li class="menu-item" data-color="red">menu1</li>
  <li class="menu-item" data-color="yellow">menu2</li>
  <li class="menu-item" data-color="pink">menu3</li>
  <li class="menu-item" data-color="blue">menu4</li>
</ul>
```

### Typescript 
```typescript
import { ProcessDataAttrAsFunc } from 'process-data-attr-as-func'

interface Test {
  color: string
}

const body = new ProcessDataAttrAsFunc<Test>(
  'body',
  (element, props: Partial<Test>) => {
    element.style.backgroundColor = props.color!
  }
)

const menu = new ProcessDataAttrAsFunc<Test>(
  '.menu-item',
  (element, props: Partial<Test>) => {
    element.style.backgroundColor = props.color!
  }
)
```
プラグイン実行で返ってくるdataは`Partial<Test>`となります。
※ HTMLタグのdataから取得するため、存在が担保できないため`Partial`にしています。

### Vanilla
#### html
```html
<script src="../js/process-data-attr-as-func.min.js"></script>
```

#### javascript
```javascript
const body = new ProcessDataAttrAsFunc(
  'body',
  (element, props) => {
    element.style.backgroundColor = props.color
  }
)

const menu = new ProcessDataAttrAsFunc(
  '.menu-item',
  (element, props) => {
    element.style.backgroundColor = props.color
  }
)
```

export interface ProcessDataAttrAsFuncOptions<T> {
  element: Ele
  plugin: PluginType<T>
  functions?: Functions
}

### Options

| Option Name | Description | Type |default
|:-----------|:------------|:------------|:------------|
| element      | タグ | HTMLElement string | -
| plugin  | 関数 | (element: HTMLElement, value: Partial<T>) => void | -
| functions | dataで取れた文字列がここのオブジェクトに存在していた場合、その関数をオプションとして渡します | { [key: string] : () => void } | {}
```typescript
export type Functions = { [key: string] : () => void }
export type PluginType<T> = (element: HTMLElement, value: Partial<T>) => void
export interface ProcessDataAttrAsFuncOptions<T> {
  element: HTMLElement
  plugin: PluginType<T>
  functions?: Functions
}
```

## Development
### dev
```
yarn dev
yarn serve
```

### build
```
npm run build
```

or

```
yarn build
```

---
_Source: https://npm.io/package/process-data-attr-as-func · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
