BREAKING CHANGE(scope): change scope to @pushrocks

This commit is contained in:
2018-07-21 14:37:39 +02:00
parent e9899e5451
commit 62336aa2cf
42 changed files with 1312 additions and 1289 deletions

View File

@@ -1,17 +1,11 @@
import * as create from './smartstring.create'
import * as docker from './smartstring.docker'
import * as indent from './smartstring.indent'
import * as normalize from './smartstring.normalize'
import * as typescript from './smartstring.typescript'
import * as create from './smartstring.create';
import * as docker from './smartstring.docker';
import * as indent from './smartstring.indent';
import * as normalize from './smartstring.normalize';
import * as typescript from './smartstring.typescript';
export {
create,
docker,
typescript,
normalize,
indent
}
export { create, docker, typescript, normalize, indent };
export { Base64, base64 } from './smartstring.base64'
export { Domain } from './smartstring.domain'
export { GitRepo } from './smartstring.git'
export { Base64, base64 } from './smartstring.base64';
export { Domain } from './smartstring.domain';
export { GitRepo } from './smartstring.git';

View File

@@ -1,47 +1,47 @@
import * as plugins from './smartstring.plugins'
import * as plugins from './smartstring.plugins';
/**
* the type for base 64
*/
export type TBase64Input = 'string' | 'base64' | 'base64uri'
export type TBase64Input = 'string' | 'base64' | 'base64uri';
/**
* handle base64 strings
*/
export class Base64 {
private refString: string
private refString: string;
constructor(inputStringArg, typeArg: TBase64Input) {
switch (typeArg) {
case 'string': // easiest case
this.refString = inputStringArg
break
this.refString = inputStringArg;
break;
case 'base64':
this.refString = base64.decode(inputStringArg)
break
this.refString = base64.decode(inputStringArg);
break;
case 'base64uri':
this.refString = base64.decode(inputStringArg)
this.refString = base64.decode(inputStringArg);
}
}
/**
* the simple string (unencoded)
*/
get simpleString () {
return this.refString
get simpleString() {
return this.refString;
}
/**
* the base64 encoded version of the original string
*/
get base64String () {
return base64.encode(this.refString)
get base64String() {
return base64.encode(this.refString);
}
/**
* the base64uri encoded version of the original string
*/
get base64UriString () {
return base64.encodeUri(this.refString)
get base64UriString() {
return base64.encodeUri(this.refString);
}
}
@@ -50,20 +50,20 @@ export let base64 = {
* encodes the string
*/
encode: (stringArg: string) => {
return plugins.jsBase64.encode(stringArg)
return plugins.jsBase64.encode(stringArg);
},
/**
* encodes a stringArg to base64 uri style
*/
encodeUri: (stringArg: string) => {
return plugins.jsBase64.encodeURI(stringArg)
return plugins.jsBase64.encodeURI(stringArg);
},
/**
* decodes a base64 encoded string
*/
decode: (stringArg: string) => {
return plugins.jsBase64.decode(stringArg)
return plugins.jsBase64.decode(stringArg);
}
}
};

View File

@@ -1,13 +1,13 @@
import * as plugins from './smartstring.plugins'
import * as plugins from './smartstring.plugins';
export const createRandomString = (
patternArg: string,
lengthArg: number,
optionsArg: any
): string => {
return plugins.randomatic(patternArg, lengthArg, optionsArg)
}
return plugins.randomatic(patternArg, lengthArg, optionsArg);
};
export const createCryptoRandomString = (lengthArg): string => {
return plugins.cryptoRandomString(lengthArg)
}
return plugins.cryptoRandomString(lengthArg);
};

View File

@@ -1,18 +1,18 @@
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.
* @param envArrayArg
* @returns {}
*/
export const makeEnvObject = function (envArrayArg: string[]) {
let returnObject = {}
let regexString = /(.*)=(.*)/
export const makeEnvObject = function(envArrayArg: string[]) {
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;
};

View File

@@ -1,62 +1,61 @@
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
fullName: string;
level1: string;
level2: string;
level3: string;
level4: string;
level5: string;
protocol: string;
zoneName: string;
// aliases
topLevel: string
domainName
subDomain
constructor (domainStringArg: string) {
topLevel: string;
domainName;
subDomain;
constructor(domainStringArg: string) {
let regexMatches = domainRegex(domainStringArg);
this.fullName = ''
this.fullName = '';
for (let i = 1; i <= 5; i++) {
if (regexMatches[ i - 1 ]) {
let localMatch = regexMatches[ i - 1 ]
this[ 'level' + i.toString() ] = localMatch
if (regexMatches[i - 1]) {
let localMatch = regexMatches[i - 1];
this['level' + i.toString()] = localMatch;
if (this.fullName === '') {
this.fullName = localMatch
this.fullName = localMatch;
} else {
this.fullName = localMatch + '.' + this.fullName
this.fullName = localMatch + '.' + this.fullName;
}
} else {
this[ 'level' + i.toString() ] = undefined
};
};
this.protocol = protocolRegex(domainStringArg)
this.zoneName = this.level2 + '.' + this.level1
this['level' + i.toString()] = undefined;
}
}
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 regexMatchesFiltered = regexMatches.filter(function (stringArg: string) {
return (stringArg !== '')
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 regexMatchesFiltered = regexMatches.filter(function(stringArg: string) {
return stringArg !== '';
});
return regexMatchesFiltered
return regexMatchesFiltered;
};
let protocolRegex = function (stringArg: string) {
let regexString = /^([a-zA-Z0-9]*):\/\//
let regexMatches = regexString.exec(stringArg)
let protocolRegex = function(stringArg: string) {
let regexString = /^([a-zA-Z0-9]*):\/\//;
let regexMatches = regexString.exec(stringArg);
if (regexMatches) {
return regexMatches[ 1 ]
return regexMatches[1];
} else {
return undefined
return undefined;
}
}
};

View File

@@ -1,52 +1,56 @@
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 ------------------- *
* ---------------------------------------------- */
const gitRegex = function (stringArg: string) {
const regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-\.]*)(?:\/)([a-zA-Z0-9\-\.]*)(?:\.git)/
let regexMatches = regexString.exec(stringArg)
return regexMatches
}
const gitRegex = function(stringArg: string) {
const regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-\.]*)(?:\/)([a-zA-Z0-9\-\.]*)(?:\.git)/;
let regexMatches = regexString.exec(stringArg);
return regexMatches;
};
const gitLink = function (hostArg: string, userArg: string, repoArg: string, tokenArg: string = '', linkTypeArg): string {
let returnString
const gitLink = function(
hostArg: string,
userArg: string,
repoArg: string,
tokenArg: string = '',
linkTypeArg
): string {
let returnString;
if (tokenArg !== '') {
tokenArg = tokenArg + '@'
tokenArg = tokenArg + '@';
}
switch (linkTypeArg) {
case 'https':
returnString = 'https://' +
tokenArg + hostArg + '/' + userArg + '/' + repoArg + '.git'
break
returnString = 'https://' + tokenArg + hostArg + '/' + userArg + '/' + repoArg + '.git';
break;
case 'ssh':
returnString = 'git@' +
hostArg + ':' + userArg + '/' + repoArg + '.git'
break
returnString = 'git@' + hostArg + ':' + userArg + '/' + repoArg + '.git';
break;
default:
console.error('Link Type ' + linkTypeArg + ' not known')
break
console.error('Link Type ' + linkTypeArg + ' not known');
break;
}
return returnString
}
return returnString;
};

View File

@@ -1,40 +1,40 @@
import * as plugins from './smartstring.plugins'
import * as plugins from './smartstring.plugins';
/**
* splits a string into an array
* @param stringArg
*/
const splitStringAtLineBreak = (stringArg: string): string[] => {
let resultArray = stringArg.split('\n')
return cleanStringArray(resultArray)
}
let resultArray = stringArg.split('\n');
return cleanStringArray(resultArray);
};
/**
* joins a string together again
* @param stringArrayArg
*/
const joinStringWithLineBreaks = (stringArrayArg: string[]): string => {
let resultString: string = ''
let resultString: string = '';
for (let line of stringArrayArg) {
resultString = resultString + line + '\n' // add new line at end
resultString = resultString + line + '\n'; // add new line at end
}
return resultString
}
return resultString;
};
/**
* cleans first and last line in case they are empty
* @param stringArrayArg
*/
const cleanStringArray = (stringArrayArg: string[]): string[] => {
let testRegex = /^[\s]*$/
if (testRegex.test(stringArrayArg[ 0 ])) {
stringArrayArg.shift()
let testRegex = /^[\s]*$/;
if (testRegex.test(stringArrayArg[0])) {
stringArrayArg.shift();
}
if (testRegex.test(stringArrayArg[ stringArrayArg.length - 1 ])) {
stringArrayArg.pop()
if (testRegex.test(stringArrayArg[stringArrayArg.length - 1])) {
stringArrayArg.pop();
}
return stringArrayArg
}
return stringArrayArg;
};
/**
* indent an array
@@ -42,13 +42,13 @@ const cleanStringArray = (stringArrayArg: string[]): string[] => {
* @param spaceAmount
*/
export const indent = (stringArg: string, spaceAmount: number): string => {
let localStringArray = splitStringAtLineBreak(stringArg)
let localStringArray = splitStringAtLineBreak(stringArg);
for (let stringArg of localStringArray) {
stringArg = ' '.repeat(spaceAmount) + stringArg
stringArg = ' '.repeat(spaceAmount) + stringArg;
}
let resultString = joinStringWithLineBreaks(localStringArray)
return resultString
}
let resultString = joinStringWithLineBreaks(localStringArray);
return resultString;
};
/**
* indents a string with prefix
@@ -56,37 +56,37 @@ export const indent = (stringArg: string, spaceAmount: number): string => {
* @param prefixArg
*/
export const indentWithPrefix = (stringArg: string, prefixArg: string): string => {
let resultString: string
let stringArray = splitStringAtLineBreak(stringArg)
let resultArray: string[] = []
let resultString: string;
let stringArray = splitStringAtLineBreak(stringArg);
let resultArray: string[] = [];
for (let stringItem of stringArray) {
resultArray.push(prefixArg + stringItem)
resultArray.push(prefixArg + stringItem);
}
resultString = joinStringWithLineBreaks(resultArray)
return resultString
}
resultString = joinStringWithLineBreaks(resultArray);
return resultString;
};
export const normalize = (stringArg: string): string => {
let resultString: string
let splitStringArray: string[] = splitStringAtLineBreak(stringArg)
let minCommonLeftOffset: number
let resultString: string;
let splitStringArray: string[] = splitStringAtLineBreak(stringArg);
let minCommonLeftOffset: number;
const deIndentRegex = /^(\s*)/
const emptyLineRegex = /^(\s*)$/
const deIndentRegex = /^(\s*)/;
const emptyLineRegex = /^(\s*)$/;
for (let stringItem of splitStringArray) {
let offsetString = deIndentRegex.exec(stringItem)[ 1 ]
let offsetString = deIndentRegex.exec(stringItem)[1];
if (
(typeof minCommonLeftOffset === 'undefined' || offsetString.length < minCommonLeftOffset)
&& !emptyLineRegex.test(stringItem)
(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))
}
resultString = joinStringWithLineBreaks(resultSplitStringArray)
return resultString
}
let resultSplitStringArray = [];
for (let stringItem of splitStringArray) {
resultSplitStringArray.push(stringItem.substr(minCommonLeftOffset));
}
resultString = joinStringWithLineBreaks(resultSplitStringArray);
return resultString;
};

View File

@@ -1,22 +1,22 @@
import * as plugins from './smartstring.plugins'
import * as plugins from './smartstring.plugins';
/**
* replaces all occurences of something in a string
* @param stringArg
* @param searchRegExp
* @param replacementString
* @param searchRegExp
* @param replacementString
*/
export const replaceAll = (stringArg: string, searchRegExp: any, replacementString: string) => {
return stringArg.replace(new RegExp(searchRegExp, 'g'), replacementString)
}
return stringArg.replace(new RegExp(searchRegExp, 'g'), replacementString);
};
/**
* normalizes a string
* @param stringArg
*/
export const standard = (stringArg: string): string => {
let fix1 = plugins.stripIndent(stringArg) // fix indention
let fix2 = plugins.normalizeNewline(fix1) // fix newlines
let fix3 = replaceAll(fix2, /\t/, ' ') // fix tabs
return fix3
}
let fix1 = plugins.stripIndent(stringArg); // fix indention
let fix2 = plugins.normalizeNewline(fix1); // fix newlines
let fix3 = replaceAll(fix2, /\t/, ' '); // fix tabs
return fix3;
};

View File

@@ -1,7 +1,7 @@
import 'typings-global'
export let jsBase64 = require('js-base64').Base64
import 'typings-global';
export let jsBase64 = require('js-base64').Base64;
export let stripIndent = require('strip-indent')
export let normalizeNewline = require('normalize-newline')
export let randomatic = require('randomatic')
export let cryptoRandomString = require('crypto-random-string')
export let stripIndent = require('strip-indent');
export let normalizeNewline = require('normalize-newline');
export let randomatic = require('randomatic');
export let cryptoRandomString = require('crypto-random-string');

View File

@@ -1,3 +1,3 @@
import * as plugins from './smartstring.plugins'
import * as plugins from './smartstring.plugins';
export const regexReferencePath = /\/\/\/\s*<reference\s+path\s*=\s*["|'].*["|']\s*\/>\s*[\\n]?/
export const regexReferencePath = /\/\/\/\s*<reference\s+path\s*=\s*["|'].*["|']\s*\/>\s*[\\n]?/;