Deriving a new Array from an existing Array:
['■','●','▲'].slice(1, 3) ⟼ ['●','▲']
['■','●','■'].filter(x => x==='■') ⟼ ['■','■']
['▲','●'].map(x => x+x) ⟼ ['▲▲','●●']
['▲','●'].flatMap(x => [x,x]) ⟼ ['▲','▲','●','●']The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.
This means you have the following choices:
import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.await import(…) from CommonJS instead of require(…).| // Typescript lets you put constraints on assignment -- cool | |
| // - I don't know what this feature is officially called and can't find it. | |
| // for example, telling the IDE that a constant should be "even" | |
| type even = 2 | 4 | 6; | |
| const a = 2; | |
| const b: even = 2; | |
| const c: even = 4; | |
| const d: even = 3; // error: constraint violation | |
| // you can assert types, this is different! |
| # Slack Block Kit Cheatsheet | |
| This is a cheatsheat for the [Block Kit API](https://api.slack.com/block-kit), great for referencing when wireframing out Slack interactions. | |
| ## Values to know | |
| ### Surfaces | |
| - [50 blocks per message](https://api.slack.com/reference/block-kit/blocks#:~:text=You%20can%20include%20up%20to,in%20modals%20or%20home%20tabs.) | |
| - [100 blocks per modal or in the home tab](https://api.slack.com/reference/block-kit/blocks#:~:text=You%20can%20include%20up%20to,in%20modals%20or%20home%20tabs.) |
| /* eslint-disable no-return-assign */ | |
| const chalk = require('chalk'); | |
| const ora = require('ora'); | |
| const prettyMs = require('pretty-ms'); | |
| const throttle = require('lodash/throttle'); | |
| const getHeapUsed = throttle( | |
| () => { | |
| const heapUsed = process.memoryUsage().heapUsed / 1024 / 1024; | |
| return Math.round(heapUsed, 2); |
| /* | |
| Problem | |
| We have a function that updates objects and generates audit records of the changes. | |
| Think about financial systems or just any app where it's useful to know who made changes to what. | |
| Audit records needs to be saved to the DB as well as updates to objects, but ideally | |
| we would want to execute business logic, accumulate all updates and audit records in memory | |
| and then save it to DB all at once. Let's look at the specifics. |
| // based on vanilla lodash, todo: rewrite with lodash/fp | |
| // uses isPlainObject to detect ojbects to go deep into | |
| // detects circular references using Set() | |
| function mapValuesDeep(originalObj, mapFunc) { | |
| const visitedObjects = new Set() | |
| const mapValues = (originalObj, mapFunc) => | |
| _.mapValues(originalObj, value => { | |
| if (_.isPlainObject(value)) { |
| // gets time now in milliseconds | |
| const msNow = () => (+new Date()) | |
| function createProgress ({ | |
| maxItems = 100, | |
| onProgressChange = () => {}, | |
| onComplete = () => {} | |
| }) { | |
| let currentProgress = 0 // % | |
| let lastProgress = 0 |
It will check if current branch is master, then ask a confirmation, in case of master branch
Articles with initial info: https://dev.ghost.org/prevent-master-push/, https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook
| // getComponent is a function that returns a promise for a component | |
| // It will not be called until the first mount | |
| function asyncComponent(getComponent) { | |
| return class AsyncComponent extends React.Component { | |
| static Component = null; | |
| state = { Component: AsyncComponent.Component }; | |
| componentWillMount() { | |
| if (!this.state.Component) { | |
| getComponent().then(Component => { |