-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stdlib [array]: Better array joining
- Loading branch information
Vihan
committed
Jul 10, 2016
1 parent
52ca626
commit 6627f70
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default (api) => ["collapse", api.var(new api.func( | ||
[ | ||
["dimensions", { | ||
Type: api.string, | ||
Splat: true | ||
}] | ||
], | ||
function(scope, input) { | ||
// TODO: | ||
} | ||
))]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export default (api) => ["fuse", api.prop(new api.func( | ||
[], | ||
function(scope, input) { | ||
let self = input("self").value; | ||
|
||
let stringified = "", | ||
cast, text; | ||
|
||
for (let i = 0; i < self.length; i++) { | ||
cast = (self[i] instanceof api.string) || self[i].constructor.Cast.get('String'); | ||
|
||
if (cast) { | ||
if (cast === true) { | ||
text = self[i].value; | ||
} else { | ||
text = cast(self[i]).value; | ||
} | ||
stringified += "" + text; | ||
} else { | ||
return `Cannot stringify \`${ | ||
self[i].constructor.Name || self[i].Name | ||
}\` in join`; | ||
} | ||
} | ||
|
||
return api.init(api.string, stringified); | ||
} | ||
))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var TestCheddarFrom = require('../../globals').TestCheddarFrom; | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
chai.should(); | ||
|
||
describe('Array', function() { | ||
describe('has', function() { | ||
it('should print true', TestCheddarFrom.Code( | ||
'print [1] has 1', | ||
'true' | ||
)) | ||
|
||
it('should print false', TestCheddarFrom.Code( | ||
'print [1] has 2', | ||
'false' | ||
)) | ||
}) | ||
}); |