source: trip-planner-front/node_modules/stylus/lib/nodes/boolean.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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