BVB Source Codes

prettier Show simple-predicate-func.js Source code

Return Download prettier: download simple-predicate-func.js Source code - Download prettier Source code - Type:.js
  1. // @flow
  2.  
  3. function is_string(y): %checks {
  4.   return typeof y === "string";
  5. }
  6.  
  7. function is_bool(y): %checks {
  8.   return typeof y === "boolean";
  9. }
  10.  
  11. function is_number(y): %checks {
  12.   return typeof y === "number";
  13. }
  14.  
  15. // Feature check:
  16. function foo(x: string | Array<string>): string {
  17.   if (is_string(x)) {
  18.     // The use of `is_string` as a conditional check
  19.     // should guarantee the narrowing of the type of `x`
  20.     // to string.
  21.     return x;
  22.   } else {
  23.     // Accordingly the negation of the above check
  24.     // guarantees that `x` here is an Array<string>
  25.     return x.join();
  26.   }
  27. }
  28.  
  29. // Same as above but refining an offset
  30. function bar(z: { f: string | Array<string>}): string {
  31.   if (is_string(z.f)) {
  32.     return z.f;
  33.   } else {
  34.     return z.f.join();
  35.   }
  36. }
  37.  
  38. function is_number_or_bool(y): %checks {
  39.   return is_number(y) || is_bool(y);
  40. }
  41.  
  42. function baz(z: string | number): number {
  43.   if (is_number_or_bool(z)) {
  44.     return z;
  45.   } else {
  46.     return z.length;
  47.   }
  48. }
  49.  
  50. // Feature: multi params
  51. function multi_param(w,x,y,z): %checks {
  52.   return typeof z === "string";
  53. }
  54.  
  55. function foo(x: string | Array<string>): string {
  56.   if (multi_param("1", "2", "3", x)) {
  57.     return x;
  58.   } else {
  59.     return x.join();
  60.   }
  61. }
  62.  
  63. function foo(a, b) {
  64.   if (two_strings(a, b)) {
  65.     from_two_strings(a, b);
  66.   }
  67. }
  68.  
  69. function two_strings(x,y): %checks {
  70.   return is_string(x) && is_string(y) ;
  71. }
  72.  
  73. declare function from_two_strings(x: string, y: string): void;
  74.  
downloadsimple-predicate-func.js Source code - Download prettier Source code
Related Source Codes/Software:
storybook - 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top