File tree 5 files changed +48
-1
lines changed
5 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"require" : " ts-node/register,source-map-support/register" ,
3
3
"watch-extensions" : " ts" ,
4
+ "watch-files" : " src/**/*.ts, test/**/*.ts" ,
4
5
"recursive" : true ,
5
6
"reporter" : " spec" ,
6
7
"timeout" : 5000
Original file line number Diff line number Diff line change 14
14
],
15
15
"scripts" : {
16
16
"build" : " sf-build" ,
17
+ "ci-docs" : " yarn sf-ci-docs" ,
17
18
"clean" : " sf-clean" ,
18
19
"clean-all" : " sf-clean all" ,
19
20
"compile" : " sf-compile" ,
20
21
"docs" : " sf-docs" ,
21
- "ci-docs" : " yarn sf-ci-docs" ,
22
22
"format" : " sf-format" ,
23
23
"lint" : " sf-lint" ,
24
24
"lint-fix" : " yarn sf-lint --fix" ,
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2022, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ */
7
+
8
+ /**
9
+ * Normalize an object to be an array if it isn't one.
10
+ *
11
+ * @param entryOrArray - An object that could be an array of its type or just its type
12
+ * @returns An array of the input element (which might be empty)
13
+ */
14
+
15
+ export const ensureArray = < T > ( entryOrArray : T | T [ ] | undefined ) : T [ ] => {
16
+ if ( entryOrArray ) {
17
+ return Array . isArray ( entryOrArray ) ? entryOrArray : [ entryOrArray ] ;
18
+ }
19
+ return [ ] ;
20
+ } ;
Original file line number Diff line number Diff line change @@ -11,3 +11,4 @@ export * from './env';
11
11
export * from './errors' ;
12
12
export * from './json' ;
13
13
export * from './nodash' ;
14
+ export * from './collections' ;
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2022, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ */
7
+ import { expect } from 'chai' ;
8
+ import { ensureArray } from '../src/collections' ;
9
+
10
+ describe ( 'collections' , ( ) => {
11
+ describe ( 'ensureArray' , ( ) => {
12
+ it ( 'undefined => empty array' , ( ) => {
13
+ const input = undefined ;
14
+ expect ( ensureArray ( input ) ) . to . deep . equal ( [ ] ) ;
15
+ } ) ;
16
+ it ( 'an array => the array' , ( ) => {
17
+ const input = [ 'a' , 'b' ] ;
18
+ expect ( ensureArray ( input ) ) . to . deep . equal ( input ) ;
19
+ } ) ;
20
+ it ( 'a single item => obj in an array' , ( ) => {
21
+ const input = 'a' ;
22
+ expect ( ensureArray ( input ) ) . to . deep . equal ( [ input ] ) ;
23
+ } ) ;
24
+ } ) ;
25
+ } ) ;
You can’t perform that action at this time.
0 commit comments