Skip to content

feat: Organize comprehensive templates in examples.ts with helper methods and combined template #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 3, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 3, 2025

This PR reorganizes the template structure by moving comprehensive templates to a dedicated examples.ts file and adding convenient helper methods for common data generation tasks.

Changes Made

File Organization

  • Moved comprehensive templates from src/structured/templates.ts to src/examples.ts
  • Restored src/structured/templates.ts to contain only basic templates (nil, tokensHelloWorld, tokensObjectKey, str)
  • Removed examples namespace export from main src/index.ts to keep the public API clean

Combined Template

Created allExamples template that uses the or pattern to randomly select from all 34 comprehensive templates:

export const allExamples: Template = ['or',
  userProfile,
  userBasic,
  apiResponse,
  // ... all other templates including recursive ones
  tree,
  comment,
];

Helper Methods for Easy Generation

Added convenient helper methods that eliminate the need to construct templates manually:

import { genUser, genAddress, genProduct, genRandomExample } from '@jsonjoy.com/json-random/lib/examples';

// Generate common data types quickly
const user = genUser();
const address = genAddress();
const product = genProduct();
const randomData = genRandomExample();

Available helper methods include:

  • genUser(), genUserBasic() - User profiles
  • genAddress(), genLocation() - Geographic data
  • genProduct(), genOrder() - E-commerce data
  • genTransaction(), genBankAccount() - Financial data
  • genSocialPost(), genSocialProfile() - Social media data
  • genPatient(), genMedicalRecord() - Medical data
  • genStudent(), genCourse() - Educational data
  • genSensorReading(), genIotDevice() - IoT data
  • genLogEntry(), genMetricData() - Monitoring data
  • genRandomExample() - Random selection from all templates

Template Categories Available

  • String patterns: Email, phone, URLs, product codes
  • User profiles: Basic and detailed user data with authentication
  • E-commerce: Products, orders, transactions, bank accounts
  • API responses: Success/error responses with data arrays
  • IoT & sensors: Device readings, sensor data, network information
  • Medical records: Patient data, diagnoses, medications, vitals
  • Educational data: Students, courses, grades, schedules
  • Geographic data: Addresses, coordinates, locations
  • Social media: Posts, profiles, hashtags, media attachments
  • Financial data: Transactions, accounts, multi-currency support
  • Monitoring: Log entries, metrics, system data
  • Edge cases: Empty structures, Unicode text, large numbers
  • Performance testing: Deeply nested data structures

Quality Assurance

  • ✅ All 84 tests pass
  • ✅ Linter and formatter compliance maintained
  • ✅ Helper methods fully documented in README.md
  • ✅ Clean separation between core library and examples

This organization provides better separation of concerns while adding convenient helper methods for common use cases, making the library more approachable for developers who need quick data generation without template construction.

Fixes #4.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…amples and real-life scenarios

Co-authored-by: streamich <[email protected]>
@Copilot Copilot AI changed the title [WIP] Generate templates for TemplateJson feat: Generate comprehensive templates for TemplateJson covering README examples and real-life scenarios Aug 3, 2025
Copilot finished work on behalf of streamich August 3, 2025 12:25
@Copilot Copilot AI requested a review from streamich August 3, 2025 12:25
@streamich streamich marked this pull request as ready for review August 3, 2025 12:35
Copy link
Collaborator

@streamich streamich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Move all new templates to src/examples.ts.
  • Crate a template which combines all templates using or template.
  • Make sure tests pass.
  • Make sure linter and formatter pass.

Copy link
Contributor Author

Copilot AI commented Aug 3, 2025

  • Move all new templates to src/examples.ts.
  • Crate a template which combines all templates using or template.
  • Make sure tests pass....

All changes implemented in commit d54454e:

✅ Moved all new templates to src/examples.ts
✅ Created allExamples template that combines all templates using or template
✅ All tests pass (84 tests)
✅ Linter and formatter pass

The comprehensive templates are now properly organized in src/examples.ts with a combined template that randomly selects from all 34 available examples using the or template pattern.

@Copilot Copilot AI changed the title feat: Generate comprehensive templates for TemplateJson covering README examples and real-life scenarios feat: Organize comprehensive templates in examples.ts with combined template using 'or' pattern Aug 3, 2025
@Copilot Copilot AI requested a review from streamich August 3, 2025 12:54
Copilot finished work on behalf of streamich August 3, 2025 12:54
Copy link
Collaborator

@streamich streamich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When done, make sure formatter passes.

src/index.ts Outdated
@@ -3,3 +3,4 @@ export * from './RandomJson';
export * from './number';
export * from './string';
export * from './structured';
export * as examples from './examples';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the export * as examples from './examples'; line from src/index.ts in commit 6a4fba8.

src/examples.ts Outdated
Comment on lines 1091 to 1092
tree(),
comment(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tree(),
comment(),
tree,
comment,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the function calls to function references - changed tree(), and comment(), to tree, and comment, in commit 6a4fba8.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to this file (and export) methods for easy random JSON generation, such as getUser(), genAddress(), etc.

Mention these methods in README.md.

DO NOT re-export anything from this file in main index.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added helper methods for easy random JSON generation (like genUser(), genAddress(), etc.) to src/examples.ts and documented them in README.md in commit 6a4fba8. These methods are not re-exported from main index.ts as requested.

…ion calls, add helper methods

Co-authored-by: streamich <[email protected]>
Copy link
Contributor Author

Copilot AI commented Aug 3, 2025

When done, make sure formatter passes.

Formatter passes - confirmed with yarn format check in commit 6a4fba8.

@Copilot Copilot AI changed the title feat: Organize comprehensive templates in examples.ts with combined template using 'or' pattern feat: Organize comprehensive templates in examples.ts with helper methods and combined template Aug 3, 2025
@Copilot Copilot AI requested a review from streamich August 3, 2025 13:07
Copilot finished work on behalf of streamich August 3, 2025 13:07
@streamich streamich merged commit d5c3d4b into master Aug 3, 2025
2 checks passed
@streamich streamich deleted the copilot/fix-4 branch August 3, 2025 13:08
Copy link

github-actions bot commented Aug 3, 2025

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate templates for TemplateJson
2 participants