Skip to content

Instantly share code, notes, and snippets.

@Devcon4
Created April 24, 2018 02:17
Show Gist options
  • Select an option

  • Save Devcon4/0d7a6783a72d93dbb972bb2ff5b6f140 to your computer and use it in GitHub Desktop.

Select an option

Save Devcon4/0d7a6783a72d93dbb972bb2ff5b6f140 to your computer and use it in GitHub Desktop.
Fun with dynamic literals!
const number = /(?:sbyte|ushort|short|uint|int|ulong|long|float|double|decimal|byte)/;
const string = /(?:char|string)/;
const bool = /(?:bool)/;
const date = /(?:DateTime)/;
let builder = {
accessModifier: 'public',
name: 'test',
type: 'int'
};
let checkObj = {
[+true]: 'Any',
[+number.test(builder.type)]: 'number',
[+string.test(builder.type)]: 'string',
[+bool.test(builder.type)]: 'boolean',
[+date.test(builder.type)]: 'moment.Moment',
};
return `${builder.accessModifier} ${builder.name}: ${checkObj[+true]}`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment