@plq/faker
v1.1.1
Published
A set of classes for mocking known data types such as browser history, browser download list, persona, domain name, Jira project, GitHub repository, etc.
Downloads
78
Maintainers
Readme
faker
A set of classes for mocking known data types such as browser history, browser download list, person, domain name, Jira project, GitHub repository, etc.
Installation
Install the library using npm:
npm install @plq/faker
Usage
Domain
Generates an object with random protocol, domain name and TLD. It's using for generating History, Project, Repository, Tracker and User.
import { Domain } from '@plq/faker'
const domain = new Domain()
domain.getItem()
/* Output: {
protocol: 'https', // Random protocol
name: 'close-reality', // Random domain name
tld: 'name', // Random TLD
domainName: 'close-reality.name',
full: 'https://close-reality.name',
} */
Or you can generate a domain with predefined data:
new Domain('https://github.com') // Nothing random
new Domain('npmjs.com') // Random protocol
new Domain('development') // Random protocol and TLD
Downloads
Generates an array of random download items. See chrome.downloads.DownloadItem.
import { Downloads } from '@plq/faker'
const downloads = new Downloads()
downloads.getItems() // Returns an array of download items
downloads.getItem() // Returns a single download item
With predefined data, class accepts an object with type of downloads.DownloadQuery:
new Downloads({
url: 'https://downloads.info', // All download items will have the same domain
limit: 100, // Number of download items
startedAfter: new Date('2023-01-01').getTime(), // All items will be created with startTime after 2023-01-01
startedBefore: new Date('2023-01-31').getTime(), // All items will be created with startTime before 2023-01-31
})
History
Generates an array of random history items. See chrome.history.HistoryItem.
import { History } from '@plq/faker'
const history = new History()
history.getItems() // Returns an array of history items
history.getItem() // Returns a single history item
With predefined data, class accepts an object with type of history.search.query:
new History({
text: 'https://github.com', // All history items will have the same domain
maxResults: 100, // Number of history items
startTime: new Date('2023-01-01').getTime(), // All items will be created with lastVisitTime after 2023-01-01
endTime: new Date('2023-01-31').getTime(), // All items will be created with lastVisitTime before 2023-01-31
})
Project
Generates an object with random project name.
import { Project } from '@plq/faker'
const project = new Project()
project.getItem()
/* Output: {
name: 'Zieme, Hauck and McClure'
shortName: 'Zieme'
abbreviation: 'ZHM'
} */
Repository
Generates an object with random GitHub or Gitlab repository data.
import { Repository } from '@plq/faker'
const repository = new Repository()
repository.getItem()
/* Output: {
provider: 'github' | 'gitlab', // Random or predefined
user: 'Nettie_Zboncak40', // Random user nickname
project: 'zieme', // Random project shortName
url: https://${provider}.${project}.${tld}, // Random url
} */
Repository constructor params:
- user?: MockUserItem,
- project?: MockProjectItem,
- domain?: MockDomainItem
new Repository({
user: new User().getItem(),
project: new Project().getItem(),
domain: new Domain().getItem(),
})
Tracker
Generates an object with random Jira or Youtrack tracker data.
import { Tracker } from '@plq/faker'
const tracker = new Tracker()
tracker.getItem()
/*
Output: {
provider: 'jira' | 'youtrack', // Random or predefined
user: 'Nettie_Zboncak40', // Random user nickname
project: 'zieme', // Random project shortName
url: `https://${provider}.${tld}/${user}/${project}`, // Random url
path: `${user}/${project}`
}
*/
Tracker constructor params:
- user?: MockUserItem,
- project?: MockProjectItem,
- domain?: MockDomainItem
new Tracker({
user: new User().getItem(),
project: new Project().getItem(),
domain: new Domain().getItem(),
})
User
Generates an object with random user data.
import { User } from '@plq/faker'
const user = new User()
user.getItem()
/* Output: {
nickname: 'Helene_Muller11'
email: '[email protected]'
firstName: 'Helene'
lastName: 'Muller'
fullName: 'Helene Muller'
} */
User constructor params:
- domain?: MockDomainItem
new User(
new Domain().getItem() // Using for email generation
)
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, please submit an issue or a pull request on the GitHub repository.
License
This library is distributed under the MIT License. See the LICENSE file for more information.
Bug Reports
If you encounter any bugs or issues, please report them on the issue tracker.