Skip to content

Repository files navigation

Prettier.swift

Version License Platform codecov

Prettier.io wrapper for swift. An opinionated code formatter.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

Prettier.swift is available via SPM or Cocoapods.

pod 'Prettier.swift'

How to use

JSON

import Prettier_swift

let prettier = Prettier()
let input = "{\"id\":1,\"name\":\"Michael Henry\"}"
let output = prettier.prettify(input, parser: .jsonStringify)!

let expected_output =
"""
{
  "id": 1,
  "name": "Michael Henry"
}

"""
XCTAssertEqual(output, expected_output)

HTML

import Prettier_swift

let prettier = Prettier()
let input = "<html><body><p>hello</p></body></html>"
let output = prettier.prettify(input, parser: .html)!

let expected_output =
"""
<html>
  <body>
    <p>hello</p>
  </body>
</html>

"""

XCTAssertEqual(output, expected_output)

GRAPHQL

import Prettier_swift

let prettier = Prettier()
let input = "{human(id:\"1000\"){name height}}"
let output = prettier.prettify(input, parser: .graphql)

let expected_output =
"""
{
  human(id: "1000") {
    name
    height
  }
}

"""
XCTAssertEqual(output, expected_output)

AND MORE!

License

Prettier.swift is available under the MIT license. See the LICENSE file for more info.

About

Prettier.io wrapper for swift. An opinionated code formatter.

Topics

Resources

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages