{"id":18256894,"url":"https://github.com/mediacomem/test-value-generator","last_synced_at":"2025-04-08T22:28:55.504Z","repository":{"id":73832600,"uuid":"111902513","full_name":"MediaComem/test-value-generator","owner":"MediaComem","description":"Utilities to generate incremental and unique values in automated tests.","archived":false,"fork":false,"pushed_at":"2017-11-28T12:18:32.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-15T01:03:16.428Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MediaComem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-24T09:50:27.000Z","updated_at":"2017-11-24T09:51:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"9a714bf3-8000-46bf-bda3-462bde8daf9f","html_url":"https://github.com/MediaComem/test-value-generator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Ftest-value-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Ftest-value-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Ftest-value-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Ftest-value-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MediaComem","download_url":"https://codeload.github.com/MediaComem/test-value-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247938525,"owners_count":21021539,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T10:24:03.117Z","updated_at":"2025-04-08T22:28:55.499Z","avatar_url":"https://github.com/MediaComem.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# test-value-generator\n\nUtilities to generate incremental and unique values in automated tests.\n\n[![npm version](https://badge.fury.io/js/test-value-generator.svg)](https://badge.fury.io/js/test-value-generator)\n[![Dependency Status](https://gemnasium.com/badges/github.com/MediaComem/test-value-generator.svg)](https://gemnasium.com/github.com/MediaComem/test-value-generator)\n[![Build Status](https://travis-ci.org/MediaComem/test-value-generator.svg?branch=master)](https://travis-ci.org/MediaComem/test-value-generator)\n[![Coverage Status](https://coveralls.io/repos/github/MediaComem/test-value-generator/badge.svg?branch=master)](https://coveralls.io/github/MediaComem/test-value-generator?branch=master)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.txt)\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\nDeveloped at the [Media Engineering Institute](http://mei.heig-vd.ch) ([HEIG-VD](https://heig-vd.ch)).\n\n\n\n## Usage\n\nThis module exposes factory functions that return value generator functions when called:\n\n```js\nconst testValueGenerator = require('test-value-generator');\n\n// Create a value generator function:\nconst numberGenerator = testValueGenerator.incremental(i =\u003e i);\ntypeof(numberGenerator); // =\u003e \"function\"\n\n// Generate a value by calling it:\nnumberGenerator(); // =\u003e 0\n```\n\n### Generating incremental values\n\n```js\nconst testValueGenerator = require('test-value-generator');\n\n// An incremental value generator helps you produce values containing\n// a number that is incremented each time you use the generator.\nconst incrementalEmail = testValueGenerator.incremental(i =\u003e `email-${i}@example.com`);\nincrementalEmail(); // =\u003e \"email-0@example.com\"\nincrementalEmail(); // =\u003e \"email-1@example.com\"\nincrementalEmail(); // =\u003e \"email-2@example.com\"\n```\n\n### Generating unique values\n\nA value generator created with `unique` will call your function until it can\ngenerate a value that it has not generated before. It will throw an error if it\nfails after 10 attempts.\n\n```js\nconst testValueGenerator = require('test-value-generator');\n\n// A unique value generator makes sure to never produces the same value\n// twice, and throws an error if it cannot.\nconst uniqueDiceRoll = testValueGenerator.unique(() =\u003e Math.floor(Math.random() * 6 + 1));\nuniqueDiceRoll(); // =\u003e 3\nuniqueDiceRoll(); // =\u003e 5\nuniqueDiceRoll(); // =\u003e 6\nuniqueDiceRoll(); // =\u003e 2\nuniqueDiceRoll(); // =\u003e 1\nuniqueDiceRoll(); // =\u003e 4\ntry {\n  uniqueDiceRoll();\n} catch(err) {\n  // Error thrown: Could not generate unique value after 10 attempts.\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediacomem%2Ftest-value-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmediacomem%2Ftest-value-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediacomem%2Ftest-value-generator/lists"}