mock_data 1.2.5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 69

mock_data

License Build status

Generate random data using Dart.

List of random data to generate:

  • colors with various color spaces
  • date between different moments in time
  • integers in between range of numbers
  • IPs ~ IPv4 and IPv6
  • name; male or female first name
  • strings of different length and characters
  • url with different parts; routes, GET query parameters and fragments
mocking Nelson Muntz

Inspired by: https://www.npmjs.com/package/mock-data

Usage

A simple usage example:

import 'package:mock_data/mock_data.dart';

main() {
  
  // Mock string of given length and group of characters:
  
  // Generate string of length 16(default) and any 
  // combination of letters and digits.
  mockString();
  
  // Generate string of length 10 and any combination
  // of letters and digits.
  mockString(10);
  
  // Generate string of length 15 and any combination
  // of lowercase letters and digits.
  mockString(15, 'a#');
  
  // Generate string of length 3 and any combination
  // of letters and digits.
  mockString(3, '!');
  
  // Generate string of length 7 and any combination
  // of letters.
  mockString(7, 'aA');

  // Mock integer in range from min to max, inclusive:
  
  // Generate integer in range from min(default 1)
  // to max(default 10). Works with negative numbers.
  mockInteger();
  
  // Generate integer in range from 3 to 30.
  mockInteger(3, 30);
  
  // Generate integer in range from -15 to 5.
  mockInteger(-15, 5);
  
  // Generate integer in range from -25 to -15.
  mockInteger(-25, -15);

  // Mock IPv4 or IPv6 with given format:
  
  // Generate IPv4 represented with
  // format(default is '*.*.*.*') as String. 
  mockIPv4();
  
  // Generate IPv4 starting with groups of
  // 192, 168 and 0, followed by any integer
  // of last group.
  mockIPv4('192.168.0.*');
  
  // Generate IPv4 starting with groups of
  // 192 and 168, followed by any integer
  // of last two groups.
  mockIPv4('192.168.*.*');
  
  // Generate IPv4 starting with groups of
  // 192, followed by any integer
  // of next two groups and end group of 55.
  mockIPv4('192.*.*.55');

  // Generate IPv6, same usage as with IPv4.
  mockIPv6();
  mockIPv6('*:e331:93bf:*:a7c9:a63:*:*');
  mockIPv6('e1b3:7bae:*:3474:*:c0cc:462:c4b9');

  // Mock first name from passed gender:
  
  // Generate male or female first name. 
  mockName();
  
  // Generate male first name. 
  mockName('male');
  
  // Generate female first name. 
  mockName('female');
  
  // Mock color from a given color model:
  
  // Generate color represented in hex or rgb format.
  mockColor(); 
  
  // Generate color represented in hex format.
  mockColor('hex');
  
  // Generate color represented in RGB format.
  mockColor('rgb');
  
  // Generate color represented in HSL format.
  mockColor('hsl');
  
  // Generate color represented in HSV format.
  mockColor('hsv');
  
  // Generate color represented in CMYK format.
  mockColor('cmyk');
  
  // Mock url from passed parameters:
  
  // Generate url starting with http scheme.
  mockUrl('http');
  
  // Generate url starting with http or https
  // followed by 1 to 4 paths.
  mockUrl('*', true);
  
  // Generate url starting with https
  // followed by 1 to 4 paths
  // followed by fragment(permalink).
  mockUrl('https', true, false, true);
  
  // Mock DateTime from two moments in time:
    
  // Generate DateTime object in between
  // 1970-01-01 01:00:00.000 and now.
  mockDate();
  
  // Generate DateTime object in between
  // 1995-00-00 00:00:00.000 and now.
  mockDate(DateTime(1995));
  
  // Generate DateTime object in between
  // 1995-00-00 00:00:00.000 and now.
  mockDate(DateTime(1995, 26, 7), DateTime(2005, 26, 7));
  
  // Generate DateTime object in between
  // 2015-10-21 04:29:00.000 and now.
  mockDate(DateTime.parse("2015-10-21 04:29:00"));
  
  // Generate range of mocks of particular
  // function(more at documentation).
  mockRange(mockString, 3);
  mockRange(mockInteger, 5, min: 3, max: 15);
  mockRange(mockIPv4, 7, format: '*.*.0.0');
  mockRange(mockName, 5, gender: 'male');
  mockRange(mockColor, 12, returnModel: 'hex');
  mockRange(mockUrl, 4, scheme: 'http', withQuery: true);
  mockRange(mockDate, 5, firstMoment: DateTime(2010, DateTime.november, 2));

}

More explanation and examples at documentation.

TODO

Please see TODO.

Contributors

License

MIT.

1.2.2 - 1.2.5

1.2.1

  • UPDATED: Added support for IPv6 instead of IPv4 only.
  • UPDATED: Added new color spaces for mockColor
  • UPDATED: Added new male and female names
  • IMPROVED: Added more tests
  • CHANGED: mockName defaults to 'any' instead of empty string
  • FIX: mockName test for gender changed to more valid one

1.2.0

  • NEW: mockColor, mockUrl and mockDate functions

1.1.0

  • NEW: mockName function
  • Improved documentation
  • FIX: Removed last dot that was generated using mockIPv4 function

1.0.1

  • FIX: Added proper documentation link

1.0.0

  • Initial version

example/mock_data_example.dart

import 'package:mock_data/mock_data.dart';

main() {

  // Mock string from a given length and group of characters.
  mockString(); // default length of 16 and include of '!'.
  mockString(10);
  mockString(15, 'a#');
  mockString(3, '!');
  mockString(7, 'aA');

  // Mock integer in range from min to max.
  mockInteger(); // default min set to 1 and max to 10.
  mockInteger(3, 30);
  mockInteger(-15, 5);
  mockInteger(-25, -15);

  // Mock IPv4 with given format.
  mockIPv4(); // default format set to '*.*.*.*'.
  mockIPv4('192.168.0.*');
  mockIPv4('192.168.*.*');
  mockIPv4('192.*.*.55');

  // Mock IPv6 with given format.
  mockIPv6(); // default format set to '*:*:*:*:*:*:*:*'.
  mockIPv6('*:e331:93bf:*:a7c9:a63:*:*');
  mockIPv6('e1b3:7bae:*:3474:*:c0cc:462:c4b9');

  // Mock first name.
  mockName(); // default set to 'any'.
  mockName('any'); // default set to 'any'.
  mockName('male');
  mockName('female');

  // Mock color from a given color model.
  mockColor(); // default model is 'rgb'.
  mockColor('hex');
  mockColor('rgb');
  mockColor('hsv');
  mockColor('hsb');
  mockColor('hsl');
  mockColor('cmyk');

  // Mock url with given properties.
  mockUrl(); // default scheme set to '*' and all other parameters are false.
  mockUrl('http');
  mockUrl('https');
  mockUrl('*', true);
  mockUrl('*', true, true);
  mockUrl('*', true, false, true);

  // Mock date from in between given moments in time.
  mockDate(); // default is in between 1970-01-01 01:00:00.000 and now.
  mockDate(DateTime(1995, 7, 26));
  mockDate(DateTime(1969, 6, 15, 11, 15), DateTime(2002));
  mockDate(DateTime.parse("1969-07-20 20:18:04"), DateTime(1989, DateTime.november, 9));

  // Generate range of mocks of particular function(more at [mockRange]).
  mockRange(mockString, 3);
  mockRange(mockInteger, 5, min: 3, max: 15);
  mockRange(mockIPv4, 7, format: '*.*.0.0');
  mockRange(mockIPv6, 7, format: '*:*:*:e37b:abcd:*:*:*');
  mockRange(mockName, 5, gender: 'male');
  mockRange(mockColor, 13, returnModel: 'hex');
  mockRange(mockUrl, 5, scheme: 'https', withPath: true, withFragment: true);
  mockRange(mockDate, 5, firstMoment: DateTime(2010, DateTime.november, 2));

}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mock_data: ^1.2.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mock_data/mock_data.dart';
  
Version Uploaded Documentation Archive
1.2.5 Jan 2, 2019 Go to the documentation of mock_data 1.2.5 Download mock_data 1.2.5 archive
1.2.4 Dec 25, 2018 Go to the documentation of mock_data 1.2.4 Download mock_data 1.2.4 archive
1.2.3 Dec 25, 2018 Go to the documentation of mock_data 1.2.3 Download mock_data 1.2.3 archive
1.2.2 Dec 25, 2018 Go to the documentation of mock_data 1.2.2 Download mock_data 1.2.2 archive
1.2.1 Dec 24, 2018 Go to the documentation of mock_data 1.2.1 Download mock_data 1.2.1 archive
1.2.0 Dec 19, 2018 Go to the documentation of mock_data 1.2.0 Download mock_data 1.2.0 archive
1.1.0 Dec 17, 2018 Go to the documentation of mock_data 1.1.0 Download mock_data 1.1.0 archive
1.0.1 Dec 17, 2018 Go to the documentation of mock_data 1.0.1 Download mock_data 1.0.1 archive
1.0.0 Dec 17, 2018 Go to the documentation of mock_data 1.0.0 Download mock_data 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

We analyzed this package on Jan 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.10

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:mock_data/mock_data.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.0.0