Skip to content

mane115/gutil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Dec 20, 2017
86509fd · Dec 20, 2017

History

12 Commits
Dec 20, 2017
Dec 15, 2017
Dec 14, 2017
Dec 14, 2017
Dec 15, 2017
Dec 20, 2017
Dec 14, 2017
Dec 14, 2017

Repository files navigation

gutil

util collect

  • util.fs

    • Description

      promisify fs

    • Source

       let fs = require('fs');
       bluebird.promisifyAll('fs');
    • Example

       util.fs.readFileAsync(path.resolve(__diranme, './')).then(content => {
       	// => file content
       }).catch(err => {
       	// => 
       	readFile error 
       })
  • util.parse.json

    • Arguments

      str(Any): string ready to parse

    • Return

      (Object | String): if str is a JSON,return Object,else return itself

    • Example

       util.parse.json(`{"a":1}`);
       // => { a: 1 }
      
       util.parse.json('normal string');
       // => normal string
  • util.parse.number

    • Arguments

      num(Any): value ready to parse

      default(Number): if parse fail,return default value, default to 0

    • Return

      (Number=0): if parse fail,return default value, default to 0

    • Example

       util.parse.number('1');
       // => 1
      
       util.parse.number('normal string', 10);
       // => 10
      
       util.parse.number('normal string');
       // => 0
  • util.parse.url

    • Arguments

      url(String): url string ready to parse

      protocol='http'(String):url protocol

    • Return

      (String): parse url with protocol

    • Example

       util.parse.url('127.0.0.1');
       // => 'http://127.0.0.1'
      
       util.parse.url('http://127.0.0.1');
       // => 'http://127.0.0.1'
      
       util.parse.url('127.0.0.1:6379', 'redis');
       // => 'redis://127.0.0.1:6379'