From a998da981036ed26e5c81ac6b3c22ff2a92bf99a Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Fri, 1 Jun 2018 11:58:50 +0530 Subject: [PATCH] [init] --- .gitignore | 1 + .vscode/launch.json | 14 ++++++++++++++ es6/index.js | 1 + package-lock.json | 5 +++++ package.json | 15 +++++++++++++++ test.js | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 es6/index.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 test.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e8f6960 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/test.js" + } + ] +} \ No newline at end of file diff --git a/es6/index.js b/es6/index.js new file mode 100644 index 0000000..a2b4fcd --- /dev/null +++ b/es6/index.js @@ -0,0 +1 @@ +module.exports = require('../index.js'); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..2e0d9ed --- /dev/null +++ b/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "@codefeathers/promise.object", + "version": "0.0.1", + "lockfileVersion": 1 +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..58185c4 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "@codefeathers/promise.object", + "version": "0.0.1", + "description": "Deep resolving promises in objects.", + "main": "es6/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Muthu Kumar <@MKRhere> (https://mkr.pw)", + "contributors": [ + "Thomas Rory Gummerson <@TRGWII> (https://rory.no)" + ], + "license": "MIT" +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..050196d --- /dev/null +++ b/test.js @@ -0,0 +1,33 @@ +Promise.object = require('./es6'); +const assert = require('assert'); + +const linked = { + foo: Promise.resolve(1), + bar: { + foobar: Promise.resolve(2) + }, + baz: [1, "two", Promise.resolve(3)], + ok: "four" +} + +linked.linked = linked; + +Promise.object(linked).then(x => { + console.log(x); + assert(x.foo === 1); + assert(x.bar.foobar === 2); + assert(x.baz[0] === 1 && x.baz[1] === "two"); + assert(Array.isArray(x.baz) && x.baz[2] === 3); + assert(x.linked === x); +}); + +Promise.object( + Promise.resolve({ + foo: Promise.resolve({ + bar: Promise.resolve(4) + }) + }) +).then(x => { + console.log(x) + assert(x.foo.bar === 4); +}); \ No newline at end of file