xdevor/type

A Laravel package which object type collection powered by Laravel's validation components.

v0.0.1-alpha 2023-11-11 08:04 UTC

This package is auto-updated.

Last update: 2024-10-11 09:58:05 UTC


README

In this package we've introduced a new type package that focuses on validating object types.

This package not only allows you to validate basic data types but also supports complex object structures. Using Laravel's fluent validation syntax, you can define the expected properties of an object to ensure their types and existence.

Test Status Total Downloads packagist License

Installation

Require this package with composer:

composer require xdevor/type

Usage

  • ❌ Without object type
function increase(int $count)
{
    if ($count < 1) {
        throw new InvalidArgumentException('Receive invalid argument');
    }
    return $this->value + $count;
}
  • ✅ With object type
use Xdevor\Type\Numbers\PositiveInt;

function increase(PositiveInt $count)
{
    return $this->value + $count->value();
}

Features

Supports

  1. PositiveInt: Positive integer
  2. NegativeInt: Negative integer

Todo

  1. NonZeroInt: Non-zero integer
  2. PositiveFloat: Positive floating-point number
  3. NegativeFloat: Negative floating-point number
  4. NonZeroFloat: Non-zero floating-point number
  5. NonEmptyString: Non-empty string
  6. EmailAddress: Email address
  7. Url: URL
  8. PhoneNumber: Phone number
  9. Date: Date
  10. DateTime: Date and time
  11. Uuid: Universally Unique Identifier (UUID)
  12. IPv4Address: IPv4 address
  13. IPv6Address: IPv6 address
  14. HexColorCode: Hexadecimal color code
  15. AlphanumericString: Alphanumeric string
  16. Json: JSON string
  17. ArrayOfType: Array of a specific type
  18. CustomEnum: Custom enumeration type
  19. CreditCardNumber: Credit card number
  20. SocialSecurityNumber: Social Security number
  21. LatitudeLongitude: Latitude and longitude coordinates
  22. CurrencyAmount: Currency amount
  23. Percentage: Percentage value
  24. FileSize: File size
  25. TimeInterval: Time interval
  26. ISBN: International Standard Book Number (ISBN)
  27. MACAddress: MAC address
  28. IBAN: International Bank Account Number (IBAN)
  29. Password: Password with specific constraints
  30. PostalCode: Postal code
  31. CreditScore: Credit score
  32. FahrenheitTemperature: Temperature in Fahrenheit
  33. CelsiusTemperature: Temperature in Celsius
  34. BinaryData: Binary data
  35. Gender: Gender (Male/Female/Other)
  36. Latitude: Latitude coordinate
  37. Longitude: Longitude coordinate
  38. ISBN13: ISBN-13
  39. IMEI: International Mobile Equipment Identity (IMEI)
  40. CreditCardExpirationDate: Credit card expiration date
  41. VATNumber: Value Added Tax (VAT) number
  42. HexadecimalNumber: Hexadecimal number
  43. BooleanString: Boolean represented as a string
  44. RomanNumeral: Roman numeral
  45. PassportNumber: Passport number
  46. MIMEType: Multipurpose Internet Mail Extensions (MIME) type
  47. MACAddressOUI: MAC address Organizationally Unique Identifier (OUI)
  48. EAN13: International Article Number (EAN-13)
  49. EAN8: International Article Number (EAN-8)
  50. VehicleIdentificationNumber (VIN): VIN for vehicles
  51. ISSN: International Standard Serial Number (ISSN)
  52. UPC: Universal Product Code (UPC)
  53. GS1Barcode: GS1 Barcode
  54. MD5Hash: MD5 hash
  55. SHA1Hash: SHA-1 hash
  56. SHA256Hash: SHA-256 hash
  57. SHA512Hash: SHA-512 hash
  58. RGBColor: RGB color
  59. RGBAColor: RGBA color (with alpha channel)
  60. HSLColor: HSL color
  61. HSLAColor: HSLA color (with alpha channel)
  62. HTMLColorName: HTML color name
  63. Base64EncodedString: Base64-encoded string
  64. ISBN10: ISBN-10
  65. USStateAbbreviation: US state abbreviation
  66. CanadianPostalCode: Canadian postal code
  67. SocialMediaUsername: Social media username
  68. HexadecimalRGBColor: Hexadecimal RGB color
  69. AlphabeticalString: Alphabetical string
  70. MongoDBObjectId: MongoDB Object ID
  71. JWToken: JSON Web Token (JWT)
  72. UnixTimestamp: Unix timestamp
  73. YouTubeVideoId: YouTube video ID
  74. HexadecimalUUID: Hexadecimal UUID
  75. HTTPStatusCode: HTTP status code
  76. SemVer: Semantic versioning string
  77. EpochTime: Epoch time
  78. HexadecimalMACAddress: Hexadecimal MAC address
  79. GoogleAnalyticsTrackingId: Google Analytics tracking ID
  80. USZipCode: US ZIP code
  81. Slug: URL-friendly slug
  82. TwitterHandle: Twitter handle
  83. HexadecimalBinary: Hexadecimal binary data
  84. RandomGuid: Randomly generated GUID
  85. ICAOAirportCode: ICAO airport code
  86. HexadecimalHTMLColor: Hexadecimal HTML color code
  87. GitCommitHash: Git commit hash
  88. CustomMimeType: Custom MIME type
  89. GPSCoordinates: GPS coordinates
  90. AmericanExpressCardNumber: American Express credit card number
  91. MasterCardNumber: MasterCard credit card number
  92. VisaCardNumber: Visa credit card number
  93. DinersClubCardNumber: Diners Club credit card number
  94. DiscoverCardNumber: Discover credit card number
  95. JCBCardNumber: JCB credit card number
  96. DebitCardNumber: Debit card number
  97. WindowsFilePath: Windows file path
  98. UnixFilePath: Unix file path
  99. CurrencyCode: Represents the code of a currency (e.g., USD, EUR).
  100. CurrencyAmount: Represents the numerical value of an amount in a specific currency.
  101. ExchangeRate: Represents the exchange rate between two currencies.
  102. CryptocurrencyCode: Represents the code of a cryptocurrency (e.g., BTC, ETH).
  103. CryptocurrencyAmount: Represents the numerical value of an amount in a specific cryptocurrency.
  104. BitcoinAddress: Represents a Bitcoin wallet address.
  105. EthereumAddress: Represents an Ethereum wallet address.
  106. LitecoinAddress: Represents a Litecoin wallet address.
  107. RippleAddress: Represents a Ripple wallet address.
  108. MoneroAddress: Represents a Monero wallet address.
  109. StellarAddress: Represents a Stellar wallet address.
  110. EOSAddress: Represents an EOS wallet address.
  111. DashAddress: Represents a Dash wallet address.
  112. ZcashAddress: Represents a Zcash wallet address.
  113. USDCurrency: Represents the United States Dollar (USD).
  114. EuroCurrency: Represents the Euro (EUR).
  115. BritishPoundCurrency: Represents the British Pound (GBP).
  116. JapaneseYenCurrency: Represents the Japanese Yen (JPY).
  117. CanadianDollarCurrency: Represents the Canadian Dollar (CAD).
  118. AustralianDollarCurrency: Represents the Australian Dollar (AUD).
  119. SwissFrancCurrency: Represents the Swiss Franc (CHF).
  120. ChineseYuanCurrency: Represents the Chinese Yuan (CNY).
  121. IndianRupeeCurrency: Represents the Indian Rupee (INR).
  122. BrazilianRealCurrency: Represents the Brazilian Real (BRL).
  123. SouthAfricanRandCurrency: Represents the South African Rand (ZAR).
  124. SwedishKronaCurrency: Represents the Swedish Krona (SEK).
  125. NorwegianKroneCurrency: Represents the Norwegian Krone (NOK).
  126. SingaporeDollarCurrency: Represents the Singapore Dollar (SGD).
  127. NewZealandDollarCurrency: Represents the New Zealand Dollar (NZD).
  128. MexicanPesoCurrency: Represents the Mexican Peso (MXN).

Contributing

Please see CONTRIBUTING for details.

Code of Conduct

In order to ensure that the php community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

This package is open-sourced software licensed under the MIT license.