diff --git a/Chapter02/communicating-with-sockets/client.js b/Chapter02/communicating-with-sockets/client.js new file mode 100644 index 0000000..d712e99 --- /dev/null +++ b/Chapter02/communicating-with-sockets/client.js @@ -0,0 +1,12 @@ +const net = require('net'); + +const HOSTNAME = 'localhost'; +const PORT = 3000; + +const socket = net.connect(PORT, HOSTNAME); + +socket.write('World'); + +socket.on('data', (data) => { + console.log(data.toString()); +}); diff --git a/Chapter02/communicating-with-sockets/server.js b/Chapter02/communicating-with-sockets/server.js new file mode 100644 index 0000000..ddf6495 --- /dev/null +++ b/Chapter02/communicating-with-sockets/server.js @@ -0,0 +1,13 @@ +const net = require('net'); + +const HOSTNAME = 'localhost'; +const PORT = 3000; + +net.createServer((socket) => { + console.log('Client connected.'); + + socket.on('data', name => { + socket.write(`Hello ${name}!`); + }); + +}).listen(PORT, HOSTNAME); \ No newline at end of file diff --git a/Chapter02/fetching-metadata/.DS_Store b/Chapter02/fetching-metadata/.DS_Store new file mode 100644 index 0000000..e936e88 Binary files /dev/null and b/Chapter02/fetching-metadata/.DS_Store differ diff --git a/Chapter02/fetching-metadata/chmod-octal.js b/Chapter02/fetching-metadata/chmod-octal.js new file mode 100644 index 0000000..3d5e1df --- /dev/null +++ b/Chapter02/fetching-metadata/chmod-octal.js @@ -0,0 +1,6 @@ +'use strict' + +const fs = require('fs'); +const file = './file.txt'; + +fs.chmodSync("./file.txt", 0o664); \ No newline at end of file diff --git a/Chapter02/fetching-metadata/chmod.js b/Chapter02/fetching-metadata/chmod.js new file mode 100644 index 0000000..7da6a40 --- /dev/null +++ b/Chapter02/fetching-metadata/chmod.js @@ -0,0 +1,9 @@ +'use strict' + +const fs = require('fs'); +const file = './file.txt'; + +fs.chmodSync("./file.txt", + fs.constants.S_IRUSR | fs.constants.S_IWUSR | + fs.constants.S_IRGRP | fs.constants.S_IWGRP | + fs.constants.S_IROTH); \ No newline at end of file diff --git a/Chapter02/fetching-metadata/file.txt b/Chapter02/fetching-metadata/file.txt new file mode 100644 index 0000000..e69de29 diff --git a/Chapter02/fetching-metadata/metadata.js b/Chapter02/fetching-metadata/metadata.js new file mode 100644 index 0000000..d762341 --- /dev/null +++ b/Chapter02/fetching-metadata/metadata.js @@ -0,0 +1,9 @@ +const fs = require('fs'); +const file = process.argv[2]; + +function printMetadata(file) { + const fileStats = fs.statSync(file); + console.log(fileStats); +}; + +printMetadata(file); \ No newline at end of file diff --git a/Chapter02/fetching-metadata/metadata2.js b/Chapter02/fetching-metadata/metadata2.js new file mode 100644 index 0000000..ed1011e --- /dev/null +++ b/Chapter02/fetching-metadata/metadata2.js @@ -0,0 +1,13 @@ +const fs = require('fs'); +const file = process.argv[2]; + +function printMetadata(file) { + try { + const fileStats = fs.statSync(file); + console.log(fileStats); + } catch (err) { + console.error("Error reading file path:", file); + } +}; + +printMetadata(file); \ No newline at end of file diff --git a/Chapter02/file-watching/file.txt b/Chapter02/file-watching/file.txt new file mode 100644 index 0000000..6f87cc6 --- /dev/null +++ b/Chapter02/file-watching/file.txt @@ -0,0 +1,12 @@ +HELLO! + ls + Hello again; + gs + gsgds + gsdsdf + sddsf + sdfsd + sdda + dfsdf + dsad + sdasd \ No newline at end of file diff --git a/Chapter02/file-watching/package-lock.json b/Chapter02/file-watching/package-lock.json new file mode 100644 index 0000000..e6ac875 --- /dev/null +++ b/Chapter02/file-watching/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "file-watching", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "moment": { + "version": "2.24.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", + "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" + } + } +} diff --git a/Chapter02/file-watching/package.json b/Chapter02/file-watching/package.json new file mode 100644 index 0000000..3de0014 --- /dev/null +++ b/Chapter02/file-watching/package.json @@ -0,0 +1,16 @@ +{ + "name": "file-watching", + "version": "1.0.0", + "main": "watch.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "moment": "^2.24.0" + }, + "devDependencies": {}, + "description": "" +} diff --git a/Chapter02/file-watching/watch.js b/Chapter02/file-watching/watch.js new file mode 100644 index 0000000..cea0862 --- /dev/null +++ b/Chapter02/file-watching/watch.js @@ -0,0 +1,6 @@ +const fs = require('fs'); +const file = './file.txt'; + +fs.watchFile(file, (current, previous) => { + return console.log(`${file} updated ${time}`) +}); \ No newline at end of file diff --git a/Chapter02/file-watching/watch2.js b/Chapter02/file-watching/watch2.js new file mode 100644 index 0000000..b756a34 --- /dev/null +++ b/Chapter02/file-watching/watch2.js @@ -0,0 +1,8 @@ +const fs = require('fs'); +const file = './file.txt'; +const moment = require('moment'); + +fs.watch(file, (eventType, filename) => { + const time = moment().format('MMMM Do YYYY, h:mm:ss a'); + return console.log(`${filename} updated ${time}`) +}); \ No newline at end of file diff --git a/Chapter02/installing-dependencies/hsl-to-hex/package.json b/Chapter02/installing-dependencies/hsl-to-hex/package.json deleted file mode 100644 index 31b90ac..0000000 --- a/Chapter02/installing-dependencies/hsl-to-hex/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "hsl-to-hex", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "", - "dependencies": { - "hsl-to-rgb-for-reals": "^1.1.0" - } -} diff --git a/Chapter02/installing-dependencies/installing-development-dependencies/hsl-to-hex/package.json b/Chapter02/installing-dependencies/installing-development-dependencies/hsl-to-hex/package.json deleted file mode 100644 index ee37b5b..0000000 --- a/Chapter02/installing-dependencies/installing-development-dependencies/hsl-to-hex/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "hsl-to-hex", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "", - "dependencies": { - "hsl-to-rgb-for-reals": "^1.1.0" - }, - "devDependencies": { - "standard": "^6.0.8" - } -} diff --git a/Chapter02/installing-dependencies/using-npm-run-scripts/hsl-to-hex/package.json b/Chapter02/installing-dependencies/using-npm-run-scripts/hsl-to-hex/package.json deleted file mode 100644 index 5169107..0000000 --- a/Chapter02/installing-dependencies/using-npm-run-scripts/hsl-to-hex/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "hsl-to-hex", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "npm run lint", - "lint": "standard" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "", - "dependencies": { - "hsl-to-rgb-for-reals": "^1.1.0" - }, - "devDependencies": { - "standard": "^6.0.8" - } -} diff --git a/Chapter02/interfacing-with-io/greeting.js b/Chapter02/interfacing-with-io/greeting.js new file mode 100644 index 0000000..8082c47 --- /dev/null +++ b/Chapter02/interfacing-with-io/greeting.js @@ -0,0 +1,4 @@ +process.stdin.on('data', (data) => { + let name = data.toString().trim().toUpperCase(); + process.stdout.write(`Hello ${name}!`); +}); \ No newline at end of file diff --git a/Chapter02/interfacing-with-io/greeting2.js b/Chapter02/interfacing-with-io/greeting2.js new file mode 100644 index 0000000..e4d20ed --- /dev/null +++ b/Chapter02/interfacing-with-io/greeting2.js @@ -0,0 +1,8 @@ +process.stdin.on('data', data => { + let name = data.toString().trim().toUpperCase(); + if (name != '') { + process.stdout.write(`Hello ${name}!`); + } else { + process.stderr.write('Input was empty.'); + } +}); \ No newline at end of file diff --git a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/.gitignore b/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/.gitignore deleted file mode 100644 index eb03e3e..0000000 --- a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -*.log diff --git a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/example.js b/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/example.js deleted file mode 100644 index cfa65b7..0000000 --- a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/example.js +++ /dev/null @@ -1,6 +0,0 @@ -var hsl = require('./') -var hue = 133 -var saturation = 40 -var luminosity = 60 -var hex = hsl(hue, saturation, luminosity) -console.log(hex) // #70c282 diff --git a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/index.js b/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/index.js deleted file mode 100644 index 3abbdc5..0000000 --- a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/index.js +++ /dev/null @@ -1,66 +0,0 @@ -// In our case, there's only one dependency - -var toRgb = require('hsl-to-rgb-for-reals') -var debug = require('debug')('hsl-to-hex') - -// Typically all dependencies should be declared at the top of the file. - -// Now let's define an API for our module, we're taking hue, saturation and luminosity values and outputting a CSS compatible hex string. -// Hue is in degrees, between 0 and 359. Since degrees a cyclical in nature, we'll support numbers greater than 359 or less than 0 by "spinning" them around until they fall within the 0 to 359 range. -// Saturation and luminosity are both percentages, we'll represent these percentages with whole numbers between 0 and 100. For these numbers we'll need to enforce a maximum and a minimum, anything below 0 will become 0, anything above 100 will become 100. -// Let's write some utility functions to handle this logic: - -function max (val, n) { - debug('ensuring ' + val + ' is no more than ' + n) - return (val > n) ? n : val -} - -function min (val, n) { - debug('ensuring ' + val + ' is no less than ' + n) - return (val < n) ? n : val -} - -function cycle (val) { - debug('resolving ' + val + ' within the 0-359 range') - - // for safety: - val = max(val, 1e7) - val = min(val, -1e7) - // cycle value: - while (val < 0) { val += 360 } - while (val > 359) { val -= 360 } - return val -} - -// Now for the main piece, the `hsl` function: - -function hsl (hue, saturation, luminosity) { - debug('calculating hex for hue: ' + hue + ' saturation: ' + saturation + ' luminosity: ' + luminosity) - - // resolve degrees to 0 - 359 range - hue = cycle(hue) - - // enforce constraints - saturation = min(max(saturation, 100), 0) - luminosity = min(max(luminosity, 100), 0) - - // convert to 0 to 1 range used by hsl-to-rgb-for-reals - saturation /= 100 - luminosity /= 100 - - // let hsl-to-rgb-for-reals do the hard work - var rgb = toRgb(hue, saturation, luminosity) - - // convert each value in the returned RGB array - // to a 2 character hex value, join the array into - // a string, prefixed with a hash - return '#' + rgb - .map(function (n) { - return (256 + n).toString(16).substr(-2) - }) - .join('') -} - -// In order to make our code into a bona fide module we have to export it: - -module.exports = hsl diff --git a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/package.json b/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/package.json deleted file mode 100644 index 1c7df06..0000000 --- a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@davidmarkclements/hsl-to-hex", - "version": "1.0.1", - "main": "index.js", - "scripts": { - "check": "npm ls && npm test", - "test": "npm run lint && tap --cov test", - "lint": "standard", - "prepublish": "npm run check && ./publish-dep.sh" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "Convert HSL colors to RGB colors in hex format.", - "dependencies": { - "debug": "^2.2.0", - "hsl-to-rgb-for-reals": "^1.1.0" - }, - "devDependencies": { - "standard": "^6.0.8", - "tap": "^5.7.0" - }, - "directories": { - "test": "test" - } -} \ No newline at end of file diff --git a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/publish-dep.sh b/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/publish-dep.sh deleted file mode 100644 index 7d27a99..0000000 --- a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/publish-dep.sh +++ /dev/null @@ -1,50 +0,0 @@ -#! /bin/sh - -# 400 - Missing hash and/or peer_id -# 403 - Not allowed -# 413 - Too big -# 200 - Ok! - - -if echo $npm_config_argv | grep -q "install"; then - echo "Running at install step, skipping" -else - if ipfs &>/dev/null; then - echo "## Publishing dependency" - - mv node_modules .node_modules 2>/dev/null - - HASH=$(ipfs add . -r | tail -n 1 | cut -d ' ' -f 2) - - mv .node_modules node_modules 2>/dev/null - - echo "Published as $HASH" - - PEER=$(ipfs id --format '') - - if [ -f ~/.stay/nodes.json ]; then - cat ~/.stay/nodes.json | jq -rc '.[]' | while read host; do - address="$host/api/pin/add/$HASH/$PEER" - status=$(curl -X POST --silent $address) - case "$status" in - "400") echo "$host - Application Error: Missing the hash and/or peer_id" - ;; - "403") echo "$host - You do not have access to pinning at this node" - ;; - "413") echo "$host - The module was too big to pin!" - ;; - "200") echo "$host - Pinned!" - ;; - *) echo "Weird status code $status for $host" - ;; - esac - done - else - echo "You don't have any saved nodes in ~/.stay/nodes.json, skip pinning" - fi - else - echo "## Could not publish dependency to IPFS, doing the good'ol 'fetch from npm registry' way" - echo "Either 'ipfs' doesn't exists in PATH or you haven't run 'ipfs daemon' before running the command" - exit 0 - fi -fi diff --git a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/readme.md b/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/readme.md deleted file mode 100644 index a7bdfc2..0000000 --- a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/readme.md +++ /dev/null @@ -1,31 +0,0 @@ -# hsl-to-hex - -Convert HSL colors to RGB colors in hex format. - -## Install - -```sh -npm install --save @davidmarkclements/hsl-to-hex -``` - -## API - -``` -require('hsl-to-hex') => Function -hsl(hue, saturation, luminosity)` => String -``` - -## Example - -```js -var hsl = require('hsl-to-hex') -var hue = 133 -var saturation = 40 -var luminosity = 60 -var hex = hsl(hue, saturation, luminosity) -console.log(hex) // #70c282 -``` - -## License - -ISC \ No newline at end of file diff --git a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/test/index.js b/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/test/index.js deleted file mode 100644 index b355f31..0000000 --- a/Chapter02/publishing-a-module/decentralized-publishing/hsl-to-hex/test/index.js +++ /dev/null @@ -1,74 +0,0 @@ -var hsl = require('../') -var test = require('tap').test - -test('pure white', function (assert) { - var expected = '#ffffff' - var actual = hsl(0, 100, 100) - var it = 'max saturation and luminosity should return pure white' - assert.is(actual, expected, it) - assert.end() -}) - -test('medium gray', function (assert) { - var expected = '#808080' - var actual = hsl(0, 0, 50) - var it = '0% saturation, 50% luminosity should be medium gray' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - red', function (assert) { - var expected = '#ff0000' - var actual = hsl(0, 100, 50) - var it = '0deg should be red' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - blue', function (assert) { - var expected = '#0000ff' - var actual = hsl(240, 100, 50) - var it = '240deg should be blue' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - cyan', function (assert) { - var expected = '#00ffff' - var actual = hsl(180, 100, 50) - var it = '180deg should be cyan' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree overflow', function (assert) { - var expected = hsl(1, 100, 50) - var actual = hsl(361, 100, 50) - var it = '361deg should be the same as 1deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree underflow', function (assert) { - var expected = hsl(-1, 100, 50) - var actual = hsl(359, 100, 50) - var it = '-1deg should be the same as 359deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('max constraint', function (assert) { - var expected = hsl(0, 101, 50) - var actual = hsl(0, 100, 50) - var it = '101% should be the same as 100%' - assert.is(actual, expected, it) - assert.end() -}) - -test('min constraint', function (assert) { - var expected = hsl(0, -1, 50) - var actual = hsl(0, 0, 50) - var it = '-1% should be the same as 0%' - assert.is(actual, expected, it) - assert.end() -}) diff --git a/Chapter02/publishing-a-module/decentralized-publishing/stay-play/package.json b/Chapter02/publishing-a-module/decentralized-publishing/stay-play/package.json deleted file mode 100644 index 86c3bc5..0000000 --- a/Chapter02/publishing-a-module/decentralized-publishing/stay-play/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "stay-play", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "David Mark Clements", - "license": "MIT" -} diff --git a/Chapter02/publishing-a-module/hsl-to-hex/.gitignore b/Chapter02/publishing-a-module/hsl-to-hex/.gitignore deleted file mode 100644 index eb03e3e..0000000 --- a/Chapter02/publishing-a-module/hsl-to-hex/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -*.log diff --git a/Chapter02/publishing-a-module/hsl-to-hex/example.js b/Chapter02/publishing-a-module/hsl-to-hex/example.js deleted file mode 100644 index cfa65b7..0000000 --- a/Chapter02/publishing-a-module/hsl-to-hex/example.js +++ /dev/null @@ -1,6 +0,0 @@ -var hsl = require('./') -var hue = 133 -var saturation = 40 -var luminosity = 60 -var hex = hsl(hue, saturation, luminosity) -console.log(hex) // #70c282 diff --git a/Chapter02/publishing-a-module/hsl-to-hex/index.js b/Chapter02/publishing-a-module/hsl-to-hex/index.js deleted file mode 100644 index 6a623e7..0000000 --- a/Chapter02/publishing-a-module/hsl-to-hex/index.js +++ /dev/null @@ -1,59 +0,0 @@ -// In our case, there's only one dependency - -var toRgb = require('hsl-to-rgb-for-reals') - -// Typically all dependencies should be declared at the top of the file. - -// Now let's define an API for our module, we're taking hue, saturation and luminosity values and outputting a CSS compatible hex string. -// Hue is in degrees, between 0 and 359. Since degrees a cyclical in nature, we'll support numbers greater than 359 or less than 0 by "spinning" them around until they fall within the 0 to 359 range. -// Saturation and luminosity are both percentages, we'll represent these percentages with whole numbers between 0 and 100. For these numbers we'll need to enforce a maximum and a minimum, anything below 0 will become 0, anything above 100 will become 100. -// Let's write some utility functions to handle this logic: - -function max (val, n) { - return (val > n) ? n : val -} - -function min (val, n) { - return (val < n) ? n : val -} - -function cycle (val) { - // for safety: - val = max(val, 1e7) - val = min(val, -1e7) - // cycle value: - while (val < 0) { val += 360 } - while (val > 359) { val -= 360 } - return val -} - -// Now for the main piece, the `hsl` function: - -function hsl (hue, saturation, luminosity) { - // resolve degrees to 0 - 359 range - hue = cycle(hue) - - // enforce constraints - saturation = min(max(saturation, 100), 0) - luminosity = min(max(luminosity, 100), 0) - - // convert to 0 to 1 range used by hsl-to-rgb-for-reals - saturation /= 100 - luminosity /= 100 - - // let hsl-to-rgb-for-reals do the hard work - var rgb = toRgb(hue, saturation, luminosity) - - // convert each value in the returned RGB array - // to a 2 character hex value, join the array into - // a string, prefixed with a hash - return '#' + rgb - .map(function (n) { - return (256 + n).toString(16).substr(-2) - }) - .join('') -} - -// In order to make our code into a bona fide module we have to export it: - -module.exports = hsl diff --git a/Chapter02/publishing-a-module/hsl-to-hex/package.json b/Chapter02/publishing-a-module/hsl-to-hex/package.json deleted file mode 100644 index 6026529..0000000 --- a/Chapter02/publishing-a-module/hsl-to-hex/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@davidmarkclements/hsl-to-hex", - "version": "1.0.1", - "main": "index.js", - "scripts": { - "test": "npm run lint && tap --cov test", - "lint": "standard" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "Convert HSL colors to RGB colors in hex format.", - "dependencies": { - "hsl-to-rgb-for-reals": "^1.1.0" - }, - "devDependencies": { - "standard": "^6.0.8", - "tap": "^5.7.0" - }, - "directories": { - "test": "test" - } -} diff --git a/Chapter02/publishing-a-module/hsl-to-hex/readme.md b/Chapter02/publishing-a-module/hsl-to-hex/readme.md deleted file mode 100644 index 7343ebf..0000000 --- a/Chapter02/publishing-a-module/hsl-to-hex/readme.md +++ /dev/null @@ -1,32 +0,0 @@ -# hsl-to-hex - -Convert HSL colors to RGB colors in hex format. - -## Install - -```sh -npm install --save @davidmarkclements/hsl-to-hex -``` - -## API - -``` -require('hsl-to-hex') => Function -hsl(hue, saturation, luminosity)` => String -``` - -## Example - -```js -var hsl = require('hsl-to-hex') -var hue = 133 -var saturation = 40 -var luminosity = 60 -var hex = hsl(hue, saturation, luminosity) -console.log(hex) // #70c282 - -``` - -## License - -ISC \ No newline at end of file diff --git a/Chapter02/publishing-a-module/hsl-to-hex/test/index.js b/Chapter02/publishing-a-module/hsl-to-hex/test/index.js deleted file mode 100644 index b355f31..0000000 --- a/Chapter02/publishing-a-module/hsl-to-hex/test/index.js +++ /dev/null @@ -1,74 +0,0 @@ -var hsl = require('../') -var test = require('tap').test - -test('pure white', function (assert) { - var expected = '#ffffff' - var actual = hsl(0, 100, 100) - var it = 'max saturation and luminosity should return pure white' - assert.is(actual, expected, it) - assert.end() -}) - -test('medium gray', function (assert) { - var expected = '#808080' - var actual = hsl(0, 0, 50) - var it = '0% saturation, 50% luminosity should be medium gray' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - red', function (assert) { - var expected = '#ff0000' - var actual = hsl(0, 100, 50) - var it = '0deg should be red' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - blue', function (assert) { - var expected = '#0000ff' - var actual = hsl(240, 100, 50) - var it = '240deg should be blue' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - cyan', function (assert) { - var expected = '#00ffff' - var actual = hsl(180, 100, 50) - var it = '180deg should be cyan' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree overflow', function (assert) { - var expected = hsl(1, 100, 50) - var actual = hsl(361, 100, 50) - var it = '361deg should be the same as 1deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree underflow', function (assert) { - var expected = hsl(-1, 100, 50) - var actual = hsl(359, 100, 50) - var it = '-1deg should be the same as 359deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('max constraint', function (assert) { - var expected = hsl(0, 101, 50) - var actual = hsl(0, 100, 50) - var it = '101% should be the same as 100%' - assert.is(actual, expected, it) - assert.end() -}) - -test('min constraint', function (assert) { - var expected = hsl(0, -1, 50) - var actual = hsl(0, 0, 50) - var it = '-1% should be the same as 0%' - assert.is(actual, expected, it) - assert.end() -}) diff --git a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/.gitignore b/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/.gitignore deleted file mode 100644 index eb03e3e..0000000 --- a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -*.log diff --git a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/example.js b/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/example.js deleted file mode 100644 index cfa65b7..0000000 --- a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/example.js +++ /dev/null @@ -1,6 +0,0 @@ -var hsl = require('./') -var hue = 133 -var saturation = 40 -var luminosity = 60 -var hex = hsl(hue, saturation, luminosity) -console.log(hex) // #70c282 diff --git a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/index.js b/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/index.js deleted file mode 100644 index 3abbdc5..0000000 --- a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/index.js +++ /dev/null @@ -1,66 +0,0 @@ -// In our case, there's only one dependency - -var toRgb = require('hsl-to-rgb-for-reals') -var debug = require('debug')('hsl-to-hex') - -// Typically all dependencies should be declared at the top of the file. - -// Now let's define an API for our module, we're taking hue, saturation and luminosity values and outputting a CSS compatible hex string. -// Hue is in degrees, between 0 and 359. Since degrees a cyclical in nature, we'll support numbers greater than 359 or less than 0 by "spinning" them around until they fall within the 0 to 359 range. -// Saturation and luminosity are both percentages, we'll represent these percentages with whole numbers between 0 and 100. For these numbers we'll need to enforce a maximum and a minimum, anything below 0 will become 0, anything above 100 will become 100. -// Let's write some utility functions to handle this logic: - -function max (val, n) { - debug('ensuring ' + val + ' is no more than ' + n) - return (val > n) ? n : val -} - -function min (val, n) { - debug('ensuring ' + val + ' is no less than ' + n) - return (val < n) ? n : val -} - -function cycle (val) { - debug('resolving ' + val + ' within the 0-359 range') - - // for safety: - val = max(val, 1e7) - val = min(val, -1e7) - // cycle value: - while (val < 0) { val += 360 } - while (val > 359) { val -= 360 } - return val -} - -// Now for the main piece, the `hsl` function: - -function hsl (hue, saturation, luminosity) { - debug('calculating hex for hue: ' + hue + ' saturation: ' + saturation + ' luminosity: ' + luminosity) - - // resolve degrees to 0 - 359 range - hue = cycle(hue) - - // enforce constraints - saturation = min(max(saturation, 100), 0) - luminosity = min(max(luminosity, 100), 0) - - // convert to 0 to 1 range used by hsl-to-rgb-for-reals - saturation /= 100 - luminosity /= 100 - - // let hsl-to-rgb-for-reals do the hard work - var rgb = toRgb(hue, saturation, luminosity) - - // convert each value in the returned RGB array - // to a 2 character hex value, join the array into - // a string, prefixed with a hash - return '#' + rgb - .map(function (n) { - return (256 + n).toString(16).substr(-2) - }) - .join('') -} - -// In order to make our code into a bona fide module we have to export it: - -module.exports = hsl diff --git a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/package.json b/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/package.json deleted file mode 100644 index abe2adb..0000000 --- a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@davidmarkclements/hsl-to-hex", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "npm run lint && tap --cov test", - "lint": "standard" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "Convert HSL colors to RGB colors in hex format.", - "dependencies": { - "hsl-to-rgb-for-reals": "^1.1.0" - }, - "devDependencies": { - "standard": "^6.0.8", - "tap": "^5.7.0" - }, - "directories": { - "test": "test" - } -} diff --git a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/readme.md b/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/readme.md deleted file mode 100644 index a7bdfc2..0000000 --- a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/readme.md +++ /dev/null @@ -1,31 +0,0 @@ -# hsl-to-hex - -Convert HSL colors to RGB colors in hex format. - -## Install - -```sh -npm install --save @davidmarkclements/hsl-to-hex -``` - -## API - -``` -require('hsl-to-hex') => Function -hsl(hue, saturation, luminosity)` => String -``` - -## Example - -```js -var hsl = require('hsl-to-hex') -var hue = 133 -var saturation = 40 -var luminosity = 60 -var hex = hsl(hue, saturation, luminosity) -console.log(hex) // #70c282 -``` - -## License - -ISC \ No newline at end of file diff --git a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/test/index.js b/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/test/index.js deleted file mode 100644 index b355f31..0000000 --- a/Chapter02/publishing-a-module/listing-installed-modules/hsl-to-hex/test/index.js +++ /dev/null @@ -1,74 +0,0 @@ -var hsl = require('../') -var test = require('tap').test - -test('pure white', function (assert) { - var expected = '#ffffff' - var actual = hsl(0, 100, 100) - var it = 'max saturation and luminosity should return pure white' - assert.is(actual, expected, it) - assert.end() -}) - -test('medium gray', function (assert) { - var expected = '#808080' - var actual = hsl(0, 0, 50) - var it = '0% saturation, 50% luminosity should be medium gray' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - red', function (assert) { - var expected = '#ff0000' - var actual = hsl(0, 100, 50) - var it = '0deg should be red' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - blue', function (assert) { - var expected = '#0000ff' - var actual = hsl(240, 100, 50) - var it = '240deg should be blue' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - cyan', function (assert) { - var expected = '#00ffff' - var actual = hsl(180, 100, 50) - var it = '180deg should be cyan' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree overflow', function (assert) { - var expected = hsl(1, 100, 50) - var actual = hsl(361, 100, 50) - var it = '361deg should be the same as 1deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree underflow', function (assert) { - var expected = hsl(-1, 100, 50) - var actual = hsl(359, 100, 50) - var it = '-1deg should be the same as 359deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('max constraint', function (assert) { - var expected = hsl(0, 101, 50) - var actual = hsl(0, 100, 50) - var it = '101% should be the same as 100%' - assert.is(actual, expected, it) - assert.end() -}) - -test('min constraint', function (assert) { - var expected = hsl(0, -1, 50) - var actual = hsl(0, 0, 50) - var it = '-1% should be the same as 0%' - assert.is(actual, expected, it) - assert.end() -}) diff --git a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/.gitignore b/Chapter02/publishing-a-module/prepublish/hsl-to-hex/.gitignore deleted file mode 100644 index eb03e3e..0000000 --- a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -*.log diff --git a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/example.js b/Chapter02/publishing-a-module/prepublish/hsl-to-hex/example.js deleted file mode 100644 index cfa65b7..0000000 --- a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/example.js +++ /dev/null @@ -1,6 +0,0 @@ -var hsl = require('./') -var hue = 133 -var saturation = 40 -var luminosity = 60 -var hex = hsl(hue, saturation, luminosity) -console.log(hex) // #70c282 diff --git a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/index.js b/Chapter02/publishing-a-module/prepublish/hsl-to-hex/index.js deleted file mode 100644 index 3abbdc5..0000000 --- a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/index.js +++ /dev/null @@ -1,66 +0,0 @@ -// In our case, there's only one dependency - -var toRgb = require('hsl-to-rgb-for-reals') -var debug = require('debug')('hsl-to-hex') - -// Typically all dependencies should be declared at the top of the file. - -// Now let's define an API for our module, we're taking hue, saturation and luminosity values and outputting a CSS compatible hex string. -// Hue is in degrees, between 0 and 359. Since degrees a cyclical in nature, we'll support numbers greater than 359 or less than 0 by "spinning" them around until they fall within the 0 to 359 range. -// Saturation and luminosity are both percentages, we'll represent these percentages with whole numbers between 0 and 100. For these numbers we'll need to enforce a maximum and a minimum, anything below 0 will become 0, anything above 100 will become 100. -// Let's write some utility functions to handle this logic: - -function max (val, n) { - debug('ensuring ' + val + ' is no more than ' + n) - return (val > n) ? n : val -} - -function min (val, n) { - debug('ensuring ' + val + ' is no less than ' + n) - return (val < n) ? n : val -} - -function cycle (val) { - debug('resolving ' + val + ' within the 0-359 range') - - // for safety: - val = max(val, 1e7) - val = min(val, -1e7) - // cycle value: - while (val < 0) { val += 360 } - while (val > 359) { val -= 360 } - return val -} - -// Now for the main piece, the `hsl` function: - -function hsl (hue, saturation, luminosity) { - debug('calculating hex for hue: ' + hue + ' saturation: ' + saturation + ' luminosity: ' + luminosity) - - // resolve degrees to 0 - 359 range - hue = cycle(hue) - - // enforce constraints - saturation = min(max(saturation, 100), 0) - luminosity = min(max(luminosity, 100), 0) - - // convert to 0 to 1 range used by hsl-to-rgb-for-reals - saturation /= 100 - luminosity /= 100 - - // let hsl-to-rgb-for-reals do the hard work - var rgb = toRgb(hue, saturation, luminosity) - - // convert each value in the returned RGB array - // to a 2 character hex value, join the array into - // a string, prefixed with a hash - return '#' + rgb - .map(function (n) { - return (256 + n).toString(16).substr(-2) - }) - .join('') -} - -// In order to make our code into a bona fide module we have to export it: - -module.exports = hsl diff --git a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/package.json b/Chapter02/publishing-a-module/prepublish/hsl-to-hex/package.json deleted file mode 100644 index b9449a2..0000000 --- a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@davidmarkclements/hsl-to-hex", - "version": "1.0.1", - "main": "index.js", - "scripts": { - "prepublish": "npm ls && npm test", - "test": "npm run lint && tap --cov test", - "lint": "standard" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "Convert HSL colors to RGB colors in hex format.", - "dependencies": { - "debug": "^2.2.0", - "hsl-to-rgb-for-reals": "^1.1.0" - }, - "devDependencies": { - "standard": "^6.0.8", - "tap": "^5.7.0" - }, - "directories": { - "test": "test" - } -} diff --git a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/readme.md b/Chapter02/publishing-a-module/prepublish/hsl-to-hex/readme.md deleted file mode 100644 index a7bdfc2..0000000 --- a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/readme.md +++ /dev/null @@ -1,31 +0,0 @@ -# hsl-to-hex - -Convert HSL colors to RGB colors in hex format. - -## Install - -```sh -npm install --save @davidmarkclements/hsl-to-hex -``` - -## API - -``` -require('hsl-to-hex') => Function -hsl(hue, saturation, luminosity)` => String -``` - -## Example - -```js -var hsl = require('hsl-to-hex') -var hue = 133 -var saturation = 40 -var luminosity = 60 -var hex = hsl(hue, saturation, luminosity) -console.log(hex) // #70c282 -``` - -## License - -ISC \ No newline at end of file diff --git a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/test/index.js b/Chapter02/publishing-a-module/prepublish/hsl-to-hex/test/index.js deleted file mode 100644 index b355f31..0000000 --- a/Chapter02/publishing-a-module/prepublish/hsl-to-hex/test/index.js +++ /dev/null @@ -1,74 +0,0 @@ -var hsl = require('../') -var test = require('tap').test - -test('pure white', function (assert) { - var expected = '#ffffff' - var actual = hsl(0, 100, 100) - var it = 'max saturation and luminosity should return pure white' - assert.is(actual, expected, it) - assert.end() -}) - -test('medium gray', function (assert) { - var expected = '#808080' - var actual = hsl(0, 0, 50) - var it = '0% saturation, 50% luminosity should be medium gray' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - red', function (assert) { - var expected = '#ff0000' - var actual = hsl(0, 100, 50) - var it = '0deg should be red' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - blue', function (assert) { - var expected = '#0000ff' - var actual = hsl(240, 100, 50) - var it = '240deg should be blue' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - cyan', function (assert) { - var expected = '#00ffff' - var actual = hsl(180, 100, 50) - var it = '180deg should be cyan' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree overflow', function (assert) { - var expected = hsl(1, 100, 50) - var actual = hsl(361, 100, 50) - var it = '361deg should be the same as 1deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree underflow', function (assert) { - var expected = hsl(-1, 100, 50) - var actual = hsl(359, 100, 50) - var it = '-1deg should be the same as 359deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('max constraint', function (assert) { - var expected = hsl(0, 101, 50) - var actual = hsl(0, 100, 50) - var it = '101% should be the same as 100%' - assert.is(actual, expected, it) - assert.end() -}) - -test('min constraint', function (assert) { - var expected = hsl(0, -1, 50) - var actual = hsl(0, 0, 50) - var it = '-1% should be the same as 0%' - assert.is(actual, expected, it) - assert.end() -}) diff --git a/Chapter02/scaffolding-a-module/hsl-to-hex/package.json b/Chapter02/scaffolding-a-module/hsl-to-hex/package.json deleted file mode 100644 index 3386883..0000000 --- a/Chapter02/scaffolding-a-module/hsl-to-hex/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "hsl-to-hex", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "" -} diff --git a/Chapter02/scaffolding-a-module/reinitializing/hsl-to-hex/.gitignore b/Chapter02/scaffolding-a-module/reinitializing/hsl-to-hex/.gitignore deleted file mode 100644 index eb03e3e..0000000 --- a/Chapter02/scaffolding-a-module/reinitializing/hsl-to-hex/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -*.log diff --git a/Chapter02/scaffolding-a-module/reinitializing/hsl-to-hex/package.json b/Chapter02/scaffolding-a-module/reinitializing/hsl-to-hex/package.json deleted file mode 100644 index 3386883..0000000 --- a/Chapter02/scaffolding-a-module/reinitializing/hsl-to-hex/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "hsl-to-hex", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "" -} diff --git a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/.gitignore b/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/.gitignore deleted file mode 100644 index eb03e3e..0000000 --- a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -*.log diff --git a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/example.js b/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/example.js deleted file mode 100644 index cfa65b7..0000000 --- a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/example.js +++ /dev/null @@ -1,6 +0,0 @@ -var hsl = require('./') -var hue = 133 -var saturation = 40 -var luminosity = 60 -var hex = hsl(hue, saturation, luminosity) -console.log(hex) // #70c282 diff --git a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/index.js b/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/index.js deleted file mode 100644 index 3abbdc5..0000000 --- a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/index.js +++ /dev/null @@ -1,66 +0,0 @@ -// In our case, there's only one dependency - -var toRgb = require('hsl-to-rgb-for-reals') -var debug = require('debug')('hsl-to-hex') - -// Typically all dependencies should be declared at the top of the file. - -// Now let's define an API for our module, we're taking hue, saturation and luminosity values and outputting a CSS compatible hex string. -// Hue is in degrees, between 0 and 359. Since degrees a cyclical in nature, we'll support numbers greater than 359 or less than 0 by "spinning" them around until they fall within the 0 to 359 range. -// Saturation and luminosity are both percentages, we'll represent these percentages with whole numbers between 0 and 100. For these numbers we'll need to enforce a maximum and a minimum, anything below 0 will become 0, anything above 100 will become 100. -// Let's write some utility functions to handle this logic: - -function max (val, n) { - debug('ensuring ' + val + ' is no more than ' + n) - return (val > n) ? n : val -} - -function min (val, n) { - debug('ensuring ' + val + ' is no less than ' + n) - return (val < n) ? n : val -} - -function cycle (val) { - debug('resolving ' + val + ' within the 0-359 range') - - // for safety: - val = max(val, 1e7) - val = min(val, -1e7) - // cycle value: - while (val < 0) { val += 360 } - while (val > 359) { val -= 360 } - return val -} - -// Now for the main piece, the `hsl` function: - -function hsl (hue, saturation, luminosity) { - debug('calculating hex for hue: ' + hue + ' saturation: ' + saturation + ' luminosity: ' + luminosity) - - // resolve degrees to 0 - 359 range - hue = cycle(hue) - - // enforce constraints - saturation = min(max(saturation, 100), 0) - luminosity = min(max(luminosity, 100), 0) - - // convert to 0 to 1 range used by hsl-to-rgb-for-reals - saturation /= 100 - luminosity /= 100 - - // let hsl-to-rgb-for-reals do the hard work - var rgb = toRgb(hue, saturation, luminosity) - - // convert each value in the returned RGB array - // to a 2 character hex value, join the array into - // a string, prefixed with a hash - return '#' + rgb - .map(function (n) { - return (256 + n).toString(16).substr(-2) - }) - .join('') -} - -// In order to make our code into a bona fide module we have to export it: - -module.exports = hsl diff --git a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/package.json b/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/package.json deleted file mode 100644 index 05a6253..0000000 --- a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@ncb/hsl-to-hex", - "version": "1.0.1", - "main": "index.js", - "scripts": { - "check": "npm ls && npm test", - "test": "npm run lint && tap --cov test", - "lint": "standard", - "prepublish": "npm run check && ./publish-dep.sh" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "Convert HSL colors to RGB colors in hex format.", - "dependencies": { - "debug": "^2.2.0", - "hsl-to-rgb-for-reals": "^1.1.0" - }, - "devDependencies": { - "standard": "^6.0.8", - "tap": "^5.7.0" - }, - "directories": { - "test": "test" - } -} diff --git a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/publish-dep.sh b/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/publish-dep.sh deleted file mode 100644 index 7d27a99..0000000 --- a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/publish-dep.sh +++ /dev/null @@ -1,50 +0,0 @@ -#! /bin/sh - -# 400 - Missing hash and/or peer_id -# 403 - Not allowed -# 413 - Too big -# 200 - Ok! - - -if echo $npm_config_argv | grep -q "install"; then - echo "Running at install step, skipping" -else - if ipfs &>/dev/null; then - echo "## Publishing dependency" - - mv node_modules .node_modules 2>/dev/null - - HASH=$(ipfs add . -r | tail -n 1 | cut -d ' ' -f 2) - - mv .node_modules node_modules 2>/dev/null - - echo "Published as $HASH" - - PEER=$(ipfs id --format '') - - if [ -f ~/.stay/nodes.json ]; then - cat ~/.stay/nodes.json | jq -rc '.[]' | while read host; do - address="$host/api/pin/add/$HASH/$PEER" - status=$(curl -X POST --silent $address) - case "$status" in - "400") echo "$host - Application Error: Missing the hash and/or peer_id" - ;; - "403") echo "$host - You do not have access to pinning at this node" - ;; - "413") echo "$host - The module was too big to pin!" - ;; - "200") echo "$host - Pinned!" - ;; - *) echo "Weird status code $status for $host" - ;; - esac - done - else - echo "You don't have any saved nodes in ~/.stay/nodes.json, skip pinning" - fi - else - echo "## Could not publish dependency to IPFS, doing the good'ol 'fetch from npm registry' way" - echo "Either 'ipfs' doesn't exists in PATH or you haven't run 'ipfs daemon' before running the command" - exit 0 - fi -fi diff --git a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/readme.md b/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/readme.md deleted file mode 100644 index a7bdfc2..0000000 --- a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/readme.md +++ /dev/null @@ -1,31 +0,0 @@ -# hsl-to-hex - -Convert HSL colors to RGB colors in hex format. - -## Install - -```sh -npm install --save @davidmarkclements/hsl-to-hex -``` - -## API - -``` -require('hsl-to-hex') => Function -hsl(hue, saturation, luminosity)` => String -``` - -## Example - -```js -var hsl = require('hsl-to-hex') -var hue = 133 -var saturation = 40 -var luminosity = 60 -var hex = hsl(hue, saturation, luminosity) -console.log(hex) // #70c282 -``` - -## License - -ISC \ No newline at end of file diff --git a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/test/index.js b/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/test/index.js deleted file mode 100644 index b355f31..0000000 --- a/Chapter02/using-a-private-repository/scope-registries/hsl-to-hex/test/index.js +++ /dev/null @@ -1,74 +0,0 @@ -var hsl = require('../') -var test = require('tap').test - -test('pure white', function (assert) { - var expected = '#ffffff' - var actual = hsl(0, 100, 100) - var it = 'max saturation and luminosity should return pure white' - assert.is(actual, expected, it) - assert.end() -}) - -test('medium gray', function (assert) { - var expected = '#808080' - var actual = hsl(0, 0, 50) - var it = '0% saturation, 50% luminosity should be medium gray' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - red', function (assert) { - var expected = '#ff0000' - var actual = hsl(0, 100, 50) - var it = '0deg should be red' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - blue', function (assert) { - var expected = '#0000ff' - var actual = hsl(240, 100, 50) - var it = '240deg should be blue' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - cyan', function (assert) { - var expected = '#00ffff' - var actual = hsl(180, 100, 50) - var it = '180deg should be cyan' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree overflow', function (assert) { - var expected = hsl(1, 100, 50) - var actual = hsl(361, 100, 50) - var it = '361deg should be the same as 1deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree underflow', function (assert) { - var expected = hsl(-1, 100, 50) - var actual = hsl(359, 100, 50) - var it = '-1deg should be the same as 359deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('max constraint', function (assert) { - var expected = hsl(0, 101, 50) - var actual = hsl(0, 100, 50) - var it = '101% should be the same as 100%' - assert.is(actual, expected, it) - assert.end() -}) - -test('min constraint', function (assert) { - var expected = hsl(0, -1, 50) - var actual = hsl(0, 0, 50) - var it = '-1% should be the same as 0%' - assert.is(actual, expected, it) - assert.end() -}) diff --git a/Chapter02/working-with-files/.DS_Store b/Chapter02/working-with-files/.DS_Store new file mode 100644 index 0000000..3e4cff2 Binary files /dev/null and b/Chapter02/working-with-files/.DS_Store differ diff --git a/Chapter02/working-with-files/callback-hell.js b/Chapter02/working-with-files/callback-hell.js new file mode 100644 index 0000000..04cbf4d --- /dev/null +++ b/Chapter02/working-with-files/callback-hell.js @@ -0,0 +1,5 @@ +first(args, function () { + second(args, function () { + third(args, function () {}) + }) +}) \ No newline at end of file diff --git a/Chapter02/working-with-files/hello.txt b/Chapter02/working-with-files/hello.txt new file mode 100644 index 0000000..428b97b --- /dev/null +++ b/Chapter02/working-with-files/hello.txt @@ -0,0 +1 @@ +HELLO WORLD! diff --git a/Chapter02/working-with-files/readWriteAsync.js b/Chapter02/working-with-files/readWriteAsync.js new file mode 100644 index 0000000..44bc0a9 --- /dev/null +++ b/Chapter02/working-with-files/readWriteAsync.js @@ -0,0 +1,16 @@ +const fs = require('fs'); +const path = require('path') + +const filepath = path.join(process.cwd(), 'hello.txt'); + +fs.readFile(filepath, 'utf8', function (err, contents) { + if (err) { + return console.log(err); + } + console.log("File Contents:", contents); + contents = contents.toUpperCase(); + fs.writeFile(filepath, contents, function (err) { + if (err) throw err; + console.log("File updated.") + }); +}); diff --git a/Chapter02/working-with-files/readWriteAsync2.js b/Chapter02/working-with-files/readWriteAsync2.js new file mode 100644 index 0000000..e45a9fb --- /dev/null +++ b/Chapter02/working-with-files/readWriteAsync2.js @@ -0,0 +1,20 @@ +const fs = require('fs'); +const path = require('path') + +const filepath = path.join(process.cwd(), 'hello.txt'); + +fs.readFile(filepath, 'utf8', function (err, contents) { + if (err) { + return console.log(err); + } + console.log("File Contents:", contents); + contents = contents.toUpperCase(); + updateFile(filepath, contents); +}); + +function updateFile(filepath, contents) { + fs.writeFile(filepath, contents, function (err) { + if (err) throw err; + console.log("File updated."); + }); +}; \ No newline at end of file diff --git a/Chapter02/working-with-files/readWritePromise.js b/Chapter02/working-with-files/readWritePromise.js new file mode 100644 index 0000000..ecc474d --- /dev/null +++ b/Chapter02/working-with-files/readWritePromise.js @@ -0,0 +1,15 @@ +const fs = require("fs").promises; +const path = require('path'); + +const filepath = path.join(process.cwd(), 'hello.txt'); + +async function run() { + try { + const contents = await fs.readFile(filepath, 'utf8'); + console.log("File Contents:", contents); + } catch (error) { + console.error(error); + } +}; + +run(); \ No newline at end of file diff --git a/Chapter02/working-with-files/readWriteSync.js b/Chapter02/working-with-files/readWriteSync.js new file mode 100644 index 0000000..2f1ebd9 --- /dev/null +++ b/Chapter02/working-with-files/readWriteSync.js @@ -0,0 +1,12 @@ +const fs = require('fs'); +const path = require('path'); + +const filepath = path.join(process.cwd(), 'hello.txt'); + +let contents = fs.readFileSync(filepath, 'utf8'); +console.log("File Contents:", contents); + +contents = contents.toString().toUpperCase(); + +fs.writeFileSync(filepath, contents); +console.log("File updated."); diff --git a/Chapter02/writing-module-code/adding-tests/hsl-to-hex/index.js b/Chapter02/writing-module-code/adding-tests/hsl-to-hex/index.js deleted file mode 100644 index 6a623e7..0000000 --- a/Chapter02/writing-module-code/adding-tests/hsl-to-hex/index.js +++ /dev/null @@ -1,59 +0,0 @@ -// In our case, there's only one dependency - -var toRgb = require('hsl-to-rgb-for-reals') - -// Typically all dependencies should be declared at the top of the file. - -// Now let's define an API for our module, we're taking hue, saturation and luminosity values and outputting a CSS compatible hex string. -// Hue is in degrees, between 0 and 359. Since degrees a cyclical in nature, we'll support numbers greater than 359 or less than 0 by "spinning" them around until they fall within the 0 to 359 range. -// Saturation and luminosity are both percentages, we'll represent these percentages with whole numbers between 0 and 100. For these numbers we'll need to enforce a maximum and a minimum, anything below 0 will become 0, anything above 100 will become 100. -// Let's write some utility functions to handle this logic: - -function max (val, n) { - return (val > n) ? n : val -} - -function min (val, n) { - return (val < n) ? n : val -} - -function cycle (val) { - // for safety: - val = max(val, 1e7) - val = min(val, -1e7) - // cycle value: - while (val < 0) { val += 360 } - while (val > 359) { val -= 360 } - return val -} - -// Now for the main piece, the `hsl` function: - -function hsl (hue, saturation, luminosity) { - // resolve degrees to 0 - 359 range - hue = cycle(hue) - - // enforce constraints - saturation = min(max(saturation, 100), 0) - luminosity = min(max(luminosity, 100), 0) - - // convert to 0 to 1 range used by hsl-to-rgb-for-reals - saturation /= 100 - luminosity /= 100 - - // let hsl-to-rgb-for-reals do the hard work - var rgb = toRgb(hue, saturation, luminosity) - - // convert each value in the returned RGB array - // to a 2 character hex value, join the array into - // a string, prefixed with a hash - return '#' + rgb - .map(function (n) { - return (256 + n).toString(16).substr(-2) - }) - .join('') -} - -// In order to make our code into a bona fide module we have to export it: - -module.exports = hsl diff --git a/Chapter02/writing-module-code/adding-tests/hsl-to-hex/package.json b/Chapter02/writing-module-code/adding-tests/hsl-to-hex/package.json deleted file mode 100644 index e736a7d..0000000 --- a/Chapter02/writing-module-code/adding-tests/hsl-to-hex/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "hsl-to-hex", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "npm run lint && tap --cov test", - "lint": "standard" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "", - "dependencies": { - "hsl-to-rgb-for-reals": "^1.1.0" - }, - "devDependencies": { - "standard": "^6.0.8", - "tap": "^5.7.0" - } -} diff --git a/Chapter02/writing-module-code/adding-tests/hsl-to-hex/test/index.js b/Chapter02/writing-module-code/adding-tests/hsl-to-hex/test/index.js deleted file mode 100644 index b355f31..0000000 --- a/Chapter02/writing-module-code/adding-tests/hsl-to-hex/test/index.js +++ /dev/null @@ -1,74 +0,0 @@ -var hsl = require('../') -var test = require('tap').test - -test('pure white', function (assert) { - var expected = '#ffffff' - var actual = hsl(0, 100, 100) - var it = 'max saturation and luminosity should return pure white' - assert.is(actual, expected, it) - assert.end() -}) - -test('medium gray', function (assert) { - var expected = '#808080' - var actual = hsl(0, 0, 50) - var it = '0% saturation, 50% luminosity should be medium gray' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - red', function (assert) { - var expected = '#ff0000' - var actual = hsl(0, 100, 50) - var it = '0deg should be red' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - blue', function (assert) { - var expected = '#0000ff' - var actual = hsl(240, 100, 50) - var it = '240deg should be blue' - assert.is(actual, expected, it) - assert.end() -}) - -test('hue - cyan', function (assert) { - var expected = '#00ffff' - var actual = hsl(180, 100, 50) - var it = '180deg should be cyan' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree overflow', function (assert) { - var expected = hsl(1, 100, 50) - var actual = hsl(361, 100, 50) - var it = '361deg should be the same as 1deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('degree underflow', function (assert) { - var expected = hsl(-1, 100, 50) - var actual = hsl(359, 100, 50) - var it = '-1deg should be the same as 359deg' - assert.is(actual, expected, it) - assert.end() -}) - -test('max constraint', function (assert) { - var expected = hsl(0, 101, 50) - var actual = hsl(0, 100, 50) - var it = '101% should be the same as 100%' - assert.is(actual, expected, it) - assert.end() -}) - -test('min constraint', function (assert) { - var expected = hsl(0, -1, 50) - var actual = hsl(0, 0, 50) - var it = '-1% should be the same as 0%' - assert.is(actual, expected, it) - assert.end() -}) diff --git a/Chapter02/writing-module-code/hsl-to-hex/index.js b/Chapter02/writing-module-code/hsl-to-hex/index.js deleted file mode 100644 index 6a623e7..0000000 --- a/Chapter02/writing-module-code/hsl-to-hex/index.js +++ /dev/null @@ -1,59 +0,0 @@ -// In our case, there's only one dependency - -var toRgb = require('hsl-to-rgb-for-reals') - -// Typically all dependencies should be declared at the top of the file. - -// Now let's define an API for our module, we're taking hue, saturation and luminosity values and outputting a CSS compatible hex string. -// Hue is in degrees, between 0 and 359. Since degrees a cyclical in nature, we'll support numbers greater than 359 or less than 0 by "spinning" them around until they fall within the 0 to 359 range. -// Saturation and luminosity are both percentages, we'll represent these percentages with whole numbers between 0 and 100. For these numbers we'll need to enforce a maximum and a minimum, anything below 0 will become 0, anything above 100 will become 100. -// Let's write some utility functions to handle this logic: - -function max (val, n) { - return (val > n) ? n : val -} - -function min (val, n) { - return (val < n) ? n : val -} - -function cycle (val) { - // for safety: - val = max(val, 1e7) - val = min(val, -1e7) - // cycle value: - while (val < 0) { val += 360 } - while (val > 359) { val -= 360 } - return val -} - -// Now for the main piece, the `hsl` function: - -function hsl (hue, saturation, luminosity) { - // resolve degrees to 0 - 359 range - hue = cycle(hue) - - // enforce constraints - saturation = min(max(saturation, 100), 0) - luminosity = min(max(luminosity, 100), 0) - - // convert to 0 to 1 range used by hsl-to-rgb-for-reals - saturation /= 100 - luminosity /= 100 - - // let hsl-to-rgb-for-reals do the hard work - var rgb = toRgb(hue, saturation, luminosity) - - // convert each value in the returned RGB array - // to a 2 character hex value, join the array into - // a string, prefixed with a hash - return '#' + rgb - .map(function (n) { - return (256 + n).toString(16).substr(-2) - }) - .join('') -} - -// In order to make our code into a bona fide module we have to export it: - -module.exports = hsl diff --git a/Chapter02/writing-module-code/hsl-to-hex/package.json b/Chapter02/writing-module-code/hsl-to-hex/package.json deleted file mode 100644 index 5169107..0000000 --- a/Chapter02/writing-module-code/hsl-to-hex/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "hsl-to-hex", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "npm run lint", - "lint": "standard" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "", - "dependencies": { - "hsl-to-rgb-for-reals": "^1.1.0" - }, - "devDependencies": { - "standard": "^6.0.8" - } -} diff --git a/Chapter02/writing-module-code/modernizing-syntax/hsl-to-hex/index.js b/Chapter02/writing-module-code/modernizing-syntax/hsl-to-hex/index.js deleted file mode 100644 index 6a623e7..0000000 --- a/Chapter02/writing-module-code/modernizing-syntax/hsl-to-hex/index.js +++ /dev/null @@ -1,59 +0,0 @@ -// In our case, there's only one dependency - -var toRgb = require('hsl-to-rgb-for-reals') - -// Typically all dependencies should be declared at the top of the file. - -// Now let's define an API for our module, we're taking hue, saturation and luminosity values and outputting a CSS compatible hex string. -// Hue is in degrees, between 0 and 359. Since degrees a cyclical in nature, we'll support numbers greater than 359 or less than 0 by "spinning" them around until they fall within the 0 to 359 range. -// Saturation and luminosity are both percentages, we'll represent these percentages with whole numbers between 0 and 100. For these numbers we'll need to enforce a maximum and a minimum, anything below 0 will become 0, anything above 100 will become 100. -// Let's write some utility functions to handle this logic: - -function max (val, n) { - return (val > n) ? n : val -} - -function min (val, n) { - return (val < n) ? n : val -} - -function cycle (val) { - // for safety: - val = max(val, 1e7) - val = min(val, -1e7) - // cycle value: - while (val < 0) { val += 360 } - while (val > 359) { val -= 360 } - return val -} - -// Now for the main piece, the `hsl` function: - -function hsl (hue, saturation, luminosity) { - // resolve degrees to 0 - 359 range - hue = cycle(hue) - - // enforce constraints - saturation = min(max(saturation, 100), 0) - luminosity = min(max(luminosity, 100), 0) - - // convert to 0 to 1 range used by hsl-to-rgb-for-reals - saturation /= 100 - luminosity /= 100 - - // let hsl-to-rgb-for-reals do the hard work - var rgb = toRgb(hue, saturation, luminosity) - - // convert each value in the returned RGB array - // to a 2 character hex value, join the array into - // a string, prefixed with a hash - return '#' + rgb - .map(function (n) { - return (256 + n).toString(16).substr(-2) - }) - .join('') -} - -// In order to make our code into a bona fide module we have to export it: - -module.exports = hsl diff --git a/Chapter02/writing-module-code/modernizing-syntax/hsl-to-hex/package.json b/Chapter02/writing-module-code/modernizing-syntax/hsl-to-hex/package.json deleted file mode 100644 index 1a965c4..0000000 --- a/Chapter02/writing-module-code/modernizing-syntax/hsl-to-hex/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "hsl-to-hex", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "npm run lint && tap --node-arg='--harmony-destructuring' --cov test", - "lint": "standard" - }, - "author": "David Mark Clements", - "license": "ISC", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/davidmarkclements/hsl-to-hex.git" - }, - "bugs": { - "url": "https://github.com/davidmarkclements/hsl-to-hex/issues" - }, - "homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme", - "description": "", - "dependencies": { - "hsl-to-rgb-for-reals": "^1.1.0" - }, - "devDependencies": { - "standard": "^6.0.8", - "tap": "^5.7.0" - } -} diff --git a/Chapter02/writing-module-code/modernizing-syntax/hsl-to-hex/test/index.js b/Chapter02/writing-module-code/modernizing-syntax/hsl-to-hex/test/index.js deleted file mode 100644 index 8b0f99a..0000000 --- a/Chapter02/writing-module-code/modernizing-syntax/hsl-to-hex/test/index.js +++ /dev/null @@ -1,90 +0,0 @@ -const hsl = require('../') -const {test} = require('tap') - -test('pure white', ({is, end}) => { - const expected = '#ffffff' - const actual = hsl(0, 100, 100) - const it = ` - max saturation and luminosity should return pure white - ` - is(actual, expected, it) - end() -}) - -test('medium gray', ({is, end}) => { - const expected = '#808080' - const actual = hsl(0, 0, 50) - const it = ` - 0% saturation, 50% luminosity should be medium gray - ` - is(actual, expected, it) - end() -}) - -test('hue', ({is, end}) => { - { - const expected = '#ff0000' - const actual = hsl(0, 100, 50) - const it = ` - 0deg should be red - ` - is(actual, expected, it) - } - { - const expected = '#0000ff' - const actual = hsl(240, 100, 50) - const it = ` - 240deg should be blue - ` - is(actual, expected, it) - } - { - const expected = '#00ffff' - const actual = hsl(180, 100, 50) - const it = ` - 180deg should be cyan - ` - is(actual, expected, it) - } - end() -}) - -test('degree overflow/underflow', ({is, end}) => { - { - const expected = hsl(1, 100, 50) - const actual = hsl(361, 100, 50) - const it = ` - 361deg should be the same as 1deg - ` - is(actual, expected, it) - } - { - const expected = hsl(-1, 100, 50) - const actual = hsl(359, 100, 50) - const it = ` - -1deg should be the same as 359deg - ` - is(actual, expected, it) - } - end() -}) - -test('max constraint', ({is, end}) => { - { - const expected = hsl(0, 101, 50) - const actual = hsl(0, 100, 50) - const it = ` - 101% should be the same as 100% - ` - is(actual, expected, it) - } - { - const expected = hsl(0, -1, 50) - const actual = hsl(0, 0, 50) - const it = ` - -1% should be the same as 0% - ` - is(actual, expected, it) - } - end() -})