0.2.1 • Published 5 years ago

@yama-dev/js-parse-module v0.2.1

Weekly downloads
32
License
MIT
Repository
github
Last release
5 years ago

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);

ParameterTypeDefaultDescription
strstring- ※省略不可文字列にhtmlのリンクが付与されます。
targetstring'_blank 'リンクのtarget属性を指定します。

Str2AddLinkHashtag

Str2AddLinkHashtag(str, target);

ParameterTypeDefaultDescription
strstring- ※省略不可文字列(ハッシュタグ)にhtmlのリンクが付与されます。
targetstring'_blank'リンクのtarget属性を指定します。

Str2DateFormat

Str2DateFormat(str);

ParameterTypeDefaultDescription
strstring- ※省略不可文字列(日付)をyyyy-mm-ddの形に変換します。

1

Str2Mustache

Str2Mustache(str, obj, flg);

ParameterTypeDefaultDescription
strstring- ※省略不可ムスタッシュ記法で記述された文字列を変換します。
objobject- ※省略不可置き換える文字列をオブジェクト形式で指定します。
flgbooleantrue該当しないセパレータを除去するか。

Str2zeroPadding

Str2zeroPadding(str, length, padstr);

ParameterTypeDefaultDescription
strstring- ※省略不可文字列(ハッシュタグ)にhtmlのリンクが付与されます。
lengthnumber- ※省略不可出力する桁数を指定します。
padstrstring'0'パディングで追加する文字列を変更します。

Dependencies

none


For Developer

Contribution

  1. Fork it ( https://github.com/yama-dev/js-parse-module/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. 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

Licence

MIT

Author

yama-dev