Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
vanilla-autokana
Advanced tools
フォームのフィールドに文字を入力すると、別のフィールドにかなを自動入力するライブラリです。
npm i vanilla-autokana # or yarn add vanilla-autokana
このリポジトリの dist/autokana.js
をダウンロードし、scriptタグで読み込んでください。
AutoKana.bind()
メソッドの第1引数にふりがな入力元のinput要素、第2引数にふりがな出力先のinput要素のidを指定しますdefer
属性の追加を推奨します<input name="name" id="name">
<input name="furigana" id="furigana">
<script src="autokana.js" defer></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
AutoKana.bind("#name", "#furigana");
// ↓ふりがなをカタカナで入力したい場合
// AutoKana.bind("#name", "#furigana", { katakana: true });
});
</script>
ESModulesとしてimportすることができます。
import * as AutoKana from 'vanilla-autokana';
AutoKana.bind('#name', '#furigana');
v-model
を使用している場合、input要素のvalue属性への値のセットは動作しません。
↓のように、 getFurigana
メソッドを使ってふりがなを取り出し、リアクティブプロパティにセットしてください。
<template>
<div id="app">
<div>
<label for="name">名前</label>
<input name="name" id="name" v-model="name" @input="handleNameInput">
</div>
<div>
<label for="furigana">ふりがな</label>
<input name="furigana" id="furigana" v-model="furigana">
</div>
<h2>入力内容の確認</h2>
<p>名前: {{ name }}</p>
<p>ふりがな: {{ furigana }}</p>
</div>
</template>
<script>
import * as AutoKana from 'vanilla-autokana';
let autokana;
export default {
name: 'App',
data() {
return {
name: '',
furigana: '',
}
},
mounted() {
autokana = AutoKana.bind('#name', '#furigana');
},
methods: {
handleNameInput() {
this.furigana = autokana.getFurigana();
}
}
}
</script>
Vue.jsと同様の対応が必要です。
import React, { Component } from 'react';
import * as AutoKana from 'vanilla-autokana';
let autokana;
class App extends Component {
constructor() {
super();
this.state = {
name: '',
furigana: '',
};
this.handleNameInput = this.handleNameInput.bind(this);
}
componentDidMount() {
autokana = AutoKana.bind('#name', '#furigana');
}
handleNameInput(ev) {
this.setState({
name: ev.target.value,
furigana: autokana.getFurigana(),
});
}
render() {
return (
<div className="App">
<div>
<label htmlFor="name">名前</label>
<input name="name" id="name" value={this.state.name} onInput={this.handleNameInput} />
</div>
<div>
<label htmlFor="furigana">ふりがな</label>
<input name="furigana" id="furigana" value={this.state.furigana} />
</div>
<h2>入力内容の確認</h2>
<p>名前: { this.state.name }</p>
<p>ふりがな: { this.state.furigana }</p>
</div>
);
}
}
export default App;
MIT
このライブラリの設計・実装は jquery-autokana(https://github.com/harisenbon/autokana) に大きく影響を受けています。
FAQs
A JavaScript library to complete furigana automatically.
The npm package vanilla-autokana receives a total of 10,498 weekly downloads. As such, vanilla-autokana popularity was classified as popular.
We found that vanilla-autokana demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.