This repository has been archived by the owner on Dec 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser): add support of dynamic variables (#7)
closes #6
- Loading branch information
Showing
12 changed files
with
1,109 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
export default [ | ||
'/Applications', | ||
'/bin', | ||
'/boot', | ||
'/boot/defaults', | ||
'/dev', | ||
'/etc', | ||
'/etc/defaults', | ||
'/etc/mail', | ||
'/etc/namedb', | ||
'/etc/periodic', | ||
'/etc/ppp', | ||
'/home', | ||
'/home/user', | ||
'/home/user/dir', | ||
'/lib', | ||
'/Library', | ||
'/lost+found', | ||
'/media', | ||
'/mnt', | ||
'/net', | ||
'/Network', | ||
'/opt', | ||
'/opt/bin', | ||
'/opt/include', | ||
'/opt/lib', | ||
'/opt/sbin', | ||
'/opt/share', | ||
'/private', | ||
'/private/tmp', | ||
'/private/var', | ||
'/proc', | ||
'/rescue', | ||
'/root', | ||
'/sbin', | ||
'/selinux', | ||
'/srv', | ||
'/sys', | ||
'/System', | ||
'/tmp', | ||
'/Users', | ||
'/usr', | ||
'/usr/X11R6', | ||
'/usr/bin', | ||
'/usr/include', | ||
'/usr/lib', | ||
'/usr/libdata', | ||
'/usr/libexec', | ||
'/usr/local/bin', | ||
'/usr/local/src', | ||
'/usr/obj', | ||
'/usr/ports', | ||
'/usr/sbin', | ||
'/usr/share', | ||
'/usr/src', | ||
'/var', | ||
'/var/log', | ||
'/var/mail', | ||
'/var/spool', | ||
'/var/tmp', | ||
'/var/yp' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as directories } from './directories'; | ||
export { default as locales } from './locales'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
export default [ | ||
'af', | ||
'am', | ||
'an', | ||
'ar', | ||
'ast', | ||
'az', | ||
'be', | ||
'bg', | ||
'bh', | ||
'bn', | ||
'br', | ||
'bs', | ||
'ca', | ||
'ceb', | ||
'ckb', | ||
'co', | ||
'cs', | ||
'cy', | ||
'da', | ||
'de', | ||
'el', | ||
'en', | ||
'eo', | ||
'es', | ||
'et', | ||
'eu', | ||
'fa', | ||
'fi', | ||
'fil', | ||
'fo', | ||
'fr', | ||
'fy', | ||
'ga', | ||
'gd', | ||
'gl', | ||
'gn', | ||
'gu', | ||
'ha', | ||
'haw', | ||
'he', | ||
'hi', | ||
'hmn', | ||
'hr', | ||
'ht', | ||
'hu', | ||
'hy', | ||
'ia', | ||
'id', | ||
'ig', | ||
'is', | ||
'it', | ||
'ja', | ||
'jv', | ||
'ka', | ||
'kk', | ||
'km', | ||
'kn', | ||
'ko', | ||
'ku', | ||
'ky', | ||
'la', | ||
'lb', | ||
'ln', | ||
'lo', | ||
'lt', | ||
'lv', | ||
'mg', | ||
'mi', | ||
'mk', | ||
'ml', | ||
'mn', | ||
'mo', | ||
'mr', | ||
'ms', | ||
'mt', | ||
'my', | ||
'nb', | ||
'ne', | ||
'nl', | ||
'nn', | ||
'no', | ||
'ny', | ||
'oc', | ||
'om', | ||
'or', | ||
'pa', | ||
'pl', | ||
'ps', | ||
'pt', | ||
'qu', | ||
'rm', | ||
'ro', | ||
'ru', | ||
'sd', | ||
'sh', | ||
'si', | ||
'sk', | ||
'sl', | ||
'sm', | ||
'sn', | ||
'so', | ||
'sq', | ||
'sr', | ||
'st', | ||
'su', | ||
'sv', | ||
'sw', | ||
'ta', | ||
'te', | ||
'tg', | ||
'th', | ||
'ti', | ||
'tk', | ||
'to', | ||
'tr', | ||
'tt', | ||
'tw', | ||
'ug', | ||
'uk', | ||
'ur', | ||
'uz', | ||
'vi', | ||
'wa', | ||
'xh', | ||
'yi', | ||
'yo', | ||
'zh', | ||
'zu' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
import { VariableParser } from './VariableParser'; | ||
import faker from 'faker'; | ||
import { Generators } from './Generators'; | ||
|
||
export abstract class BaseVariableParser implements VariableParser { | ||
protected constructor(private readonly variables: Postman.Variable[]) {} | ||
protected constructor( | ||
private readonly variables: Postman.Variable[], | ||
private readonly generators: Generators | ||
) {} | ||
|
||
public abstract parse(value: string): string; | ||
|
||
public find(key: string): Postman.Variable | undefined { | ||
return this.variables.find((x: Postman.Variable) => x.key === key); | ||
public find(key: string): Postman.Variable | (() => any) | undefined { | ||
const variable: Postman.Variable | undefined = this.variables.find( | ||
(x: Postman.Variable) => x.key === key | ||
); | ||
|
||
if (!variable && key.startsWith('$')) { | ||
return this.generators[key.replace(/^\$/, '')]; | ||
} | ||
|
||
return variable; | ||
} | ||
|
||
protected sample(variable?: Postman.Variable): string { | ||
switch (variable?.type?.toLowerCase()) { | ||
case 'string': | ||
case 'text': | ||
return faker.random.word(); | ||
return this.generators.randomWord(); | ||
case 'number': | ||
return String(faker.random.number({ min: 1, max: 99 })); | ||
return String(this.generators.randomInt()); | ||
case 'any': | ||
default: | ||
return faker.random.arrayElement([ | ||
faker.random.alphaNumeric(10), | ||
String(faker.random.number({ min: 1, max: 99 })), | ||
faker.random.uuid() | ||
]); | ||
return this.generators.randomAlphaNumeric(); | ||
} | ||
} | ||
} |
Oops, something went wrong.