Please enable JavaScript.
Coggle requires JavaScript to display documents.
NodeJs JS/TS (Async (Promise (Promise.all()), cb, async/await, Bluebird,…
NodeJs JS/TS
Async
cb
async/await
Promise
Promise.all()
Bluebird
promise-retry
Tesing
Chai //assertion lib
Mocha
Sinon
Sandbox
sandbox.stub(obj, 'methodName').throws(new Error('err'))
get Calls
assert.equal(stub.callCount, 0)
stub.getCalls().forEach((call) => {
assert.equal(call.args[1], 'CM001')
assert.deepEqual(call.args[3].availabilityByDate, { '2018-31-01': 10 })
})
_sequentialProcessor = sinon.stub(recordsProcessor, '_processSequentially').resolves(null)
_sequentialProcessor.
withArgs(...).resolves(...)
assert(jQuery.ajax.calledOnce);
assertEquals("/some/resource", jQuery.ajax.getCall(0).args[0].url);
Assertion
expect
expect(obj).to.have.property('property').eql(value)
expect(arr).an('array').length(1)
expect(() => {}).to.throw()
expect(client.client).to.have.property('get').a('function')
assert(chai)
assert.equal(p1,p2)
assert.isArray(param)
assert.isObject(obj)
assert.deepEqual(obj, expectedNotificationDto)
assert.isRejected
assert.isFulfilled
assert.instanceOf(object, Date)
expect(obj).to.deep.include({ field: 'val', etc...})
JS Core
Arrays
array.map(x=> {...})
array.forEach(e => {...})
Objects
Object.assign({}, src)
{...obj1, ...obj2}
Promise
Promise.resolve(obj)
Promise.reject(...)
Promise.all(...)
classes/interfaces
Partial
<Type>
Exceptions handling
cb
error first parameter
try/catch
promise.catch()
Other
factoryGirl (pkg)
factory.chance(...)
chance (pkg)
Lodash
_.map
_.defaults
_.chung(arr, CHUNK_SIZE)
_.flatten
_.clone
_.isUndefined
_.find
_.difference
_.isEqual
_.chain
_.chain(records)
.value()
.map((records, key) => ({ key, records }))
.groupBy('partitionKey')
_.
groupBy
(arr, (item) => { return item.field})
_.
flattenDeep
([1, [2, [3, [4]], 5]]);
// => [1, 2, 3, 4, 5]
_.omit
(hotel, 'password')
_.isMatch
(obj1, obj2)
_.pick
(object, [paths])
_.chunk
(array, [size=1])
Validation
AJV
convict
Date and Time
moment
moment('iso-8601 date string').format("YYYY-MM-DD")
moment-range
DateRange
apply days
const from = moment()
const to = from.clone().
add
(config('FLUSH_DATE_WINDOW'), 'days')
moment(reservationEvent.updatedAt).
subtract
(1, 'd').format()
js-joda
LocalDate
- date in YYYY-MM-DD format
localDate.toString() => 'YYYY-MM-DD' str
// converting from a moment is workings the same way
d =
LocalDate.from
(nativeJs(moment()));
// the recommended way with the javascript temporal
t =
LocalDate.from
(nativeJs(new Date()));
LocalDate.of(2018, 1, 1)
Configuration/Settings
config
convict
Mocking
http
axios-mock-adapter
sinon
import * as sinon from 'sinon'
let sandbox: sinon.SinonSandbox
sandbox = sinon.sandbox.create()
sandbox.stub(cm, 'getClient').callsFake(() => apiClient)
sandbox.restore()
|||
Bluebird
Promise.all
Immutability
immutable.js (Facebook)
Debugging
debug (pkg)
Validation
AJV
http-client
axios
(Promise based HTTP client for the browser and node.js)
DB
ORM Sequelize
Knowleadge
Functional Programming
Closure
(
x
)=>(y)=>{ return
x
+ y}
Immutability
Pure functions
No side effects. It does not depends on global state
First-Class Functions
Utils
Commander
Makes js file to be executable
TypeScript
Generics
const arr =
(attrs as any[])
.map((attr) => {...})
let square =
<Square>
{};
Patterns
Builder
http-client
npm:
request-promise
http-requests
working with query
npm 'querystring'
Generators
npm:chance
npm install chance
var Chance = require('chance');
var chance = new Chance();
var my_random_string = chance.string();