Blame view

node_modules/stylus/lib/nodes/boolean.js 1.66 KB
ce4c83ff   wxy   初始提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  
  /*!
   * Stylus - Boolean
   * Copyright (c) Automattic <developer.wordpress.com>
   * MIT Licensed
   */
  
  /**
   * Module dependencies.
   */
  
  var Node = require('./node')
    , nodes = require('./');
  
  /**
   * Initialize a new `Boolean` node with the given `val`.
   *
   * @param {Boolean} val
   * @api public
   */
  
  var Boolean = module.exports = function Boolean(val){
    Node.call(this);
    if (this.nodeName) {
      this.val = !!val;
    } else {
      return new Boolean(val);
    }
  };
  
  /**
   * Inherit from `Node.prototype`.
   */
  
  Boolean.prototype.__proto__ = Node.prototype;
  
  /**
   * Return `this` node.
   *
   * @return {Boolean}
   * @api public
   */
  
  Boolean.prototype.toBoolean = function(){
    return this;
  };
  
  /**
   * Return `true` if this node represents `true`.
   *
   * @return {Boolean}
   * @api public
   */
  
  Boolean.prototype.__defineGetter__('isTrue', function(){
    return this.val;
  });
  
  /**
   * Return `true` if this node represents `false`.
   *
   * @return {Boolean}
   * @api public
   */
  
  Boolean.prototype.__defineGetter__('isFalse', function(){
    return ! this.val;
  });
  
  /**
   * Negate the value.
   *
   * @return {Boolean}
   * @api public
   */
  
  Boolean.prototype.negate = function(){
    return new Boolean(!this.val);
  };
  
  /**
   * Return 'Boolean'.
   *
   * @return {String}
   * @api public
   */
  
  Boolean.prototype.inspect = function(){
    return '[Boolean ' + this.val + ']';
  };
  
  /**
   * Return 'true' or 'false'.
   *
   * @return {String}
   * @api public
   */
  
  Boolean.prototype.toString = function(){
    return this.val
      ? 'true'
      : 'false';
  };
  
  /**
   * Return a JSON representaiton of this node.
   *
   * @return {Object}
   * @api public
   */
  
  Boolean.prototype.toJSON = function(){
    return {
      __type: 'Boolean',
      val: this.val
    };
  };