Skip to content

Commit 5e818da

Browse files
committed
Added generate-pdf, dynamic-import, unified
1 parent ea0f48f commit 5e818da

27 files changed

+10449
-0
lines changed

dynamic-import/.babelrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "current"
8+
}
9+
}
10+
]
11+
],
12+
"plugins": ["@babel/plugin-transform-async-to-generator"]
13+
}
14+

dynamic-import/.gitignore

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# dotenv environment variables file
55+
.env
56+
57+
# gatsby files
58+
.cache/
59+
public
60+
61+
# Mac files
62+
.DS_Store
63+
64+
# Yarn
65+
yarn-error.log
66+
.pnp/
67+
.pnp.js
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
lib

dynamic-import/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Introduction
2+
3+
# Objectives
4+
5+
# Implementation

dynamic-import/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "dynamic-import",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"scripts": {
7+
"build": "./node_modules/.bin/babel --version && ./node_modules/.bin/babel src -d lib",
8+
"start": "node lib/index.js"
9+
},
10+
"devDependencies": {
11+
"@babel/cli": "^7.7.7",
12+
"@babel/core": "^7.7.7",
13+
"@babel/plugin-transform-async-to-generator": "^7.7.4",
14+
"@babel/preset-env": "^7.7.7"
15+
},
16+
"dependencies": {
17+
"lodash": "^4.17.15",
18+
"trough": "^1.0.5"
19+
}
20+
}

dynamic-import/src/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import _ from 'lodash'
2+
import trough from 'trough'
3+
4+
const getLib = async (name) => {
5+
const lib = await import(name)
6+
return lib
7+
}
8+
9+
const getMethod = async ({ libName, methodName }) => {
10+
const lib = await getLib(libName)
11+
let method
12+
if (methodName) method = _.get(lib, methodName, undefined)
13+
else method = _.get(lib, 'default', undefined)
14+
return method
15+
}
16+
17+
const run = async () => {
18+
const method = await getMethod({ libName: 'lodash', methodName: 'add' })
19+
20+
const sum = method(6, 4)
21+
// 10
22+
console.log(sum)
23+
}
24+
25+
const pipeline = async () => {
26+
let p = trough()
27+
const array = ['mean', 'floor']
28+
29+
for (let name of array) {
30+
const method = await getMethod({ libName: 'lodash', methodName: name })
31+
p = p.use(function(data) {
32+
const value = method(data)
33+
return value
34+
})
35+
}
36+
37+
return p
38+
}
39+
40+
(async() => {
41+
await run()
42+
const p = await pipeline()
43+
p.run([1.2, 2.4, 3.45, 6, 7, 18.5, 29.5], function(err, data) {
44+
console.log(`End of pipeline ${data}`)
45+
})
46+
console.log('async/await in node with babel...')
47+
})()

0 commit comments

Comments
 (0)