Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
IonicaBizau committed Sep 8, 2017
1 parent 9682f98 commit 7076289
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ This document contains guides that *I* defined and follow when building things.

# Contents


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

- [Variables](#variables-speech_balloon)
Expand All @@ -37,10 +36,8 @@ 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 @@ -58,10 +55,8 @@ 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 @@ -74,15 +69,12 @@ 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 @@ -97,10 +89,8 @@ class Foo {
...
}
```

## Method and property definitions :paperclip:


I use the ES6 `class` for creating classes.

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

## Deleting properties :x:


I nullify the properties when that's fine:

```js
Expand All @@ -127,24 +115,20 @@ 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 @@ -153,7 +137,6 @@ arr.forEach(c => {
});
```


However, using `for` loops is fine too:

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


For objects, I use the following style:

```js
Expand All @@ -175,7 +157,6 @@ 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 @@ -184,10 +165,8 @@ iterateObject(obj, (value, key) => {
// do something
});
```

## Multiline strings :guitar:


I use backticks to create multiline strings:

```js
Expand All @@ -197,15 +176,12 @@ 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 @@ -240,10 +216,8 @@ 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 @@ -254,10 +228,8 @@ if (expr) {
instr3;
}
```

## Array and Object Initializers :file_folder:


See examples.

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

## Commas


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

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

## Blank lines


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

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

## Binary and Ternary operators


See examples.

```js
Expand All @@ -342,20 +308,16 @@ 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 @@ -368,7 +330,6 @@ const lib1 = require("lib1")
const FOURTY_TWO = 42;
```


Use JSDoc comments for functions and methods.

```js
Expand All @@ -387,23 +348,19 @@ 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

0 comments on commit 7076289

Please sign in to comment.