@storybook/csf 0.0.2--canary.92ac0db.0 → 0.0.2--canary.7c6c115.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,9 +19,10 @@ var testValue = function testValue(cond, value) {
19
19
  var _ref = cond,
20
20
  exists = _ref.exists,
21
21
  eq = _ref.eq,
22
- neq = _ref.neq;
22
+ neq = _ref.neq,
23
+ truthy = _ref.truthy;
23
24
 
24
- if (count([exists, eq, neq]) > 1) {
25
+ if (count([exists, eq, neq, truthy]) > 1) {
25
26
  throw new Error("Invalid conditional test ".concat(JSON.stringify({
26
27
  exists: exists,
27
28
  eq: eq,
@@ -40,10 +41,10 @@ var testValue = function testValue(cond, value) {
40
41
  if (typeof exists !== 'undefined') {
41
42
  var valueExists = typeof value !== 'undefined';
42
43
  return exists ? valueExists : !valueExists;
43
- } // implicit test for truthiness
44
-
44
+ }
45
45
 
46
- return !!value;
46
+ var shouldBeTruthy = typeof truthy === 'undefined' ? true : truthy;
47
+ return shouldBeTruthy ? !!value : !value;
47
48
  };
48
49
  /**
49
50
  * Helper function to include/exclude an arg based on the value of other other args
@@ -4,8 +4,20 @@ var _includeConditionalArg = require("./includeConditionalArg");
4
4
 
5
5
  /* eslint-disable @typescript-eslint/ban-ts-ignore */
6
6
  describe('testValue', function () {
7
- describe('implicit', function () {
8
- it.each([['implicit true', {}, true, true], ['implicit truthy', {}, 1, true], ['implicit false', {}, false, false], ['implicit falsey', {}, 0, false], ['implicit undefined', {}, undefined, false]])('%s', function (_name, cond, value, expected) {
7
+ describe('truthy', function () {
8
+ it.each([['implicit true', {}, true, true], ['implicit truthy', {}, 1, true], ['implicit falsey', {}, 0, false], ['truthy true', {
9
+ truthy: true
10
+ }, true, true], ['truthy truthy', {
11
+ truthy: true
12
+ }, 1, true], ['truthy falsey', {
13
+ truthy: true
14
+ }, 0, false], ['falsey true', {
15
+ truthy: false
16
+ }, true, false], ['falsey truthy', {
17
+ truthy: false
18
+ }, 1, false], ['falsey falsey', {
19
+ truthy: false
20
+ }, 0, true]])('%s', function (_name, cond, value, expected) {
9
21
  // @ts-ignore
10
22
  expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
11
23
  });
@@ -127,40 +139,32 @@ describe('includeConditionalArg', function () {
127
139
  }
128
140
  }, {
129
141
  a: 1
130
- }, {}, true], ['implicit falsey', {
142
+ }, {}, true], ['truthy true', {
131
143
  "if": {
132
- arg: 'a'
144
+ arg: 'a',
145
+ truthy: true
133
146
  }
134
147
  }, {
135
148
  a: 0
136
- }, {}, false], ['implicit undefined', {
149
+ }, {}, false], ['truthy false', {
137
150
  "if": {
138
- arg: 'a'
151
+ arg: 'a',
152
+ truthy: false
139
153
  }
140
- }, {}, {}, false]])('%s', function (_name, argType, args, globals, expected) {
154
+ }, {}, {}, true]])('%s', function (_name, argType, args, globals, expected) {
141
155
  // @ts-ignore
142
156
  expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
143
157
  });
144
158
  });
145
159
  describe('exists', function () {
146
- it.each([['implicit exist true', {
147
- "if": {
148
- arg: 'a'
149
- }
150
- }, {
151
- a: 1
152
- }, {}, true], ['implicit exist false', {
153
- "if": {
154
- arg: 'a'
155
- }
156
- }, {}, {}, false], ['explicit exist', {
160
+ it.each([['exist', {
157
161
  "if": {
158
162
  arg: 'a',
159
163
  exists: true
160
164
  }
161
165
  }, {
162
166
  a: 1
163
- }, {}, true], ['explicit exist false', {
167
+ }, {}, true], ['exist false', {
164
168
  "if": {
165
169
  arg: 'a',
166
170
  exists: true
@@ -216,24 +220,32 @@ describe('includeConditionalArg', function () {
216
220
  });
217
221
  });
218
222
  describe('globals', function () {
219
- describe('implicit', function () {
223
+ describe('truthy', function () {
220
224
  it.each([['implicit true', {
221
225
  "if": {
222
226
  global: 'a'
223
227
  }
224
228
  }, {}, {
225
229
  a: 1
226
- }, true], ['implicit falsey', {
230
+ }, true], ['implicit undefined', {
227
231
  "if": {
228
232
  global: 'a'
229
233
  }
234
+ }, {}, {}, false], ['truthy true', {
235
+ "if": {
236
+ global: 'a',
237
+ truthy: true
238
+ }
230
239
  }, {}, {
231
240
  a: 0
232
- }, false], ['implicit undefined', {
241
+ }, false], ['truthy false', {
233
242
  "if": {
234
- global: 'a'
243
+ global: 'a',
244
+ truthy: false
235
245
  }
236
- }, {}, {}, false]])('%s', function (_name, argType, args, globals, expected) {
246
+ }, {}, {
247
+ a: 0
248
+ }, true]])('%s', function (_name, argType, args, globals, expected) {
237
249
  // @ts-ignore
238
250
  expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
239
251
  });
package/dist/story.d.ts CHANGED
@@ -17,7 +17,9 @@ export declare type Parameters = {
17
17
  [name: string]: any;
18
18
  };
19
19
  declare type ConditionalTest = {
20
- exists?: boolean;
20
+ truthy?: boolean;
21
+ } | {
22
+ exists: boolean;
21
23
  } | {
22
24
  eq: any;
23
25
  } | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/csf",
3
- "version": "0.0.2--canary.92ac0db.0",
3
+ "version": "0.0.2--canary.7c6c115.0",
4
4
  "description": "Component Story Format (CSF) utilities",
5
5
  "keywords": [
6
6
  "storybook",
@@ -38,7 +38,10 @@
38
38
  },
39
39
  "prettier": "@storybook/linter-config/prettier.config",
40
40
  "jest": {
41
- "testEnvironment": "node"
41
+ "testEnvironment": "node",
42
+ "roots": [
43
+ "<rootDir>/src"
44
+ ]
42
45
  },
43
46
  "dependencies": {
44
47
  "lodash": "^4.17.15"