PARSE MODULE
Feature
javascript parse utility.
Demo
Installation,Download
Using
NPM
# install npm.
npm install --save-dev @yama-dev/js-parse-module
// import.
import PARSE_MODULE from 'js-parse-module';
Browser
<script src="./js-parse-module.js"></script>
<script>
let str = PARSE_MODULE.Str2AddLink('https://wwww.google.com');
console.log(str);
</script>
<script>
console.log(PARSE_MODULE.Str2AddLink('https://www.google.com'));
-> <a href="https://www.google.com" target="_blank">https://www.google.com</a>
console.log(PARSE_MODULE.Str2AddLink('https://www.google.com',''));
-> <a href="https://www.google.com" target="">https://www.google.com</a>
console.log(PARSE_MODULE.Str2AddLink('https://www.google.com','_blank'));
-> <a href="https://www.google.com" target="_blank">https://www.google.com</a>
console.log(PARSE_MODULE.Str2AddLink('https://www.google.com','_self'));
-> <a href="https://www.google.com" target="_self">https://www.google.com</a>
console.log(PARSE_MODULE.Str2AddLinkHashtag());
-> false
console.log(PARSE_MODULE.Str2AddLinkHashtag(''));
-> false
console.log(PARSE_MODULE.Str2AddLinkHashtag('#tags'));
-> <a href="https://twitter.com/search?q=%23tags" target="_blank">#tags</a>
console.log(PARSE_MODULE.Str2AddLinkHashtag('#tags','_self'));
-> <a href="https://twitter.com/search?q=%23tags" target="_self">#tags</a>
console.log(PARSE_MODULE.Str2DateFormat());
-> false
console.log(PARSE_MODULE.Str2DateFormat('2018.6.9'));
-> 2018-06-09
console.log(PARSE_MODULE.Str2DateFormat('2018/6/9'));
-> 2018-06-09
console.log(PARSE_MODULE.Str2DateFormat('2018-6-9'));
-> 2018-06-09
console.log(PARSE_MODULE.Str2DateFormat('2018.06.09'));
-> 2018-06-09
console.log(PARSE_MODULE.Str2DateFormat('2018/06/09'));
-> 2018-06-09
console.log(PARSE_MODULE.Str2DateFormat('2018年6月9日'));
-> 2018-06-09
console.log(PARSE_MODULE.Str2DateFormat('2018-06-09'));
-> 2018-06-09
console.log(PARSE_MODULE.Str2Mustache());
-> false
console.log(PARSE_MODULE.Str2Mustache('test {{ str_test }} text {{ str_empty }} sample', {str_test: '123456789'}, true));
-> test 123456789 text sample
console.log(PARSE_MODULE.Str2Mustache('test {{ str_test }} text {{ str_empty }} sample', {str_test: '123456789'}, false));
-> test 123456789 text {{ str_empty }} sample
console.log(PARSE_MODULE.Str2zeroPadding());
-> false
console.log(PARSE_MODULE.Str2zeroPadding(123));
-> 123
console.log(PARSE_MODULE.Str2zeroPadding(123,10));
-> 0000000123
console.log(PARSE_MODULE.Str2zeroPadding(123456789,10));
-> 0123456789
console.log(PARSE_MODULE.Str2zeroPadding('yama-dev',12,'@'));
-> @@@@yama-dev
</script>
API
Str2AddLink
Str2AddLink(str, target);
Parameter | Type | Default | Description |
---|---|---|---|
str | string | - ※省略不可 | 文字列にhtmlのリンクが付与されます。 |
target | string | '_blank ' | リンクのtarget属性を指定します。 |
Str2AddLinkHashtag
Str2AddLinkHashtag(str, target);
Parameter | Type | Default | Description |
---|---|---|---|
str | string | - ※省略不可 | 文字列(ハッシュタグ)にhtmlのリンクが付与されます。 |
target | string | '_blank' | リンクのtarget属性を指定します。 |
Str2DateFormat
Str2DateFormat(str);
Parameter | Type | Default | Description |
---|---|---|---|
str | string | - ※省略不可 | 文字列(日付)をyyyy-mm-dd の形に変換します。 |
1
Str2Mustache
Str2Mustache(str, obj, flg);
Parameter | Type | Default | Description |
---|---|---|---|
str | string | - ※省略不可 | ムスタッシュ記法で記述された文字列を変換します。 |
obj | object | - ※省略不可 | 置き換える文字列をオブジェクト形式で指定します。 |
flg | boolean | true | 該当しないセパレータを除去するか。 |
Str2zeroPadding
Str2zeroPadding(str, length, padstr);
Parameter | Type | Default | Description |
---|---|---|---|
str | string | - ※省略不可 | 文字列(ハッシュタグ)にhtmlのリンクが付与されます。 |
length | number | - ※省略不可 | 出力する桁数を指定します。 |
padstr | string | '0' | パディングで追加する文字列を変更します。 |
Dependencies
none
For Developer
Contribution
- Fork it ( https://github.com/yama-dev/js-parse-module/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
Develop
at Development
Install node modules.
$ npm install
Run npm script 'develop'
$ npm run develop
Run npm script 'production'
$ npm run production