add Base64 handling
This commit is contained in:
21
ts/index.ts
21
ts/index.ts
@ -1,10 +1,13 @@
|
||||
import * as plugins from "./smartstring.plugins";
|
||||
import * as SmartstringDocker from "./smartstring.docker";
|
||||
import * as SmartstringTypescript from "./smartstring.typescript";
|
||||
import * as SmartstringIndent from "./smartstring.indent";
|
||||
import * as docker from './smartstring.docker'
|
||||
import * as indent from './smartstring.indent'
|
||||
import * as typescript from './smartstring.typescript'
|
||||
|
||||
export {Domain} from "./smartstring.domain";
|
||||
export {GitRepo} from "./smartstring.git";
|
||||
export let docker = SmartstringDocker;
|
||||
export let typescript = SmartstringTypescript;
|
||||
export let indent = SmartstringIndent;
|
||||
export {
|
||||
docker,
|
||||
typescript,
|
||||
indent
|
||||
}
|
||||
|
||||
export { Base64 } from './smartstring.base64'
|
||||
export { Domain } from './smartstring.domain'
|
||||
export { GitRepo } from './smartstring.git'
|
||||
|
46
ts/smartstring.base64.ts
Normal file
46
ts/smartstring.base64.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import * as plugins from './smartstring.plugins'
|
||||
|
||||
/**
|
||||
* the type for base 64
|
||||
*/
|
||||
export type TBase64Input = 'string' | 'base64' | 'base64uri'
|
||||
|
||||
/**
|
||||
* handle base64 strings
|
||||
*/
|
||||
export class Base64 {
|
||||
private refString: string
|
||||
constructor(inputStringArg, typeArg: TBase64Input) {
|
||||
switch (typeArg) {
|
||||
case 'string': // easiest case
|
||||
this.refString = inputStringArg
|
||||
break
|
||||
case 'base64':
|
||||
this.refString = plugins.jsBase64.decode(inputStringArg)
|
||||
break
|
||||
case 'base64uri':
|
||||
this.refString = plugins.jsBase64.decode(inputStringArg)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the simple string (unencoded)
|
||||
*/
|
||||
get simpleString() {
|
||||
return this.refString
|
||||
}
|
||||
|
||||
/**
|
||||
* the base64 encoded version of the original string
|
||||
*/
|
||||
get base64String() {
|
||||
return plugins.jsBase64.encode(this.refString)
|
||||
}
|
||||
|
||||
/**
|
||||
* the base64uri encoded version of the original string
|
||||
*/
|
||||
get base64StringUri() {
|
||||
return plugins.jsBase64.encodeURI(this.refString)
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from "./smartstring.plugins";
|
||||
import * as plugins from './smartstring.plugins'
|
||||
|
||||
/**
|
||||
* converts an erray of env strings from docker remote api to an usable object.
|
||||
@ -6,13 +6,13 @@ import * as plugins from "./smartstring.plugins";
|
||||
* @returns {}
|
||||
*/
|
||||
export let makeEnvObject = function (envArrayArg: string[]) {
|
||||
let returnObject = {};
|
||||
let regexString = /(.*)=(.*)/;
|
||||
if (typeof envArrayArg !== "undefined") {
|
||||
let returnObject = {}
|
||||
let regexString = /(.*)=(.*)/
|
||||
if (typeof envArrayArg !== 'undefined') {
|
||||
for (let envKey in envArrayArg) {
|
||||
let regexMatches = regexString.exec(envArrayArg[envKey]);
|
||||
returnObject[regexMatches[1]] = regexMatches[2];
|
||||
let regexMatches = regexString.exec(envArrayArg[envKey])
|
||||
returnObject[regexMatches[1]] = regexMatches[2]
|
||||
};
|
||||
}
|
||||
return returnObject;
|
||||
};
|
||||
return returnObject
|
||||
}
|
||||
|
@ -1,62 +1,62 @@
|
||||
import * as plugins from "./smartstring.plugins";
|
||||
import * as plugins from './smartstring.plugins';
|
||||
|
||||
export class Domain {
|
||||
fullName:string;
|
||||
level1:string;
|
||||
level2:string;
|
||||
level3:string;
|
||||
level4:string;
|
||||
level5:string;
|
||||
protocol:string;
|
||||
zoneName:string;
|
||||
//aliases
|
||||
topLevel:string;
|
||||
domainName;
|
||||
subDomain;
|
||||
fullName: string
|
||||
level1: string
|
||||
level2: string
|
||||
level3: string
|
||||
level4: string
|
||||
level5: string
|
||||
protocol: string
|
||||
zoneName: string
|
||||
// aliases
|
||||
topLevel: string
|
||||
domainName
|
||||
subDomain
|
||||
constructor(domainStringArg:string){
|
||||
let regexMatches = domainRegex(domainStringArg);
|
||||
this.fullName = "";
|
||||
for(let i = 1; i <= 5; i++){
|
||||
if(regexMatches[i - 1]) {
|
||||
this.fullName = ''
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
if (regexMatches[i - 1]) {
|
||||
let localMatch = regexMatches[i - 1]
|
||||
this["level" + i.toString()] = localMatch;
|
||||
if (this.fullName == ""){
|
||||
this.fullName = localMatch;
|
||||
this['level' + i.toString()] = localMatch
|
||||
if (this.fullName === ''){
|
||||
this.fullName = localMatch
|
||||
} else {
|
||||
this.fullName = localMatch + "." + this.fullName;
|
||||
this.fullName = localMatch + '.' + this.fullName
|
||||
}
|
||||
} else {
|
||||
this["level" + i.toString()] = undefined;
|
||||
this['level' + i.toString()] = undefined
|
||||
};
|
||||
};
|
||||
this.protocol = protocolRegex(domainStringArg);
|
||||
this.zoneName = this.level2 + "." + this.level1;
|
||||
|
||||
this.protocol = protocolRegex(domainStringArg)
|
||||
this.zoneName = this.level2 + '.' + this.level1
|
||||
|
||||
// aliases
|
||||
this.topLevel = this.level1;
|
||||
this.domainName = this.level2;
|
||||
this.subDomain = this.level3;
|
||||
this.topLevel = this.level1
|
||||
this.domainName = this.level2
|
||||
this.subDomain = this.level3
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let domainRegex = function(stringArg:string){
|
||||
let regexString = /([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}$/;
|
||||
let regexMatches = regexString.exec(stringArg);
|
||||
regexMatches.reverse(); //make sure we build the domain from toplevel to subdomain (reversed order)
|
||||
regexMatches.pop(); // pop the last element, which is, since we reversed the Array, the full String of matched elements
|
||||
let regexString = /([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}$/
|
||||
let regexMatches = regexString.exec(stringArg)
|
||||
regexMatches.reverse() //make sure we build the domain from toplevel to subdomain (reversed order)
|
||||
regexMatches.pop() // pop the last element, which is, since we reversed the Array, the full String of matched elements
|
||||
let regexMatchesFiltered = regexMatches.filter(function(stringArg:string){
|
||||
return(stringArg != "");
|
||||
return(stringArg !== '')
|
||||
});
|
||||
return regexMatchesFiltered;
|
||||
return regexMatchesFiltered
|
||||
};
|
||||
|
||||
let protocolRegex = function(stringArg:string){
|
||||
let regexString = /^([a-zA-Z0-9]*):\/\//;
|
||||
let regexMatches = regexString.exec(stringArg);
|
||||
if(regexMatches){
|
||||
return regexMatches[1];
|
||||
let regexString = /^([a-zA-Z0-9]*):\/\//
|
||||
let regexMatches = regexString.exec(stringArg)
|
||||
if(regexMatches) {
|
||||
return regexMatches[1]
|
||||
} else {
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,52 +1,52 @@
|
||||
import * as plugins from "./smartstring.plugins";
|
||||
import * as plugins from './smartstring.plugins'
|
||||
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ classes ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
export class GitRepo {
|
||||
host:string;
|
||||
user:string;
|
||||
repo:string;
|
||||
accessToken:string;
|
||||
sshUrl:string;
|
||||
httpsUrl:string;
|
||||
constructor(stringArg:string,tokenArg?:string){
|
||||
let regexMatches = gitRegex(stringArg);
|
||||
this.host = regexMatches[1];
|
||||
this.user = regexMatches[2];
|
||||
this.repo = regexMatches[3];
|
||||
this.accessToken = tokenArg;
|
||||
this.sshUrl = gitLink(this.host,this.user,this.repo,this.accessToken, "ssh");
|
||||
this.httpsUrl = gitLink(this.host,this.user,this.repo,this.accessToken, "https");
|
||||
};
|
||||
host: string
|
||||
user: string
|
||||
repo: string
|
||||
accessToken: string
|
||||
sshUrl: string
|
||||
httpsUrl: string
|
||||
constructor(stringArg: string,tokenArg?: string) {
|
||||
let regexMatches = gitRegex(stringArg)
|
||||
this.host = regexMatches[1]
|
||||
this.user = regexMatches[2]
|
||||
this.repo = regexMatches[3]
|
||||
this.accessToken = tokenArg
|
||||
this.sshUrl = gitLink(this.host,this.user,this.repo,this.accessToken, 'ssh')
|
||||
this.httpsUrl = gitLink(this.host,this.user,this.repo,this.accessToken, 'https')
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ helpers ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
let gitRegex = function(stringArg:string){
|
||||
let regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-]*)(?:\/)([a-zA-Z0-9\-]*)(?:\.git)/;
|
||||
let regexMatches = regexString.exec(stringArg);
|
||||
return regexMatches;
|
||||
};
|
||||
let regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-]*)(?:\/)([a-zA-Z0-9\-]*)(?:\.git)/
|
||||
let regexMatches = regexString.exec(stringArg)
|
||||
return regexMatches
|
||||
}
|
||||
|
||||
let gitLink = function(hostArg:string, userArg:string, repoArg:string, tokenArg:string = "", linkTypeArg):string{
|
||||
let returnString;
|
||||
if (tokenArg !== ""){
|
||||
tokenArg = tokenArg + "@"
|
||||
let gitLink = function(hostArg: string, userArg: string, repoArg: string, tokenArg: string = '', linkTypeArg): string{
|
||||
let returnString
|
||||
if (tokenArg !== '') {
|
||||
tokenArg = tokenArg + '@'
|
||||
}
|
||||
switch (linkTypeArg) {
|
||||
case "https":
|
||||
returnString = "https://" +
|
||||
tokenArg + hostArg + "/" + userArg + "/" + repoArg + ".git";
|
||||
break;
|
||||
case "ssh":
|
||||
returnString = "git@" +
|
||||
hostArg + ":" + userArg + "/" + repoArg + ".git";
|
||||
break;
|
||||
case 'https':
|
||||
returnString = 'https://' +
|
||||
tokenArg + hostArg + '/' + userArg + '/' + repoArg + '.git'
|
||||
break
|
||||
case 'ssh':
|
||||
returnString = 'git@' +
|
||||
hostArg + ':' + userArg + '/' + repoArg + '.git';
|
||||
break
|
||||
default:
|
||||
plugins.beautylog.error("Link Type " + linkTypeArg + " not known");
|
||||
break;
|
||||
console.error('Link Type ' + linkTypeArg + ' not known')
|
||||
break
|
||||
}
|
||||
return returnString;
|
||||
};
|
||||
return returnString
|
||||
}
|
||||
|
@ -1,64 +1,64 @@
|
||||
import * as plugins from "./smartstring.plugins";
|
||||
import * as plugins from './smartstring.plugins'
|
||||
|
||||
let splitString = (stringArg:string):string[] => {
|
||||
let resultArray = stringArg.split("\n");
|
||||
return cleanStringArray(resultArray);
|
||||
let splitString = (stringArg: string): string[] => {
|
||||
let resultArray = stringArg.split('\n')
|
||||
return cleanStringArray(resultArray)
|
||||
};
|
||||
|
||||
let joinString = (stringArrayArg:string[]):string => {
|
||||
let resultString:string = "";
|
||||
for(let line of stringArrayArg){
|
||||
resultString = resultString + line + "\n";
|
||||
};
|
||||
return resultString;
|
||||
};
|
||||
|
||||
let cleanStringArray = (stringArrayArg:string[]):string[] => {
|
||||
let testRegex = /^[\s]*$/;
|
||||
if(testRegex.test(stringArrayArg[0])){
|
||||
stringArrayArg.shift();
|
||||
let joinString = (stringArrayArg: string[]): string => {
|
||||
let resultString: string = ''
|
||||
for (let line of stringArrayArg){
|
||||
resultString = resultString + line + '\n'
|
||||
}
|
||||
if(testRegex.test(stringArrayArg[stringArrayArg.length - 1])){
|
||||
stringArrayArg.pop();
|
||||
};
|
||||
return stringArrayArg;
|
||||
return resultString
|
||||
}
|
||||
|
||||
export let indent = (stringArg:string,spaceAmount:number):string => {
|
||||
let resultString:string;
|
||||
return resultString;
|
||||
};
|
||||
|
||||
export let indentWithPrefix = (stringArg:string,prefixArg:string):string => {
|
||||
let resultString:string;
|
||||
let stringArray = splitString(stringArg);
|
||||
let resultArray:string[] = [];
|
||||
for(let stringItem of stringArray){
|
||||
resultArray.push(prefixArg + stringItem);
|
||||
let cleanStringArray = (stringArrayArg: string[]): string[] => {
|
||||
let testRegex = /^[\s]*$/
|
||||
if (testRegex.test(stringArrayArg[0])) {
|
||||
stringArrayArg.shift()
|
||||
}
|
||||
if (testRegex.test(stringArrayArg[stringArrayArg.length - 1])) {
|
||||
stringArrayArg.pop()
|
||||
};
|
||||
resultString = joinString(resultArray);
|
||||
return resultString;
|
||||
};
|
||||
return stringArrayArg
|
||||
}
|
||||
|
||||
export let normalize = (stringArg:string):string => {
|
||||
let resultString:string;
|
||||
let splitStringArray:string[] = splitString(stringArg);
|
||||
let minCommonLeftOffset:number;
|
||||
let deIndentRegex = /^(\s*)/;
|
||||
export let indent = (stringArg: string, spaceAmount: number): string => {
|
||||
let resultString: string
|
||||
return resultString
|
||||
}
|
||||
|
||||
export let indentWithPrefix = (stringArg: string,prefixArg: string): string => {
|
||||
let resultString: string
|
||||
let stringArray = splitString(stringArg)
|
||||
let resultArray: string[] = []
|
||||
for (let stringItem of stringArray){
|
||||
resultArray.push(prefixArg + stringItem)
|
||||
};
|
||||
resultString = joinString(resultArray)
|
||||
return resultString
|
||||
}
|
||||
|
||||
export let normalize = (stringArg: string): string => {
|
||||
let resultString: string
|
||||
let splitStringArray: string[] = splitString(stringArg)
|
||||
let minCommonLeftOffset: number
|
||||
let deIndentRegex = /^(\s*)/
|
||||
let emptyLineRegex = /^(\s*)$/
|
||||
for(let stringItem of splitStringArray){
|
||||
let offsetString = deIndentRegex.exec(stringItem)[1];
|
||||
for (let stringItem of splitStringArray){
|
||||
let offsetString = deIndentRegex.exec(stringItem)[1]
|
||||
if (
|
||||
(typeof minCommonLeftOffset == "undefined" || offsetString.length < minCommonLeftOffset)
|
||||
(typeof minCommonLeftOffset === 'undefined' || offsetString.length < minCommonLeftOffset)
|
||||
&& !emptyLineRegex.test(stringItem)
|
||||
){
|
||||
minCommonLeftOffset = offsetString.length;
|
||||
};
|
||||
) {
|
||||
minCommonLeftOffset = offsetString.length
|
||||
}
|
||||
};
|
||||
let resultSplitStringArray = [];
|
||||
for(let stringItem of splitStringArray){
|
||||
resultSplitStringArray.push(stringItem.substr(minCommonLeftOffset));
|
||||
let resultSplitStringArray = []
|
||||
for (let stringItem of splitStringArray) {
|
||||
resultSplitStringArray.push(stringItem.substr(minCommonLeftOffset))
|
||||
};
|
||||
resultString = joinString(resultSplitStringArray);
|
||||
return resultString;
|
||||
resultString = joinString(resultSplitStringArray)
|
||||
return resultString
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
import "typings-global"
|
||||
export import beautylog = require("beautylog");
|
||||
import 'typings-global'
|
||||
export let jsBase64 = require('js-base64').Base64
|
||||
|
@ -1,3 +1,3 @@
|
||||
import * as plugins from "./smartstring.plugins";
|
||||
import * as plugins from './smartstring.plugins'
|
||||
|
||||
export let regexReferencePath = /\/\/\/\s*<reference\s+path\s*=\s*["|'].*["|']\s*\/>\s*[\\n]?/
|
||||
export let regexReferencePath = /\/\/\/\s*<reference\s+path\s*=\s*["|'].*["|']\s*\/>\s*[\\n]?/
|
||||
|
Reference in New Issue
Block a user