Permalink
Browse files

#44 Using the JavaScript Standard Style

  • Loading branch information...
1 parent b0b1422 commit b00f648ee9b8c9c3522077c56625deca7b11e59a @akabekobeko committed Feb 16, 2017
Showing with 1,052 additions and 1,032 deletions.
  1. +10 −0 .eslintrc
  2. +17 −16 README.md
  3. +0 −3 index.js
  4. +9 −5 package.json
  5. +95 −88 src/bin/cli.js
  6. +49 −0 src/bin/index.js
  7. +0 −49 src/bin/main.js
  8. +117 −115 src/lib/converter.js
  9. +50 −50 src/lib/gfm.js
  10. +26 −0 src/lib/index.js
  11. +12 −12 src/lib/logger.js
  12. +0 −26 src/lib/main.js
  13. +70 −70 src/lib/markdown.js
  14. +35 −35 src/lib/shortcode.js
  15. +81 −81 src/lib/util.js
  16. +86 −86 src/lib/wpxml2md.js
  17. +87 −87 test/bin/cli.test.js
  18. +192 −193 test/lib/converter.test.js
  19. +54 −54 test/lib/shortcode.test.js
  20. +53 −53 test/lib/util.test.js
  21. +9 −9 test/mock/stdout.mock.js
View
@@ -0,0 +1,10 @@
+{
+ "extends": "standard",
+ "env": {
+ "mocha": true
+ },
+ "rules": {
+ "no-multi-spaces": 0,
+ "yoda": 0
+ }
+}
View
@@ -4,6 +4,7 @@
[![npm version](https://badge.fury.io/js/wpxml2md.svg)](https://badge.fury.io/js/wpxml2md)
[![Build Status](https://travis-ci.org/akabekobeko/npm-wpxml2md.svg?branch=master)](https://travis-ci.org/akabekobeko/npm-wpxml2md)
[![Document](https://doc.esdoc.org/github.com/akabekobeko/npm-wpxml2md/badge.svg?t=0)](https://doc.esdoc.org/github.com/akabekobeko/npm-wpxml2md)
+[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](http://standardjs.com/)
Convert the WordPress XML file to Markdown files.
@@ -29,29 +30,29 @@ Can export the **WordPress XML** in the following way.
`wpxml2md` is promisify function.
```js
-const wpxml2md = require( 'wpxml2md' );
+const wpxml2md = require('wpxml2md');
-wpxml2md( 'wordpress.xml', 'dest', { report: true } )
-.then( () => {
- console.log( 'Completed!!' );
+wpxml2md('wordpress.xml', 'dest', {report: true})
+.then(() => {
+ console.log('Completed!!');
} )
-.catch( ( err ) => {
- console.error( err );
-} );
+.catch((err) => {
+ console.error(err);
+});
```
Add modes:
```js
-const wpxml2md = require( 'wpxml2md' );
-
-wpxml2md( 'wordpress.xml', 'dest', { noGFM: true, noMELink: true } )
-.then( () => {
- console.log( 'Completed!!' );
-} )
-.catch( ( err ) => {
- console.error( err );
-} );
+const wpxml2md = require('wpxml2md');
+
+wpxml2md('wordpress.xml', 'dest', {noGFM: true, noMELink: true})
+.then(() => {
+ console.log('Completed!!');
+})
+.catch((err) => {
+ console.error( err);
+});
```
`wpxml2md( src, dest, [OPTIONS] )`
View
@@ -1,3 +0,0 @@
-'use strict';
-
-module.exports = require( './src/lib/main.js' );
View
@@ -8,12 +8,11 @@
"engines": {
"node": ">= 4"
},
- "main": "index.js",
- "bin": "src/bin/main.js",
+ "main": "src/lib/index.js",
+ "bin": "src/bin/index.js",
"files": [
"src/bin",
- "src/lib",
- "index.js"
+ "src/lib"
],
"keywords": [
"Convert",
@@ -52,7 +51,8 @@
},
"scripts": {
"test": "mocha --timeout 50000 --compilers js:babel-register test/**/*.test.js",
- "esdoc": "esdoc"
+ "esdoc": "esdoc",
+ "eslint": "eslint ./src"
},
"dependencies": {
"collapse-whitespace": "^1.1.4",
@@ -64,6 +64,10 @@
"babel-register": "^6.22.0",
"esdoc": "^0.5.2",
"esdoc-node": "^1.0.0",
+ "eslint": "^3.15.0",
+ "eslint-config-standard": "^6.2.1",
+ "eslint-plugin-promise": "^3.4.1",
+ "eslint-plugin-standard": "^2.0.1",
"mocha": "^3.2.0",
"power-assert": "^1.4.2"
}
View
@@ -1,13 +1,12 @@
-'use strict';
+'use strict'
-const Path = require( 'path' );
+const Path = require('path')
/**
* Help text.
* @type {[type]}
*/
-const HelpText =
-`
+const HelpText = `
Usage: wpxml2md [OPTIONS]
Convert the WordPress XML file to Markdown files.
@@ -34,20 +33,20 @@ Usage: wpxml2md [OPTIONS]
See also:
https://github.com/akabekobeko/npm-wpxml2md
-`;
+`
/**
* CLI options.
* @type {Object}
*/
const Options = {
- help: [ '-h', '--help' ],
+ help: [ '-h', '--help' ],
version: [ '-v', '--version' ],
- input: [ '-i', '--input' ],
- output: [ '-o', '--output' ],
- modes: [ '-m', '--modes' ],
- report: [ '-r', '--report' ]
-};
+ input: [ '-i', '--input' ],
+ output: [ '-o', '--output' ],
+ modes: [ '-m', '--modes' ],
+ report: [ '-r', '--report' ]
+}
/**
* Output modes.
@@ -56,7 +55,7 @@ const Options = {
const Modes = {
noGFM: 'no-gfm',
noMELink: 'no-melink'
-};
+}
/**
* Provides a command line interface.
@@ -69,22 +68,22 @@ class CLI {
*
* @return {CLIOptions} Parse results.
*/
- static parseArgv( argv ) {
- if( !( argv && 0 < argv.length ) ) {
- return { help: true };
+ static parseArgv (argv) {
+ if (!(argv && 0 < argv.length)) {
+ return { help: true }
}
- switch( argv[ 0 ] ) {
- case Options.help[ 0 ]:
- case Options.help[ 1 ]:
- return { help: true };
+ switch (argv[ 0 ]) {
+ case Options.help[0]:
+ case Options.help[1]:
+ return {help: true}
- case Options.version[ 0 ]:
- case Options.version[ 1 ]:
- return { version: true };
+ case Options.version[0]:
+ case Options.version[1]:
+ return {version: true}
default:
- return CLI._parseArgv( argv );
+ return CLI._parseArgv(argv)
}
}
@@ -93,26 +92,26 @@ class CLI {
*
* @param {WritableStream} stdout Standard output.
*/
- static printHelp( stdout ) {
- stdout.write( HelpText );
+ static printHelp (stdout) {
+ stdout.write(HelpText)
}
/**
* Print a version number.
*
* @param {WritableStream} stdout Standard output.
*/
- static printVersion( stdout ) {
- const read = ( path ) => {
+ static printVersion (stdout) {
+ const read = (path) => {
try {
- return require( path ).version;
- } catch( err ) {
- return null;
+ return require(path).version
+ } catch (err) {
+ return null
}
- };
+ }
- const version = read( '../package.json' ) || read( '../../package.json' );
- stdout.write( 'v' + version + '\n' );
+ const version = read('../package.json') || read('../../package.json')
+ stdout.write('v' + version + '\n')
}
/**
@@ -122,9 +121,9 @@ class CLI {
*
* @return {Boolean} If the option of the value "true".
*/
- static _isValue( value ) {
- const keys = Object.keys( Options );
- return !( keys.some( ( key ) => value === Options[ key ][ 0 ] || value === Options[ key ][ 1 ] ) );
+ static _isValue (value) {
+ const keys = Object.keys(Options)
+ return !(keys.some((key) => value === Options[key][0] || value === Options[key][1]))
}
/**
@@ -134,45 +133,49 @@ class CLI {
*
* @return {CLIOptions} Parse results.
*/
- static _parseArgv( argv ) {
- const options = {};
- let value = null;
-
- argv.forEach( ( arg, index ) => {
- switch( arg ) {
- case Options.input[ 0 ]:
- case Options.input[ 1 ]:
- value = CLI._parseArgValue( argv, index );
- if( value ) { options.input = Path.resolve( value ); }
- break;
-
- case Options.output[ 0 ]:
- case Options.output[ 1 ]:
- value = CLI._parseArgValue( argv, index );
- if( value ) { options.output = Path.resolve( value ); }
- break;
-
- case Options.report[ 0 ]:
- case Options.report[ 1 ]:
- options.report = true;
- break;
-
- case Options.modes[ 0 ]:
- case Options.modes[ 1 ]:
- value = CLI._parseArgValue( argv, index );
- if( value ) {
- const modes = CLI._parseModes( value );
- options.noGFM = modes.noGFM;
- options.noMELink = modes.noMELink;
+ static _parseArgv (argv) {
+ const options = {}
+ let value = null
+
+ argv.forEach((arg, index) => {
+ switch (arg) {
+ case Options.input[0]:
+ case Options.input[1]:
+ value = CLI._parseArgValue(argv, index)
+ if (value) {
+ options.input = Path.resolve(value)
}
- break;
+ break
+
+ case Options.output[0]:
+ case Options.output[1]:
+ value = CLI._parseArgValue(argv, index)
+ if (value) {
+ options.output = Path.resolve(value)
+ }
+ break
+
+ case Options.report[0]:
+ case Options.report[1]:
+ options.report = true
+ break
+
+ case Options.modes[0]:
+ case Options.modes[1]:
+ value = CLI._parseArgValue(argv, index)
+ if (value) {
+ const modes = CLI._parseModes(value)
+ options.noGFM = modes.noGFM
+ options.noMELink = modes.noMELink
+ }
+ break
default:
- break;
+ break
}
- } );
+ })
- return options;
+ return options
}
/**
@@ -183,11 +186,13 @@ class CLI {
*
* @return {String} Its contents if the option value, otherwise null.
*/
- static _parseArgValue( argv, index ) {
- if( !( index + 1 < argv.length ) ) { return null; }
+ static _parseArgValue (argv, index) {
+ if (!(index + 1 < argv.length)) {
+ return null
+ }
- const value = argv[ index + 1 ];
- return ( CLI._isValue( value ) ? value : null );
+ const value = argv[index + 1]
+ return (CLI._isValue(value) ? value : null)
}
/**
@@ -197,27 +202,29 @@ class CLI {
*
* @return {Object} Modes.
*/
- static _parseModes( arg ) {
- const result = {};
- if( typeof arg !== 'string' ) { return result; }
+ static _parseModes (arg) {
+ const result = {}
+ if (typeof arg !== 'string') {
+ return result
+ }
- const units = arg.split( ',' );
- units.forEach( ( unit ) => {
- switch( unit ) {
+ const units = arg.split(',')
+ units.forEach((unit) => {
+ switch (unit) {
case Modes.noGFM:
- result.noGFM = true;
- break;
+ result.noGFM = true
+ break
case Modes.noMELink:
- result.noMELink = true;
- break;
+ result.noMELink = true
+ break
default:
- break;
+ break
}
- } );
+ })
- return result;
+ return result
}
}
@@ -226,4 +233,4 @@ module.exports = {
Options: Options,
Modes: Modes,
CLI: CLI
-};
+}
Oops, something went wrong.

0 comments on commit b00f648

Please sign in to comment.