![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
wizard
Advanced tools
Readme
npm install wizard
import Wizard from 'wizard';
import questions from './questions';
const wizard = new Wizard(questions);
wizard.init().then(selections => {
console.log(selections);
process.exit();
});
Wizard(questions, [styles, components])
Wizard
represents a new setup wizard.wizard.init() -> Promise<Object>
init
initializes your setup wizard.selection
object.The Questions Object represents every step of your setup wizard. It is an infinitely nested object representing the flow of choices from the first question, to the last.
Every section
of the Questions Object must have the following fields:
Depending on the input type, you may be required to have:
option
) All options for a question (List & ListToggle inputs).
Example:
{
question: 'My question',
id: 'my-question',
type: 'list',
options: [
{ name: 'Answer 1', value: 'answer-1', then: 'question2' },
{ name: 'Answer 2', value: 'answer-2', then: 'question3' },
],
then: {
question2: {
question: 'Question 2',
id: 'question-2',
type: 'list',
options: [
{ name: 'Answer 1', value: 'answer-1' },
{ name: 'Answer 2', value: 'answer-2' },
]
},
question3: {
question: 'Question 3',
id: 'question-3',
type: 'list',
options: [
{ name: 'Answer 1', value: 'answer-1' },
{ name: 'Answer 2', value: 'answer-2' },
{ name: 'Answer 3', value: 'answer-3' },
{ name: 'Answer 4', value: 'answer-4' },
]
}
}
}
The styles object is passed in on the creation of the wizard. There are defaults that will be overridden.
{
preserveAnswer: bool - Preserve the previous question when finished
question: {
color: function - The color of the question
prefex: string - Question text prefix
paddingLeft: int - Left padding for question
}
caret : {
icon: string - The character representing the caret
color: function - The color of the caret
paddingRight: int - Right padding for the caret
paddingLeft: int - Left padding for the caret
}
list: {
wrapToTop: bool - Whether the caret wraps to top
defaultColor: function - The color of non-selected items
selectedColor: function - The color of currently selected item
toggledColor: function - The color of toggled items
paddingLeft: int - Left padding for the whole list
toggle: {
icon: string - The character representing selected items
color: function - The color of the selected item icon
paddingRight: int - Right padding for the selected icon
paddingLeft: int - Left padding for the selected icon
}
}
}
Right now Wizard includes the following input types:
List
- A list of choices, select one with Enter
list
in your questions object: type: 'list'
ListToggle
- A list of choices, select multiple with Space
listToggle
in your questions object: type: 'listToggle'
You can make your very own personalized inputs if the ones provided don't suit your needs. A Component
class is available by importing it - import { Component } from 'wizard
. It provides a number of methods and events to extend wizard however you wish.
Each Input must have an init
and an update
method.
To create a basic component:
import { Component } from 'wizard';
class MyComponent extends Component {
constructor() {
super();
}
init() {
return new Promise(resolve => {
this.onKeySpace = () => {
this.write('Space Pressed!');
}
this.initialize('My new input!');
});
}
update() {}
}
Now import it and use it:
import Wizard from 'wizard';
import MyComponent from './MyComponent';
const question = {
question: 'Press space: ',
id: 'space',
type: 'myComponent',
};
const main = async () => {
const wizard = new Wizard(questions, {}, { myComponent: MyComponent });
const selections = await wizard.init();
console.log(selections);
};
The Component
class provides a number of methods to use when creating your input.
initialize(question)
Initialize the component.write(text)
Write string to screen.newline()
Write a newline to the screen.clear()
Clear the components output.cleanAndExit()
Restore the cursor and gracefully exit.A number of keyPress
events can be handled. The only manditory handler is for onKeyEnter
. This must resolve the component and clear the screen for the next question. The following event handlers are available:
onKeyEnter
onKeyUp
onKeyDown
onKeyLeft
onKeyRight
onKeySpace
Example:
this.onKeyEnter = () => {
this.clear();
resolve('test');
}
We use the chalk
library for coloring, and ansi-escapes
for cursor manipulation. Access them through this.color
and this.ansi
respectively.
FAQs
Wizard is a highly configurable library for building complex CLI based installation/setup wizards
The npm package wizard receives a total of 33 weekly downloads. As such, wizard popularity was classified as not popular.
We found that wizard demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.