Skip to content

Add playground examples #3667

@ikatyang

Description

@ikatyang

Add examples to getExample():

function getExample(parser) {
switch (parser) {
case "babylon":
return [
'function HelloWorld({greeting = "hello", greeted = \'"World"\', silent = false, onMouseOver,}) {',
"",
" if(!greeting){return null};",
"",
" // TODO: Don't use random in render",
' let num = Math.floor (Math.random() * 1E+7).toString().replace(/\\.\\d+/ig, "")',
"",
" return <div className='HelloWorld' title={`You are visitor number ${ num }`} onMouseOver={onMouseOver}>",
"",
" <strong>{ greeting.slice( 0, 1 ).toUpperCase() + greeting.slice(1).toLowerCase() }</strong>",
' {greeting.endsWith(",") ? " " : <span style={{color: \'\\grey\'}}>", "</span> }',
" <em>",
"\t{ greeted }",
"\t</em>",
" { (silent)",
' ? "."',
' : "!"}',
"",
" </div>;",
"",
"}"
].join("\n");

  • JavaScript (babylon)
  • JavaScript (flow)
  • TypeScript (typescript)
  • CSS (css)
  • Less (less)
  • SCSS (scss)
  • JSON (json)
  • GraphQL (graphql)
  • Markdown (markdown)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:playgroundIssues about the playground (https://prettier.io/playground)difficulty:easyIssues that should be easy to fix. Resolve me on the train to work!help wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.type:docsIssues about adding or improving documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions