Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Feature/strings (#22)
Browse files Browse the repository at this point in the history
* added support for asEnumerable on strings

* rebuilt source files

* bumped version to 1.1.4
  • Loading branch information
Gerald Burkholder committed Apr 25, 2018
1 parent 9881bf0 commit 049f2e9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enumerablejs",
"version": "1.1.3",
"version": "1.1.4",
"homepage": "https://github.com/ralphy15/enumerable-js",
"authors": [
"Gerald Burkholder <geraldeburkholder@gmail.com>"
Expand Down
13 changes: 13 additions & 0 deletions build/js/enumerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ function Enumerable(_array)

Enumerable.fn = Enumerable.prototype;

Enumerable.fn.toString = function()
{
var separator = "";
var result = "";

for(var i = 0; i < this.collection.length; i++)
{
result += separator + this.collection[i];
}

return result;
};

Enumerable.Range = function(start, count)
{
var result = [];
Expand Down
2 changes: 1 addition & 1 deletion build/js/enumerable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asenumerable",
"version": "1.1.3",
"version": "1.1.4",
"description": "a JavaScript library that provides linq functions on native JavaScript arrays",
"dependencies": {},
"main": "src/enumerable.js",
Expand Down
24 changes: 24 additions & 0 deletions spec/asEnumerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

describe("asEnumerable", function ()
{
describe("when used on a string", function ()
{
it("should return a character array", function ()
{
var str = "abcdef";

var result = str.asEnumerable();

expect(result).toEqual(new Enumerable(["a", "b", "c", "d", "e", "f"]));
});
});

describe("when toString() is called on an enumerable of strings", function ()
{
it("should return a string", function ()
{
var str = "abcdef";

var result = str.asEnumerable().toString();

expect(result).toEqual("abcdef");
});
});

describe("when used on an empty array", function ()
{
it("should return an empty enumerable object", function ()
Expand Down
13 changes: 13 additions & 0 deletions src/enumerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ function Enumerable(_array)

Enumerable.fn = Enumerable.prototype;

Enumerable.fn.toString = function()
{
var separator = "";
var result = "";

for(var i = 0; i < this.collection.length; i++)
{
result += separator + this.collection[i];
}

return result;
};

Enumerable.Range = function(start, count)
{
var result = [];
Expand Down
13 changes: 13 additions & 0 deletions src/extensions/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var Enumerable = require('../enumerable');

String.prototype.asEnumerable = function()
{
var arr = [];

for(var i = 0; i < this.length; i++)
{
arr[i] = this.charAt(i);
}

return new Enumerable(arr);
};

0 comments on commit 049f2e9

Please sign in to comment.