Guest User

Untitled

a guest
Nov 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. /**
  2. * Available decorator arguments:
  3. * - number
  4. * - string
  5. * - object
  6. * - boolean
  7. * - undefined
  8. * - null
  9. * - function
  10. */
  11. exports.typeDec = function typeDec(decoratorArgs) {
  12. return function (target, name, descriptor) {
  13. const fn = descriptor.value;
  14. const newFn = function(...args) {
  15. if (args[0] === undefined) return;
  16. fn.apply(target, arguments);
  17. args = args.map(arr => arr);
  18.  
  19. for (let i = 0; i < args.length; i++) {
  20. if (decoratorArgs[i] !== typeof args[i]) {
  21. console.warn(`TypeException in func ${name.toString()} expected type ${decoratorArgs[i]} received
  22. ${args[i]} with type ${typeof args[i]}`)
  23. }
  24. }
  25. }
  26.  
  27. descriptor.value = newFn;
  28. return descriptor.value;
  29. }
  30. }
Add Comment
Please, Sign In to add comment