Git Product home page Git Product logo

loremswiftify's Introduction

LoremSwiftify

Features

  • Support class (nesting is supported as well)
  • Support struct (nesting is supported as well)
  • Support enum (nesting is supported as well)
  • Support commonly used types
    • String
    • Int, Int8, Int16, Int32, Int64
    • UInt, UInt8, UInt16, UInt32, UInt64
    • Double, Float
    • Bool
    • Array
    • Dictionary
    • Optional
    • Date
    • URL
    • Color
  • Custom types supported if it's annotated with macro or confirms LoremIpsumize protocol
  • Add #if DEBUG
  • Create Example SwiftUI project to demonstrate package usage for previews
  • Provide a way to customize lorem in different categories (like creditCard, phoneNumber, name, price etc..) (works for auto generated init)
  • Provide a way to customize loreming for the supported built-in types (to completely determine what to receive for the lorem data)
  • Improve diagnostic
  • Implement unit test

See example project

Example


  • Annotate any struct, class or enum with @LoremSwiftify

Then use StructName.lorem() or ClassName.lorem() or EnumName.lorem(). Basically .lorem() everywhere :)

import LoremSwiftify

@LoremSwiftify
class Book {
    let name: String
    let published: Date
    let author: Author

    init(name: String, published: Date, author: Author) {
        self.name = name
        self.published = published
        self.author = author
    }

    @LoremSwiftify
    class Author {
        let name: String
        let surname: String
        var nickName: String?
        let age: Int

        init(_ name: String, surname: String, nickName: String? = nil, age: Int) {
            self.name = name
            self.surname = surname
            self.nickName = nickName
            self.age = age
        }
    }
    // Expands
    extension Book.Author: LoremIpsumize {
        public static func lorem() -> Self {
            Book.Author(
                _: .lorem(),
                surname: .lorem(),
                nickName: nil,
                age: .lorem()
            ) as! Self
        }
    }
}
// Expands
extension Book: LoremIpsumize {
    public static func lorem() -> Self {
        Book(
            name: .lorem(),
            published: .lorem(),
            author: .lorem()
        ) as! Self
    }
}

print(Book.lorem())

@LoremSwiftify
struct Hotel {
    @Lorem(.string(.name))
    let name: String

    @Lorem(.string(.phoneNumber))
    let phoneNumber: String

    @Lorem(.url(.website))
    let website: URL

    let rooms: [Room]

    @LoremSwiftify
    struct Room {
        let id: UUID
        let capacity: Capacity

        @Lorem(.url(.image))
        let image: URL

        @LoremSwiftify
        enum Capacity: Int {
            case one = 1
            case two = 2
            case three = 3
            case four = 4
        }
        // Expands
        extension Hotel.Room.Capacity: LoremIpsumize {
            public static func lorem() -> Self {
                Hotel.Room.Capacity.one
            }
        }
    }
    // Expands
    extension Hotel.Room: LoremIpsumize {
        public static func lorem() -> Self {
            Hotel.Room(
                id: .lorem(),
                capacity: .lorem(),
                image: .lorem(.url(.image))
            )
        }
    }
}
// Expands
extension Hotel: LoremIpsumize {
    public static func lorem() -> Self {
        Hotel(
            name: .lorem(.string(.name)),
            phoneNumber: .lorem(.string(.phoneNumber)),
            website: .lorem(.url(.website)),
            rooms: .lorem()
        )
    }
}

print(Hotel.lorem())

loremswiftify's People

Contributors

eneskaraosman avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

loremswiftify's Issues

Infinite recursive call .lorem on Optional property type

@LoremSwiftify
public struct Job: Codable {
    @Lorem(.url(.website))
    public let url: String?
    public let company: String?
    public let job: String
}

in this case there will be infinite call in this place

extension LoremIpsumize {
    public static func lorem(_ kind: LoremKind? = nil) -> Self {
        lorem(kind)
    }
}

if add to Optional extension

extension Optional: LoremIpsumize {
    public static func lorem() -> Optional<Wrapped> {
        .none
    }
    
    public static func lorem(_ kind: LoremKind?) -> Optional<Wrapped> {
        return .none
    }
}

error is gone but value will be nil in result

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/swift.yml
  • actions/checkout v4
  • macos 14
swift
Package.swift
  • apple/swift-syntax from: "510.0.2"
  • pointfreeco/swift-macro-testing from: "0.4.0"
  • vadymmarkov/Fakery from: "5.1.0"

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.