1
0
Fork 0
mirror of https://github.com/mmumshad/ansible-playable.git synced 2025-03-09 23:38:54 +00:00

Initial Commit

This commit is contained in:
Mumshad Mannambeth 2017-06-07 13:36:44 -04:00
commit c92f737237
273 changed files with 16964 additions and 0 deletions

View file

@ -0,0 +1,14 @@
'use strict';
const angular = require('angular');
/*@ngInject*/
export function addDotInKeyFilter() {
return function(input) {
return JSON.parse(JSON.stringify(input).replace(/__dot__/g,'.'));
};
}
export default angular.module('webAppApp.addDotInKey', [])
.filter('addDotInKey', addDotInKeyFilter)
.name;

View file

@ -0,0 +1,17 @@
'use strict';
describe('Filter: addDotInKey', function() {
// load the filter's module
beforeEach(module('webAppApp.addDotInKey'));
// initialize a new instance of the filter before each test
var addDotInKey;
beforeEach(inject(function($filter) {
addDotInKey = $filter('addDotInKey');
}));
it('should return the input prefixed with "addDotInKey filter:"', function() {
var text = 'angularjs';
expect(addDotInKey(text)).to.equal('addDotInKey filter: ' + text);
});
});

View file

@ -0,0 +1,29 @@
'use strict';
const angular = require('angular');
/*@ngInject*/
export function dictToKeyValueArrayFilter() {
var convert = function (input,prefix) {
var result = [];
angular.forEach(input,function(value,key){
key = key.replace(/\./g,"__dot__");
if(prefix){
key = prefix + '.' + key;
}
if(typeof value != 'object'){
result.push({"key":key ,"value":value})
}else{
result = result.concat(convert(value,key))
}
});
return result;
};
return convert;
}
export default angular.module('webAppApp.dictToKeyValueArray', [])
.filter('dictToKeyValueArray', dictToKeyValueArrayFilter)
.name;

View file

@ -0,0 +1,17 @@
'use strict';
describe('Filter: dictToKeyValueArray', function() {
// load the filter's module
beforeEach(module('webAppApp.dictToKeyValueArray'));
// initialize a new instance of the filter before each test
var dictToKeyValueArray;
beforeEach(inject(function($filter) {
dictToKeyValueArray = $filter('dictToKeyValueArray');
}));
it('should return the input prefixed with "dictToKeyValueArray filter:"', function() {
var text = 'angularjs';
expect(dictToKeyValueArray(text)).to.equal('dictToKeyValueArray filter: ' + text);
});
});

View file

@ -0,0 +1,20 @@
'use strict';
const angular = require('angular');
/*@ngInject*/
export function dictToKeyValueArraySimpleFilter() {
var convert = function (input,prefix) {
var result = [];
angular.forEach(input,function(value,key){
result.push({"key":key ,"value":value})
});
return result;
};
return convert;
}
export default angular.module('webAppApp.dictToKeyValueArraySimple', [])
.filter('dictToKeyValueArraySimple', dictToKeyValueArraySimpleFilter)
.name;

View file

@ -0,0 +1,17 @@
'use strict';
describe('Filter: dictToKeyValueArraySimple', function() {
// load the filter's module
beforeEach(module('webAppApp.dictToKeyValueArraySimple'));
// initialize a new instance of the filter before each test
var dictToKeyValueArraySimple;
beforeEach(inject(function($filter) {
dictToKeyValueArraySimple = $filter('dictToKeyValueArraySimple');
}));
it('should return the input prefixed with "dictToKeyValueArraySimple filter:"', function() {
var text = 'angularjs';
expect(dictToKeyValueArraySimple(text)).to.equal('dictToKeyValueArraySimple filter: ' + text);
});
});

View file

@ -0,0 +1,118 @@
'use strict';
const angular = require('angular');
/*@ngInject*/
export function json2yamlFilter() {
/*
* TODO, lots of concatenation (slow in js)
*/
var spacing = " ";
function getType(obj) {
var type = typeof obj;
if (obj instanceof Array) {
return 'array';
} else if (type == 'string') {
return 'string';
} else if (type == 'boolean') {
return 'boolean';
} else if (type == 'number') {
return 'number';
} else if (type == 'undefined' || obj === null) {
return 'null';
} else {
return 'hash';
}
}
function convert(obj, ret) {
var type = getType(obj);
switch(type) {
case 'array':
convertArray(obj, ret);
break;
case 'hash':
convertHash(obj, ret);
break;
case 'string':
convertString(obj, ret);
break;
case 'null':
ret.push('null');
break;
case 'number':
ret.push(obj.toString());
break;
case 'boolean':
ret.push(obj ? 'true' : 'false');
break;
}
}
function convertArray(obj, ret) {
for (var i=0; i<obj.length; i++) {
var ele = obj[i];
var recurse = [];
convert(ele, recurse);
for (var j=0; j<recurse.length; j++) {
ret.push((j == 0 ? "- " : spacing) + recurse[j]);
}
}
}
function convertHash(obj, ret) {
for (var k in obj) {
var recurse = [];
if (obj.hasOwnProperty(k)) {
var ele = obj[k];
convert(ele, recurse);
var type = getType(ele);
if (type == 'string' || type == 'null' || type == 'number' || type == 'boolean') {
ret.push(normalizeString(k) + ': ' + recurse[0]);
} else {
ret.push(normalizeString(k) + ': ');
for (var i=0; i<recurse.length; i++) {
ret.push(spacing + recurse[i]);
}
}
}
}
}
function normalizeString(str) {
if (str.match(/^[\w]+$/)) {
return str;
} else {
//return '"'+escape(str).replace(/%u/g,'\\u').replace(/%U/g,'\\U').replace(/%/g,'\\x')+'"';
//return str.replace(/%u/g,'\\u').replace(/%U/g,'\\U').replace(/%/g,'\\x');
return str.replace(/%u/g,'\\u').replace(/%U/g,'\\U');
}
}
function convertString(obj, ret) {
ret.push(normalizeString(obj));
}
return function(obj) {
if (typeof obj == 'string') {
try{
obj = JSON.parse(obj);
}catch(e){
return
}
}
var ret = [];
convert(obj, ret);
return ret.join("\n");
};
}
export default angular.module('webAppApp.json2yaml', [])
.filter('json2yaml', json2yamlFilter)
.name;

View file

@ -0,0 +1,17 @@
'use strict';
describe('Filter: json2yaml', function() {
// load the filter's module
beforeEach(module('webAppApp.json2yaml'));
// initialize a new instance of the filter before each test
var json2yaml;
beforeEach(inject(function($filter) {
json2yaml = $filter('json2yaml');
}));
it('should return the input prefixed with "json2yaml filter:"', function() {
var text = 'angularjs';
expect(json2yaml(text)).to.equal('json2yaml filter: ' + text);
});
});

View file

@ -0,0 +1,18 @@
'use strict';
const angular = require('angular');
/*@ngInject*/
export function keyValueArrayToArrayFilter() {
return function(input) {
var resultItem = [];
angular.forEach(input,function(item){
resultItem.push(item.value || "");
});
return resultItem;
};
}
export default angular.module('webAppApp.keyValueArrayToArray', [])
.filter('keyValueArrayToArray', keyValueArrayToArrayFilter)
.name;

View file

@ -0,0 +1,17 @@
'use strict';
describe('Filter: keyValueArrayToArray', function() {
// load the filter's module
beforeEach(module('webAppApp.keyValueArrayToArray'));
// initialize a new instance of the filter before each test
var keyValueArrayToArray;
beforeEach(inject(function($filter) {
keyValueArrayToArray = $filter('keyValueArrayToArray');
}));
it('should return the input prefixed with "keyValueArrayToArray filter:"', function() {
var text = 'angularjs';
expect(keyValueArrayToArray(text)).to.equal('keyValueArrayToArray filter: ' + text);
});
});

View file

@ -0,0 +1,18 @@
'use strict';
const angular = require('angular');
/*@ngInject*/
export function keyValueArrayToDictFilter() {
return function(input) {
var resultItem = {};
angular.forEach(input,function(item){
resultItem[item.key] = item.value || "";
});
return resultItem;
};
}
export default angular.module('webAppApp.keyValueArrayToDict', [])
.filter('keyValueArrayToDict', keyValueArrayToDictFilter)
.name;

View file

@ -0,0 +1,17 @@
'use strict';
describe('Filter: keyValueArrayToDict', function() {
// load the filter's module
beforeEach(module('webAppApp.keyValueArrayToDict'));
// initialize a new instance of the filter before each test
var keyValueArrayToDict;
beforeEach(inject(function($filter) {
keyValueArrayToDict = $filter('keyValueArrayToDict');
}));
it('should return the input prefixed with "keyValueArrayToDict filter:"', function() {
var text = 'angularjs';
expect(keyValueArrayToDict(text)).to.equal('keyValueArrayToDict filter: ' + text);
});
});

View file

@ -0,0 +1,18 @@
'use strict';
const angular = require('angular');
/*@ngInject*/
export function removeDotInKeyFilter() {
return function(input) {
var result = {};
angular.forEach(input,function(value,key){
result[key.replace(/\./g,'__dot__')] = value
});
return result;
};
}
export default angular.module('webAppApp.removeDotInKey', [])
.filter('removeDotInKey', removeDotInKeyFilter)
.name;

View file

@ -0,0 +1,17 @@
'use strict';
describe('Filter: removeDotInKey', function() {
// load the filter's module
beforeEach(module('webAppApp.removeDotInKey'));
// initialize a new instance of the filter before each test
var removeDotInKey;
beforeEach(inject(function($filter) {
removeDotInKey = $filter('removeDotInKey');
}));
it('should return the input prefixed with "removeDotInKey filter:"', function() {
var text = 'angularjs';
expect(removeDotInKey(text)).to.equal('removeDotInKey filter: ' + text);
});
});