Support
Quality
Security
License
Reuse
kandi has reviewed xkcd-password and discovered the below as its top functions. This is intended to give you an instant insight into xkcd-password implemented functionality, and help decide if they suit your requirements.
Get all kandi verified functions for this library.
Get all kandi verified functions for this library.
A password generator inspired by the xkcd password spec: http://xkcd.com/936/
See all related Code Snippets
QUESTION
Function returning undefined from a promise
Asked 2017-Mar-14 at 02:19I'm trying to make a function that returns an xkcd password like this: bat-ship-eight-loophole
. The library can be found here: https://github.com/fardog/node-xkcd-password
Here is my code:
var xkcdPassword = require('xkcd-password')
var pw = new xkcdPassword()
var options = {
numWords: 4,
minLength: 5,
maxLength: 8
}
// or, with promises
function generateCode() {
pw.generate(options).then(function (result) {
return "hello"
})
}
console.log(generateCode())
I don't think my issue has anything to do with the library though
ANSWER
Answered 2017-Mar-14 at 02:19Promises are a way to represent asynchronous operations which potentially haven't completed yet. In order to get the output, you have to make your function return the promise, and use then
to add a callback function that takes the output.
function generateCode() {
return pw.generate(options);
}
generateCode().then(function(code) {
console.log(code);
});
// pw.generate(options).then(console.log); // also works in this case
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Find more information at:
Save this library and start creating your kit
See Similar Libraries in
Save this library and start creating your kit
Open Weaver – Develop Applications Faster with Open Source