Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
IonicaBizau committed Dec 24, 2017
1 parent 936cf8e commit 2ed6bbf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This document contains guides that *I* defined and follow when building things.

# Contents


- [Variable declarations](#variable-declarations-pencil)

- [Variables](#variables-speech_balloon)
Expand All @@ -36,8 +37,10 @@ This document contains guides that *I* defined and follow when building things.
- [Project naming](#project-naming)

## Variable declarations :pencil:

### Variables :speech_balloon:


Using `var` in general or `let` when they should be accesible only in specific blocks (e.g. `if`).

```js
Expand All @@ -55,8 +58,10 @@ if (...) {
/* do something with baz */
}
```

### Constants :triangular_flag_on_post:


Using `const`. The constant names are written with UPPERCASE letters. I also use `const` when including libraries using `require` and when they should not be changed. In this case, the names will not be with caps.

```js
Expand All @@ -69,12 +74,15 @@ const PI = Math.PI
, MY_CONSTANT = 42
;
```

### Globals :earth_africa:


I define globals when there is no commonjs environment (this is actually handled by [`dist-it`](https://github.com/IonicaBizau/dist-it). When I manually define globals, I do that using `window.MyGlobal` (on the client) and `global.MyGlobal` (on the server).

## Semicolons :pencil2:


I *use* semicolons. Almost always.

```js
Expand All @@ -89,8 +97,10 @@ class Foo {
...
}
```

## Method and property definitions :paperclip:


I use the ES6 `class` for creating classes.

```js
Expand All @@ -104,8 +114,10 @@ class Person {
}
}
```

## Deleting properties :x:


I nullify the properties when that's fine:

```js
Expand All @@ -115,20 +127,24 @@ var foo = {
foo.bar = null;
```


However, I use the `delete` keyword when I really want to delete them.

```js
delete foo.bar;
```

## `eval()`


`eval` is evil. :rage: Do not use it. However I use it in some test files and in places where I have to execute the JavaScript code provided by the user.


For converting strings to JSON, use `JSON.parse(strObj)`.

## Iterating objects and arrays


For arrays, most of times, I use the `forEach` function:

```js
Expand All @@ -137,6 +153,7 @@ arr.forEach(c => {
});
```


However, using `for` loops is fine too:

```js
Expand All @@ -148,6 +165,7 @@ for (var i = 0; i < arr.length; ++i) {
}
```


For objects, I use the following style:

```js
Expand All @@ -157,6 +175,7 @@ Object.keys(obj).forEach(k => {
});
```


To simplify this, I created [`iterate-object`](https://github.com/IonicaBizau/iterate-object), which abstracts this functionality:

```js
Expand All @@ -165,8 +184,10 @@ iterateObject(obj, (value, key) => {
// do something
});
```

## Multiline strings :guitar:


I use backticks to create multiline strings:

```js
Expand All @@ -176,12 +197,15 @@ aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat
New line again...`;
```

## Modifying prototypes of built-in objects :shit:


Just don't, unless that's the scope of the library.

## Naming things :thought_balloon:


Using camel case notation for variables, in general. For constructors I capitalize the variable name (e.g. `EventEmitter`).

```js
Expand Down Expand Up @@ -216,8 +240,10 @@ var obj = {
};
obj.methodA = function () {...};
```

## Curly braces :curly_loop:


Open the curly brace at the end of the line. Always put the instructions between curly braces, even there is only one instruction.

```js
Expand All @@ -228,8 +254,10 @@ if (expr) {
instr3;
}
```

## Array and Object Initializers :file_folder:


See examples.

```js
Expand Down Expand Up @@ -257,8 +285,10 @@ var obj1 = {
, age: 20
};
```

## Commas


Put commas at the beginning of the line, not at the end.

```js
Expand All @@ -275,8 +305,10 @@ var obj = {
, y: 2
};
```

## Blank lines


Group the instructions inserting some blank lines where it's needed.

```js
Expand All @@ -286,8 +318,10 @@ bar(x);
foo(y);
bar(y);
```

## Binary and Ternary operators


See examples.

```js
Expand All @@ -308,16 +342,20 @@ var c = another_long_condition_here
: or_another_some_long_value
;
```

## Quotes :speech_balloon:


Double quotes, with some exceptions when single quotes are used.

```js
var foo = "\"Hello\", he said.";
var jQuerySelector = "div.myClass[data-foo='bar']";
```

## Comments :notes:


Put relevant comments. The comments start with uppercase letter.

```js
Expand All @@ -330,6 +368,7 @@ const lib1 = require("lib1")
const FOURTY_TWO = 42;
```


Use JSDoc comments for functions and methods.

```js
Expand All @@ -348,19 +387,23 @@ function sum (a, b) {
};
```


I use the [`blah` tool](https://github.com/IonicaBizau/blah) to generate documentation.

```sh
$ npm install -g blah
$ blah --readme
$ blah --docs some-file.js
```

## Project naming


I use [`name-it`](https://github.com/IonicaBizau/name-it) to generate project names.

## Project licenses


I :sparkling_heart: open-source! I prefer the MIT license.


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,4 @@
"bloggify.json",
"bloggify/"
]
}
}

0 comments on commit 2ed6bbf

Please sign in to comment.