Skip to content

Commit

Permalink
Merge dcb15c5 into a6c3545
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Apr 6, 2024
2 parents a6c3545 + dcb15c5 commit 52fa0b2
Show file tree
Hide file tree
Showing 28 changed files with 2,015 additions and 132 deletions.
357 changes: 338 additions & 19 deletions README.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion schema-examples/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name" : "CSV Blueprint Schema Example",
"description" : "This YAML file provides a detailed description and validation rules for CSV files\nto be processed by CSV Blueprint tool. It includes specifications for file name patterns,\nCSV formatting options, and extensive validation criteria for individual columns and their values,\nsupporting a wide range of data validation rules from basic type checks to complex regex validations.\nThis example serves as a comprehensive guide for creating robust CSV file validations.\n",

"presets" : {
"preset-alias" : ".\/readme_sample.yml"
},

"filename_pattern" : "\/demo(-\\d+)?\\.csv$\/i",

"csv" : {
Expand Down Expand Up @@ -147,9 +151,9 @@
"is_luhn" : true,

"phone" : "ALL",
"postal_code" : "US",
"is_iban" : true,
"is_bic" : true,
"postal_code" : "US",
"is_imei" : true,
"is_isbn" : true,

Expand Down
6 changes: 5 additions & 1 deletion schema-examples/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
This example serves as a comprehensive guide for creating robust CSV file validations.
',

'presets' => [
'preset-alias' => './readme_sample.yml',
],

'filename_pattern' => '/demo(-\\d+)?\\.csv$/i',

'csv' => [
Expand Down Expand Up @@ -167,9 +171,9 @@
'is_luhn' => true,

'phone' => 'ALL',
'postal_code' => 'US',
'is_iban' => true,
'is_bic' => true,
'postal_code' => 'US',
'is_imei' => true,
'is_isbn' => true,

Expand Down
6 changes: 5 additions & 1 deletion schema-examples/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ description: | # Any description of the CSV file. Not u
supporting a wide range of data validation rules from basic type checks to complex regex validations.
This example serves as a comprehensive guide for creating robust CSV file validations.
presets:
preset-alias: ./readme_sample.yml # Include another schema and define an alias for it.


# Regular expression to match the file name. If not set, then no pattern check.
# This allows you to pre-validate the file name before processing its contents.
# Feel free to check parent directories as well.
Expand Down Expand Up @@ -228,9 +232,9 @@ columns:

# Identifications
phone: ALL # Validates if the input is a phone number. Specify the country code to validate the phone number for a specific country. Example: "ALL", "US", "BR".".
postal_code: US # Validate postal code by country code (alpha-2). Example: "02179". Extracted from https://www.geonames.org
is_iban: true # IBAN - International Bank Account Number. See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
is_bic: true # Validates a Bank Identifier Code (BIC) according to ISO 9362 standards. See: https://en.wikipedia.org/wiki/ISO_9362
postal_code: US # Validate postal code by country code (alpha-2). Example: "02179". Extracted from https://www.geonames.org
is_imei: true # Validates an International Mobile Equipment Identity (IMEI). See: https://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
is_isbn: true # Validates an International Standard Book Number (ISBN). See: https://www.isbn-international.org/content/what-isbn

Expand Down
5 changes: 4 additions & 1 deletion schema-examples/full_clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ description: |
supporting a wide range of data validation rules from basic type checks to complex regex validations.
This example serves as a comprehensive guide for creating robust CSV file validations.
presets:
preset-alias: ./readme_sample.yml

filename_pattern: '/demo(-\d+)?\.csv$/i'

csv:
Expand Down Expand Up @@ -161,9 +164,9 @@ columns:
is_luhn: true

phone: ALL
postal_code: US
is_iban: true
is_bic: true
postal_code: US
is_imei: true
is_isbn: true

Expand Down
34 changes: 34 additions & 0 deletions schema-examples/preset_database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# JBZoo Toolbox - Csv-Blueprint.
#
# This file is part of the JBZoo Toolbox project.
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#
# @license MIT
# @copyright Copyright (C) JBZoo.com, All rights reserved.
# @see https://github.com/JBZoo/Csv-Blueprint
#

name: Presets for database columns
description: This schema contains basic rules for database user data.

columns:
- name: id
description: A unique identifier, usually used to denote a primary key in databases.
example: 12345
rules:
not_empty: true
is_trimmed: true
is_int: true
num_min: 1
aggregate_rules:
is_unique: true
sorted: [ asc, numeric ]

- name: status
description: Status in database
example: active
rules:
not_empty: true
allow_values: [ active, inactive, pending, deleted ]
65 changes: 65 additions & 0 deletions schema-examples/preset_features.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# JBZoo Toolbox - Csv-Blueprint.
#
# This file is part of the JBZoo Toolbox project.
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#
# @license MIT
# @copyright Copyright (C) JBZoo.com, All rights reserved.
# @see https://github.com/JBZoo/Csv-Blueprint
#

name: Complite list of preset features
description: This schema contains all the features of the presets.

presets:
# The basepath for the preset is `.` (current directory)
# Define alias "db" for schema in `./preset_database.yml`
db: preset_database.yml # Or just `db: preset_database.yml`. It's up to you.

# For example, you can use a relative path
users: ./../schema-examples/preset_users.yml

# Or you can use an absolute path
# db-3: /full/path/preset_database.yml

# Or you can use an absolute path
# db: /full/path/preset_database.yml

filename_pattern:
preset: users # Take the filename pattern from the preset

csv:
preset: users # Take the CSV settings from the preset

columns:
# Use name of column from the preset. "db" is alias. "id" is column `name` in `preset_database.yml`
- preset: 'db/id'

# Use column index. "db" is alias. "0" is column index in `preset_database.yml`
- preset: 'db/0'
- preset: 'db/0:'

# Use column index and column name. It useful if column name is not unique.
- preset: 'db/0:id'

# Override only `rules` from the preset
- name: My column
rules:
preset: 'db/status'

# Override only `aggregate_rules` from the preset
- name: My column
aggregate_rules:
preset: 'db/0:id'

# Combo. If you're a risk-taker or have a high level of inner zen. :)
# Creating a column from three other columns. In fact, it will merge all three at once with key replacement.
- name: Crazy combo!
example: ~
preset: 'users/login'
rules:
preset: 'users/email'
aggregate_rules:
preset: 'db/0'
58 changes: 58 additions & 0 deletions schema-examples/preset_usage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# JBZoo Toolbox - Csv-Blueprint.
#
# This file is part of the JBZoo Toolbox project.
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#
# @license MIT
# @copyright Copyright (C) JBZoo.com, All rights reserved.
# @see https://github.com/JBZoo/Csv-Blueprint
#

name: Schema uses presets and add new columns + specific rules.
description: This schema uses presets. Also, it demonstrates how to override preset values.

presets: # Include any other schemas and defined for each alias
users: ./preset_users.yml # Include the schema with common user data
db: ./preset_database.yml # Include the schema with basic database columns

filename_pattern:
preset: users # Take the filename pattern from the preset

csv:
preset: users # Take the CSV settings from the preset
enclosure: '|' # Overridden value

columns:
- preset: db/id
- preset: db/status
- preset: users/login
- preset: users/email
- preset: users/full_name
- preset: users/birthday

- preset: users/password
rules:
length_min: 10 # Overridden value to force a strong password

- name: user_balance
rules:
preset: users/balance # Take only rules from the preset

- preset: users/short_description
rules:
length_max: 255 # Overridden value

- name: phone # Overridden value
preset: users/phone_number

- name: admin_note
description: Admin note
rules:
not_empty: true
length_min: 1
length_max: 10
aggregate_rules: # In practice this will be a rare case, but the opportunity is there.
preset: db/id # Take only aggregate rules from the preset.
is_unique: true # Added new sprcific rule
112 changes: 112 additions & 0 deletions schema-examples/preset_users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#
# JBZoo Toolbox - Csv-Blueprint.
#
# This file is part of the JBZoo Toolbox project.
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#
# @license MIT
# @copyright Copyright (C) JBZoo.com, All rights reserved.
# @see https://github.com/JBZoo/Csv-Blueprint
#

name: Common presets for user data
description: This schema contains common presets for user data. It can be used as a base for other schemas.

filename_pattern: /users-.*\.csv$/i

csv:
delimiter: ';'

columns:
- name: login
description: User's login name
example: johndoe
rules:
not_empty: true
is_trimmed: true
is_lowercase: true
is_slug: true
length_min: 3
length_max: 20
is_alnum: true
aggregate_rules:
is_unique: true

- name: password
description: User's password
example: '9RfzE$8NKD'
rules:
not_empty: true
is_trimmed: true
regex: /^[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]{6,}$/ # Safe list of special characters for passwords
contains_none: [ "password", "123456", "qwerty", " " ]
charset: UTF-8
length_min: 6
length_max: 20

- name: full_name
description: User's full name
example: 'John Doe Smith'
rules:
not_empty: true
is_trimmed: true
charset: UTF-8
contains: " "
word_count_min: 2
word_count_max: 8
is_capitalize: true
aggregate_rules:
is_unique: true

- name: email
description: User's email address
example: user@example.com
rules:
not_empty: true
is_trimmed: true
is_email: true
is_lowercase: true
aggregate_rules:
is_unique: true

- name: birthday
description: Validates the user's birthday.
example: '1990-01-01'
rules:
not_empty: true # The birthday field must not be empty.
is_trimmed: true # Trims the value before validation.
date_format: Y-m-d # Checks if the date matches the YYYY-MM-DD format.
is_date: true # Validates if the value is a valid date.
date_age_greater: 0 # Ensures the date is in the past.
date_age_less: 150 # Ensures the user is not older than 150 years.
date_max: now # Ensures the date is not in the future.

- name: phone_number
description: User's phone number in US
example: '+1 650 253 00 00'
rules:
not_empty: true
is_trimmed: true
starts_with: '+1'
phone: US

- name: balance
description: User's balance in USD
example: '100.00'
rules:
not_empty: true
is_trimmed: true
is_float: true
num_min: 0.00
num_max: 1000000000.00 # 1 billion
precision: 2

- name: short_description
description: A brief description of the item
example: 'Lorem ipsum dolor sit amet'
rules:
not_empty: true
contains: " "
length_max: 255
is_trimmed: true
Loading

0 comments on commit 52fa0b2

Please sign in to comment.