diff --git a/flowtype.md b/flowtype.md index bf50c39b9..0428d24eb 100644 --- a/flowtype.md +++ b/flowtype.md @@ -29,7 +29,13 @@ boolean mixed number string -void +void // undefined +null // null (but not undefined) + +?number // maybe (number | void | null) + +{a: Number} // object with a shape +[any, number] // tuples (fixed-length arrays) Array Class @@ -37,6 +43,56 @@ Function Object ``` +## [Type aliases](https://flowtype.org/docs/quick-reference.html#type-aliases) + +```js +type Tree = { + foo: string, + bar: number, + qux: (foo: string, bar: number) => boolean +} + +type Generic = { + foo: T +} +``` + +## [Generic classes](https://flowtype.org/docs/quick-reference.html#generics) + +```js +class GenericClass { + x: T; + constructor (x: T) { ... } +} + +var n: GenericClass = new GenericClass(0) +``` + +## [Interfaces](https://flowtype.org/docs/quick-reference.html#interfaces) + +```js +interface Jsonable { + toJSON(): string +} + +class Foo { + toJSON() { return '{}' } +} + +(new Foo: Jsonable) +``` + +## [Functions](https://flowtype.org/docs/functions.html) + +```js +function createRenderer (): () => void { + return function () { } +} +``` + + +## Examples + ```js var myNumbers: Array = [42] function foo(): any { return 42 } diff --git a/jsdoc.md b/jsdoc.md new file mode 100644 index 000000000..fcb9d9e87 --- /dev/null +++ b/jsdoc.md @@ -0,0 +1,88 @@ +--- +title: Jsdoc +category: JavaScript +--- + +## Functions + +```js +/* + * @param {string} n - A string param + * @return {string} A good string + * + * @throws {FooException} + * @private + * @deprecated + * @see + * + * @function + * @class + */ + +function foo(n) { return n } +``` + +See: http://usejsdoc.org/index.html + +## Types + +``` +/** + * @param {string=} n - Optional param + * @param {string} [n] - Optional param + * @param {(string|number)} n - Multiple types + * @param {*} n - Any type + * @param {...string} n - Repeatable arguments + * @param {string} [n="hi"] - Optional param with default + * @param {string[]} n - An array of strings + */ +``` + +See: http://usejsdoc.org/tags-type.html + +## Variables + +```js +/** + * @type {number} + */ +var FOO = 1 + +/** + * @const {number} + */ +const FOO = 1 +``` + +## Typedef + +```js +/** + * A song + * @typedef {Object} Song + * @property {string} title - The title + * @property {string} artist - The artist + * @property {number} year - The year + */ + +/** + * Plays a song + * @param {Song} song - The {@link Song} to be played + */ + +function play (song) { +} +``` + +See: http://usejsdoc.org/tags-typedef.html + +## Renaming + +```js +/* + * @alias Foo.bar + * @name Foo.bar + */ +``` + +Prefer `alias` over `name`. See: http://usejsdoc.org/tags-alias.html diff --git a/rspec.md b/rspec.md index 45222ae4e..6c8b29793 100644 --- a/rspec.md +++ b/rspec.md @@ -53,48 +53,71 @@ expect(target).to eq 1 expect(target).not_to eq 1 ``` +### Numeric + ```rb -# Numeric -be < 6 -== 5 -equal value -be_between(1, 10) -be_within(0.05).of value +expect(5).to be < 6 +expect(5).to == 5 +expect(5).to equal value +expect(5).to be_between(1, 10) +expect(5).to be_within(0.05).of value +``` -be value -satisfy {|arg| ...} -predicate [optional args] -match regexp +### Comparison -be_an_instance_of -be_a_kind_of +```rb +expect(x).to be value +expect(x).to satisfy { |arg| ... } +expect(x).to match /regexp/ +``` -respond_to +### Predicate -# Control flow -raise_error -raise_error( [, message]) +```rb +expect(x).to be_zero # FixNum#zero? +expect(x).to be_empty # Array#empty? +expect(x).to have_key # Hash#has_key? +``` -throw +### Objects -# Enumerables/arrays -include +```rb +expect(obj).to be_an_instance_of MyClass +expect(obj).to be_a_kind_of MyClass +expect(obj).to respond_to :save! +``` -have().things -have_at_least().things -have_at_most().things +### Control flow -have().errors_on(:field) +```rb +expect { user.save! }.to raise_error +expect { user.save! }.to raise_error(ExceptionName, /msg/) +expect { user.save! }.to throw :symbol +``` -# Change -change(instance, method).from(number).to(number) +### Enumerables/arrays -# proc.should <=> expect(&proc).to -expect { thing.approve! }.to change(thing, :status). - from(Status::AWAITING_APPROVAL). - to(Status::APPROVED) +```rb +expect(list).to include() -expect { thing.destroy }.to change(Thing, :count).by(-1) +expect(list).to have(1).things +expect(list).to have_at_least(2).things +expect(list).to have_at_most(3).things + +expect(list).to have(2).errors_on(:field) +``` + +### Change + +```rb +expect { thing.approve! }.to \ + change(thing, :status) + .from(Status::AWAITING_APPROVAL) + .to(Status::APPROVED) + +expect { thing.destroy }.to \ + change(Thing, :count) + .by(-1) ``` ### Double