1.0.2 • Published 2 years ago

easy-breezy-data-generator v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Easy-breezy Data Generator

This is a package which helps user to create a random dataset for any customized schema (Internally this package uses chance.js).

What's chance.js?

Chance is a generator of random strings, numbers etc. It helps reduce some mmonotony particulary while writing any automated tests or anywhere else you need anything random everytime.

How it works??

Generating data on the customized schema was a challenge earlier, But is no longer now :). In this package, we are going to see how you can generate a dataSet providing schema of your choice.!

How to configure your schema?

Simply customized your schema specifying your kinds (types). Types can be email, natural number, paragraph etc.. (find list of supported kinds at the end of this article.). Random data is an integral part of any testing or statistical modeling. They play an increasing important role in the system. And having control over the modelling/structuring of data would be cherry on the cake. So lets control the structuring of data by passing any variations of fields, arrays and objects in just one file. Below is the test schema.json for reference.

{
  "email": {
    "kind": "email",
    "params": {
      "domain": "test.com"
    }
  },
  "age": {
    "kind": "age",
    "params": {
      "type": "adult"
    }
  },
  "company": {
    "type": "object",
    "fields": {
      "companyName": {
        "kind": "company"
      },
      "companyAddress": {
        "kind": "address"
      },
      "companyDetails": {
        "type": "object",
        "fields": {
          "companyId": {
            "kind": "fbid"
          },
          "employeeCount": {
            "kind": "natural",
            "params": {
              "min": 1,
              "max": 20
            }
          },
          "subjects": {
            "type": "array",
            "count": 2,
            "fields": {
              "subjectName": {
                "kind": "word"
              },
              "marks": {
                "kind": "natural",
                "params": {
                  "min": 1,
                  "max": 100
                }
              }
            }
          }
        }
      }
    }
  },
  "firstName": {
    "kind": "first"
  },
  "lastName": {
    "kind": "last"
  },
  "subjects": {
    "type": "array",
    "count": 6,
    "fields": {
      "subjectName": {
        "kind": "word"
      },
      "marks": {
        "kind": "natural",
        "params": {
          "min": 1,
          "max": 100
        }
      }
    }
  }
}

You must be wondering what's this params parameter, these are optional parameters which chance.js uses for configuring you're kinds. Take the example of an email kind, it accepts domain parameter as params.

NOTE: By the way, this is just a sample schema.json, you can create your own using any combination of arrays or objects, which ever way you want it!

How to use?

  1. Install easy-breezy-data-generator from npm:
npm install easy-breezy-data-generator
  1. Import the package and schema, in whichever file you need it.
const DataGenerator = require('easy-breezy-data-generator');
const schema = require('./schema.json');
  1. Finally initialize and generate the random dataSet
const dataGenerator = new DataGenerator(schema);
console.log(JSON.stringify(dataGenerator.generateData()));

Below are some most used kinds. Also don't forget to checkout, all the different kinds provided by [chance.js] (https://chancejs.com/).

  1. bool
  2. falsy
  3. character
  4. floating
  5. integer
  6. letter
  7. natural
  8. prime
  9. string
  10. paragraph
  11. sentence
  12. syllable
  13. word
  14. age
  15. birthday
  16. cf
  17. cpf
  18. first
  19. gender
  20. last
  21. name
  22. prefix
  23. ssn
  24. suffix
  25. animal
  26. android_id
  27. apple_token
  28. bb_pin
  29. wp7_anid
  30. wp8_anid2
  31. avatar
  32. color
  33. company
  34. domain
  35. email
  36. fbid
  37. google_analytics
  38. hashtag
  39. ip
  40. ipv6
  41. klout
  42. profession
  43. tld
  44. twitter
  45. url
  46. address
  47. altitude
  48. areacode
  49. city
  50. coordinates
  51. country
  52. depth
  53. geohash
  54. latitude
  55. locale
  56. longitude
  57. phone
  58. postal
  59. postcode
  60. province
  61. state
  62. street
  63. zip
  64. ampm
  65. date
  66. hammertime
  67. hour
  68. millisecond
  69. minute
  70. month
  71. second
  72. timestamp
  73. timezone
  74. weekday
  75. year
  76. cc
  77. cc_type
  78. currency
  79. currency_pair
  80. dollar
  81. euro
  82. exp
  83. exp_month
  84. exp_year
  85. capitalize
  86. mixin
  87. pad
  88. pick
  89. pickone
  90. pickset
  91. set
  92. shuffle
  93. coin
  94. dice
  95. guid
  96. hash
  97. hidden
  98. n
  99. normal
  100. radio
  101. rpg
  102. tv
  103. unique
  104. weighted
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago