Compare commits
87 Commits
Author | SHA1 | Date | |
---|---|---|---|
ec0b82de00 | |||
5e69664f59 | |||
f5838f6d6a | |||
fb4a03ad37 | |||
ceb6962a1c | |||
ffe757d820 | |||
60eb4b6b6e | |||
f73d394d35 | |||
212f41e00b | |||
59847dd287 | |||
7fa2fb1e74 | |||
355f7442ca | |||
88af0ab9aa | |||
5b5bcd804f | |||
8c894ea1c1 | |||
62336aa2cf | |||
e9899e5451 | |||
235f380139 | |||
4a94ce3038 | |||
7c4c787539 | |||
714e3a162c | |||
099bf9b270 | |||
83279a9c19 | |||
55d679e5ee | |||
974bf90703 | |||
93029d1aae | |||
3a7740024c | |||
a412285862 | |||
a57bd446d0 | |||
afe8d5bc1b | |||
576e81588d | |||
76c590b045 | |||
bb7caa36ea | |||
a3a51bf0ca | |||
1684eae1e8 | |||
39ce541532 | |||
c2a4f05b33 | |||
3858127968 | |||
68d0124c24 | |||
16f41a7d63 | |||
d13dfc9e76 | |||
942f6b37cf | |||
211c7c3308 | |||
a55d6d2221 | |||
98ca73d0c7 | |||
ffedc7f601 | |||
8344fdf7b1 | |||
543dc98961 | |||
9c60105685 | |||
bdccf2c3a1 | |||
34d6df0923 | |||
3d3b07b7cb | |||
00004f70d6 | |||
2d263244c7 | |||
8cb1405d99 | |||
d357d6e52d | |||
c124f90a91 | |||
4bcf9f941e | |||
afb204325b | |||
cefbb6eecd | |||
c6a1a45812 | |||
00a892ee82 | |||
0eb6d13be9 | |||
c34f9611f9 | |||
820360a220 | |||
3893985bb2 | |||
33e19c54d9 | |||
074996433e | |||
6a803f1db9 | |||
927262d6d4 | |||
df39887de9 | |||
2b52b76ac6 | |||
136a06ff68 | |||
44bb4fa9ae | |||
93d5fc3070 | |||
08cd48b7bc | |||
bb17908ef5 | |||
3b8e31c8b0 | |||
a990c5ca32 | |||
2d4c480c1b | |||
05cd515824 | |||
bd4de36143 | |||
6a1fb1ec50 | |||
930f351626 | |||
9f6ab54a05 | |||
dcd7423921 | |||
5de7c2517d |
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,7 +1,4 @@
|
||||
.idea/
|
||||
coverage/
|
||||
docs/
|
||||
node_modules
|
||||
ts/**/*.js
|
||||
ts/**/*.js.map
|
||||
ts/typings/
|
||||
.yarn/
|
||||
pages/
|
||||
public/
|
||||
node_modules/
|
||||
|
150
.gitlab-ci.yml
Normal file
150
.gitlab-ci.yml
Normal file
@ -0,0 +1,150 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
sast:
|
||||
stage: security
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
||||
--volume "$PWD:/code"
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
||||
artifacts:
|
||||
reports:
|
||||
sast: gl-sast-report.json
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
12
.travis.yml
12
.travis.yml
@ -1,12 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '4.3.0'
|
||||
- 'stable'
|
||||
deploy:
|
||||
provider: npm
|
||||
email: npm@lossless.digital
|
||||
api_key:
|
||||
secure: oKx1gdYYBnaoUcpxn3WM4SdZdInIYaa3ZgbXLSh88K+PjbcSw3NNbYEnAtWFV1eAQQchDjOHId4D1Ne68DtJb5umahvhYoejtZzawjPaa6Uyi46VPk31wXYzZJyadiyefuwOhLLMM4i3yzYwEC2BeTpbU8Tvaj6B42DoySKNGUnSF9+K2wsFNp13mRje6PLe+fjo+9H4CEKLwf74alwvAWd/PLzv47KKdCZ4/9zX7TxevrIBNie+n6VxjqXm/dTv9k7J3dCunojehBr9X9sn1sd8mR+FexjcgfCA2dz8ViP8qZCslzZixGVuasmjpQH9OabrlOfQ6e+Hs4puv+U7s53SVa9nWntiYHloT29UKCPG6ofuDFq5Nd+1PCNvPfrh99F87IKTOw9DQ9Lx7Q//To4LrbnsC85/uHgkWHhbr/ZGax7wuX9og1rem1MSjYr7gQ1sx9edtDSQe3Yjhi22xDREL5/uCbnThmrd1P44CtAU7UG4TQvnHADFqi4Oogf/VBQvsC+aUJPSfZuoxX31yCYuNToH65j1Vblj9tYuPdHSriPj2OdxbuWh68lpgsh7K64Imb++3oKjh3fKZEzeJsByI+QytyUwO/Qu1c6whlkyv8yMyoaD0WARufU+zcG4P7j4rFlAO/CoezSd6l5HBUiXJNe7XniIi6KZjA1zkZc=
|
||||
on:
|
||||
tags: true
|
||||
repo: pushrocks/smartstring
|
70
README.md
70
README.md
@ -1,2 +1,70 @@
|
||||
# smartstring
|
||||
handle strings in smart ways.
|
||||
|
||||
handle strings in smart ways. TypeScript ready.
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/smartstring)
|
||||
[](https://GitLab.com/pushrocks/smartstring)
|
||||
[](https://github.com/pushrocks/smartstring)
|
||||
[](https://pushrocks.gitlab.io/smartstring/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/pushrocks/smartstring/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smartstring/commits/master)
|
||||
[](https://www.npmjs.com/package/smartstring)
|
||||
[](https://david-dm.org/pushrocks/smartstring)
|
||||
[](https://www.bithound.io/github/pushrocks/smartstring/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartstring)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```javascript
|
||||
import * as smartstring from 'smartstring';
|
||||
|
||||
// classes
|
||||
|
||||
// smartstring.Domain class
|
||||
let myDomain = new smartstring.Domain('https://sub.main.tld');
|
||||
myDomain.level1; // "tld"
|
||||
myDomain.level2; // "main"
|
||||
// level3 , level 4 and so on...
|
||||
myDomain.zoneName; // "main.tld"
|
||||
myDOmain.protocol; // "https"
|
||||
|
||||
// smartstring.GitRepo class
|
||||
let myGitRepo = new smartstring.GitRepo('git@github.com:someorg/somerepo.git'); // takes https and git and npm repo URL versions
|
||||
myGitRepo.host; // "github.com"
|
||||
myGitRepo.user; // "someorg"
|
||||
myGitRepo.repo; // "somerepo"
|
||||
myGitRepo.accessToken; // accessToken if specified with https
|
||||
myGitRepo.sshUrl; // "git@github.com:someorg/somerepo.git" (computed also from https)
|
||||
myGitRepo.httpsUrl; // "https://github.com/someorg/somerepo.git" (computed also from ssh)
|
||||
|
||||
//smartstring.Base64
|
||||
let myBase64 = new smartstring.Base64('somestring', 'string'); // first arg is the string, second is string type (can be string, base64, base64uri)
|
||||
myBase64.simpleString; // 'somestring'
|
||||
myBase64.base64String; // base64 representation of 'somestring'
|
||||
myBase64.base64UriString; // base64uri representation of 'sometring'
|
||||
|
||||
// methods
|
||||
smartstring.base64.encode('somestring'); // encodes 'somestring' to base64
|
||||
smartstring.base64.encodeUri('sometring'); // encodes 'somestring' to base64uri
|
||||
smartstring.base64.decode(); // decodes base64 and base64uri to simple string respresentation
|
||||
|
||||
smartstring.indent.indent('somestringanotherstring', 4); // indents a string by 4
|
||||
smartstring.indent.indent('somestringanotherstring', '>>>> '); // indents a string with a prefix
|
||||
smartstring.indent.normalize(' somestring anotherstring', '>>>> '); // looks for the least amount of indention and removes superflouous space
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
|
||||
[](https://push.rocks)
|
||||
|
13
dist/index.js
vendored
13
dist/index.js
vendored
@ -1,13 +0,0 @@
|
||||
"use strict";
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
var SmartstringGit = require("./smartstring.git");
|
||||
var SmartstringDocker = require("./smartstring.docker");
|
||||
var SmartstringTypescript = require("./smartstring.typescript");
|
||||
var smartstring = {
|
||||
git: SmartstringGit,
|
||||
docker: SmartstringDocker,
|
||||
typescript: SmartstringTypescript
|
||||
};
|
||||
module.exports = smartstring;
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDNUMsSUFBTyxjQUFjLFdBQVcsbUJBQW1CLENBQUMsQ0FBQztBQUNyRCxJQUFPLGlCQUFpQixXQUFXLHNCQUFzQixDQUFDLENBQUM7QUFDM0QsSUFBTyxxQkFBcUIsV0FBVywwQkFBMEIsQ0FBQyxDQUFDO0FBRW5FLElBQUksV0FBVyxHQUFHO0lBQ2QsR0FBRyxFQUFHLGNBQWM7SUFDcEIsTUFBTSxFQUFFLGlCQUFpQjtJQUN6QixVQUFVLEVBQUUscUJBQXFCO0NBQ3BDLENBQUM7QUFFRixpQkFBUyxXQUFXLENBQUMiLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzQ29udGVudCI6WyIvLy8gPHJlZmVyZW5jZSBwYXRoPVwiLi90eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgU21hcnRzdHJpbmdHaXQgPSByZXF1aXJlKFwiLi9zbWFydHN0cmluZy5naXRcIik7XG5pbXBvcnQgU21hcnRzdHJpbmdEb2NrZXIgPSByZXF1aXJlKFwiLi9zbWFydHN0cmluZy5kb2NrZXJcIik7XG5pbXBvcnQgU21hcnRzdHJpbmdUeXBlc2NyaXB0ID0gcmVxdWlyZShcIi4vc21hcnRzdHJpbmcudHlwZXNjcmlwdFwiKTtcblxubGV0IHNtYXJ0c3RyaW5nID0ge1xuICAgIGdpdCA6IFNtYXJ0c3RyaW5nR2l0LFxuICAgIGRvY2tlcjogU21hcnRzdHJpbmdEb2NrZXIsXG4gICAgdHlwZXNjcmlwdDogU21hcnRzdHJpbmdUeXBlc2NyaXB0XG59O1xuXG5leHBvcnQgPSBzbWFydHN0cmluZzsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
18
dist/smartstring.docker.js
vendored
18
dist/smartstring.docker.js
vendored
@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
/**
|
||||
* converts an erray of env strings from docker remote api to an usable object.
|
||||
* @param envArrayArg
|
||||
* @returns {}
|
||||
*/
|
||||
exports.makeEnvObject = function (envArrayArg) {
|
||||
var returnObject = {};
|
||||
var regexString = /(.*)=(.*)/;
|
||||
for (var envKey in envArrayArg) {
|
||||
var regexMatches = regexString.exec(envArrayArg[envKey]);
|
||||
returnObject[regexMatches[1]] = regexMatches[2];
|
||||
}
|
||||
;
|
||||
return returnObject;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBR0E7Ozs7R0FJRztBQUNRLHFCQUFhLEdBQUcsVUFBUyxXQUFvQjtJQUNwRCxJQUFJLFlBQVksR0FBRyxFQUFFLENBQUM7SUFDdEIsSUFBSSxXQUFXLEdBQUcsV0FBVyxDQUFDO0lBQzlCLEdBQUcsQ0FBQSxDQUFDLElBQUksTUFBTSxJQUFJLFdBQVcsQ0FBQyxDQUFBLENBQUM7UUFDM0IsSUFBSSxZQUFZLEdBQUcsV0FBVyxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztRQUN6RCxZQUFZLENBQUMsWUFBWSxDQUFDLENBQUMsQ0FBQyxDQUFDLEdBQUcsWUFBWSxDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQ3BELENBQUM7SUFBQSxDQUFDO0lBQ0YsTUFBTSxDQUFDLFlBQVksQ0FBQztBQUN4QixDQUFDLENBQUMiLCJmaWxlIjoic21hcnRzdHJpbmcuZG9ja2VyLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxuaW1wb3J0IHBsdWdpbnMgPSByZXF1aXJlKFwiLi9zbWFydHN0cmluZy5wbHVnaW5zXCIpO1xuXG4vKipcbiAqIGNvbnZlcnRzIGFuIGVycmF5IG9mIGVudiBzdHJpbmdzIGZyb20gZG9ja2VyIHJlbW90ZSBhcGkgdG8gYW4gdXNhYmxlIG9iamVjdC5cbiAqIEBwYXJhbSBlbnZBcnJheUFyZ1xuICogQHJldHVybnMge31cbiAqL1xuZXhwb3J0IGxldCBtYWtlRW52T2JqZWN0ID0gZnVuY3Rpb24oZW52QXJyYXlBcmc6c3RyaW5nW10pe1xuICAgIGxldCByZXR1cm5PYmplY3QgPSB7fTtcbiAgICBsZXQgcmVnZXhTdHJpbmcgPSAvKC4qKT0oLiopLztcbiAgICBmb3IobGV0IGVudktleSBpbiBlbnZBcnJheUFyZyl7XG4gICAgICAgIGxldCByZWdleE1hdGNoZXMgPSByZWdleFN0cmluZy5leGVjKGVudkFycmF5QXJnW2VudktleV0pO1xuICAgICAgICByZXR1cm5PYmplY3RbcmVnZXhNYXRjaGVzWzFdXSA9IHJlZ2V4TWF0Y2hlc1syXTtcbiAgICB9O1xuICAgIHJldHVybiByZXR1cm5PYmplY3Q7XG59OyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
58
dist/smartstring.git.js
vendored
58
dist/smartstring.git.js
vendored
File diff suppressed because one or more lines are too long
8
dist/smartstring.plugins.js
vendored
8
dist/smartstring.plugins.js
vendored
@ -1,8 +0,0 @@
|
||||
"use strict";
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
var plugins = {
|
||||
beautylog: require("beautylog")
|
||||
};
|
||||
module.exports = plugins;
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFJLE9BQU8sR0FBRztJQUNWLFNBQVMsRUFBRSxPQUFPLENBQUMsV0FBVyxDQUFDO0NBQ2xDLENBQUM7QUFFRixpQkFBUyxPQUFPLENBQUMiLCJmaWxlIjoic21hcnRzdHJpbmcucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmxldCBwbHVnaW5zID0ge1xuICAgIGJlYXV0eWxvZzogcmVxdWlyZShcImJlYXV0eWxvZ1wiKVxufTtcblxuZXhwb3J0ID0gcGx1Z2luczsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
4
dist/smartstring.typescript.js
vendored
4
dist/smartstring.typescript.js
vendored
@ -1,4 +0,0 @@
|
||||
"use strict";
|
||||
exports.regexReferencePath = /\/\/\/\s*<reference\s+path\s*=\s*["|'].*["|']\s*\/>\s*[\\n]?/;
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLnR5cGVzY3JpcHQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUVXLDBCQUFrQixHQUFHLDhEQUE4RCxDQUFBIiwiZmlsZSI6InNtYXJ0c3RyaW5nLnR5cGVzY3JpcHQuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3NtYXJ0c3RyaW5nLnBsdWdpbnNcIik7XG5cbmV4cG9ydCBsZXQgcmVnZXhSZWZlcmVuY2VQYXRoID0gL1xcL1xcL1xcL1xccyo8cmVmZXJlbmNlXFxzK3BhdGhcXHMqPVxccypbXCJ8J10uKltcInwnXVxccypcXC8+XFxzKltcXFxcbl0/LyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
11
npmextra.json
Normal file
11
npmextra.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"npmdocker": {
|
||||
"baseImage": "hosttoday/ht-docker-node:npmci",
|
||||
"command": "npmci node install stable && npmci npm install && npmci npm test",
|
||||
"dockerSock": false
|
||||
}
|
||||
}
|
1440
package-lock.json
generated
Normal file
1440
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@ -1,14 +1,17 @@
|
||||
{
|
||||
"name": "smartstring",
|
||||
"version": "1.0.1",
|
||||
"description": "bundles a bunch of (regex) matching and altering methods.",
|
||||
"name": "@pushrocks/smartstring",
|
||||
"version": "3.0.7",
|
||||
"private": false,
|
||||
"description": "handle strings in smart ways. TypeScript ready.",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pushrocks/smartstring.git"
|
||||
"url": "git+https://gitlab.com/pushrocks/smartstring.git"
|
||||
},
|
||||
"keywords": [
|
||||
"regex",
|
||||
@ -17,14 +20,21 @@
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pushrocks/smartstring/issues"
|
||||
"url": "https://gitlab.com/pushrocks/smartstring/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/smartstring#readme",
|
||||
"homepage": "https://gitlab.com/pushrocks/smartstring#readme",
|
||||
"devDependencies": {
|
||||
"npmts": "^5.0.4",
|
||||
"should": "^8.3.1"
|
||||
"@gitzone/tsbuild": "^2.1.4",
|
||||
"@gitzone/tsrun": "^1.1.17",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.12.18"
|
||||
},
|
||||
"dependencies": {
|
||||
"beautylog": "^4.1.2"
|
||||
"crypto-random-string": "^1.0.0",
|
||||
"js-base64": "^2.5.0",
|
||||
"normalize-newline": "^3.0.0",
|
||||
"randomatic": "^3.1.1",
|
||||
"strip-indent": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
16
test/test.base64.ts
Normal file
16
test/test.base64.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import * as smartstring from '../ts/index';
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
// Base64
|
||||
let testBase64: smartstring.Base64;
|
||||
tap.test('expect create a valid instance of Base64', async () => {
|
||||
testBase64 = new smartstring.Base64('somestring', 'string');
|
||||
expect(testBase64).be.instanceOf(smartstring.Base64);
|
||||
});
|
||||
tap.test('expect read output a file as base64 and base64uri', async () => {
|
||||
expect(testBase64.base64String).not.equal(testBase64.base64UriString);
|
||||
let testBase64_2 = new smartstring.Base64(testBase64.base64UriString, 'base64uri');
|
||||
expect(testBase64_2.simpleString).equal(testBase64.simpleString);
|
||||
});
|
||||
|
||||
tap.start();
|
12
test/test.docker.ts
Normal file
12
test/test.docker.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import * as smartstring from '../ts/index';
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
// Docker
|
||||
tap.test('expect create a Env Object', async () => {
|
||||
let envStringArray = ['VIRTUAL_HOST=sub.domain.tld', 'DEFAULT_HOST=some.domain.com'];
|
||||
let envObject: any = smartstring.docker.makeEnvObject(envStringArray);
|
||||
expect(envObject.VIRTUAL_HOST).to.equal('sub.domain.tld');
|
||||
expect(envObject.DEFAULT_HOST).to.equal('some.domain.com');
|
||||
});
|
||||
|
||||
tap.start();
|
32
test/test.domain.ts
Normal file
32
test/test.domain.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import * as smartstring from '../ts/index';
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
// Domain
|
||||
let testDomain: smartstring.Domain;
|
||||
let testDomain2: smartstring.Domain;
|
||||
tap.test('expect create a new Domain object', async () => {
|
||||
testDomain = new smartstring.Domain('https://level3D.level2D.level1D');
|
||||
expect(testDomain).be.instanceof(smartstring.Domain);
|
||||
console.log(testDomain);
|
||||
});
|
||||
tap.test('expect have a .topLevel', async () => {
|
||||
expect(testDomain.topLevel).equal('level1D');
|
||||
});
|
||||
tap.test('expect have a .level2', async () => {
|
||||
expect(testDomain.level2).equal('level2D');
|
||||
});
|
||||
tap.test('expect have a .level3', async () => {
|
||||
expect(testDomain.level3).equal('level3D');
|
||||
});
|
||||
tap.test('expect have the correct dns zone name', async () => {
|
||||
expect(testDomain.zoneName).equal('level2D.level1D');
|
||||
});
|
||||
tap.test('expect have the correct protocol', async () => {
|
||||
expect(testDomain.protocol).equal('https');
|
||||
});
|
||||
tap.test('testDomain2 expect be a basic domain', async () => {
|
||||
testDomain2 = new smartstring.Domain('bleu.de');
|
||||
console.log(testDomain2);
|
||||
});
|
||||
|
||||
tap.start();
|
26
test/test.git.ts
Normal file
26
test/test.git.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import * as smartstring from '../ts/index';
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
// git
|
||||
let testGit: smartstring.GitRepo;
|
||||
tap.test('expect create a new Git class GitRepo', async () => {
|
||||
testGit = new smartstring.GitRepo('git+https://github.com/pushrocks/smartstring.git');
|
||||
expect(testGit).be.instanceof(smartstring.GitRepo);
|
||||
});
|
||||
tap.test('expect return a .host', async () => {
|
||||
expect(testGit.host).equal('github.com');
|
||||
});
|
||||
tap.test('expect return a .user', async () => {
|
||||
expect(testGit.user).equal('pushrocks');
|
||||
});
|
||||
tap.test('expect return a .repo', async () => {
|
||||
expect(testGit.repo).equal('smartstring');
|
||||
});
|
||||
tap.test('expect return a .httpsUrl', async () => {
|
||||
expect(testGit.httpsUrl).equal('https://github.com/pushrocks/smartstring.git');
|
||||
});
|
||||
tap.test('expect return a .sshUrl', async () => {
|
||||
expect(testGit.sshUrl).equal('git@github.com:pushrocks/smartstring.git');
|
||||
});
|
||||
|
||||
tap.start();
|
28
test/test.indent.ts
Normal file
28
test/test.indent.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import * as smartstring from '../ts/index';
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
// indent
|
||||
let testString = `
|
||||
base
|
||||
expect be indented
|
||||
some more
|
||||
|
||||
base
|
||||
indented
|
||||
`;
|
||||
|
||||
// normalize
|
||||
tap.test('expect normalize a string', async () => {
|
||||
testString = smartstring.indent.normalize(testString);
|
||||
console.log(testString);
|
||||
let zoneNameArg = 'test1';
|
||||
let destinationIpArg = '111';
|
||||
});
|
||||
|
||||
// indent with prefix
|
||||
tap.test('expect indent', async () => {
|
||||
testString = smartstring.indent.indentWithPrefix(testString, '>> ');
|
||||
console.log(testString);
|
||||
});
|
||||
|
||||
tap.start();
|
52
test/test.js
52
test/test.js
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,IAAI,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC9C,IAAI,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE/B,QAAQ,CAAC,aAAa,EAAC;IACnB,QAAQ,CAAC,QAAQ,EAAC;QACd,IAAI,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;QAClF,EAAE,CAAC,uBAAuB,EAAC;YACvB,OAAO,CAAC,IAAI;iBACP,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,uBAAuB,EAAC;YACvB,OAAO,CAAC,IAAI;iBACP,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,uBAAuB,EAAC;YACvB,OAAO,CAAC,IAAI;iBACP,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,2BAA2B,EAAC;YAC3B,OAAO,CAAC,QAAQ;iBACX,MAAM,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,yBAAyB,EAAC;YACzB,OAAO,CAAC,MAAM;iBACT,MAAM,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAA;IACF,QAAQ,CAAC,SAAS,EAAC;QACf,QAAQ,CAAC,gBAAgB,EAAC;YACtB,EAAE,CAAC,4BAA4B,EAAC;gBAC5B,IAAI,cAAc,GAAG,CAAC,6BAA6B,EAAC,8BAA8B,CAAC,CAAC;gBACpF,IAAI,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;gBACjE,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;gBACtD,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;YAC3D,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAC"}
|
19
test/test.normalize.ts
Normal file
19
test/test.normalize.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartstring from '../ts/index';
|
||||
|
||||
tap.test('should normalize a string', async () => {
|
||||
const testString = `
|
||||
myawesome string;
|
||||
is indented with two spaces
|
||||
`
|
||||
const normalizedString = smartstring.normalize.standard(testString);
|
||||
expect(normalizedString).to.equal(
|
||||
`
|
||||
myawesome string;
|
||||
is indented with two spaces
|
||||
`
|
||||
)
|
||||
})
|
||||
|
||||
tap.start()
|
51
test/test.ts
51
test/test.ts
@ -1,51 +0,0 @@
|
||||
/// <reference path="../ts/typings/main.d.ts" />
|
||||
let smartstring = require("../dist/index.js");
|
||||
let should = require("should");
|
||||
|
||||
describe("smartstring",function(){
|
||||
describe(".git()",function(){
|
||||
let testGit = smartstring.git("git+https://github.com/pushrocks/smartstring.git");
|
||||
it("should return a .host",function(){
|
||||
testGit.host
|
||||
.should.equal("github.com");
|
||||
});
|
||||
it("should return a .user",function(){
|
||||
testGit.user
|
||||
.should.equal("pushrocks");
|
||||
});
|
||||
it("should return a .repo",function(){
|
||||
testGit.repo
|
||||
.should.equal("smartstring");
|
||||
});
|
||||
it("should return a .httpsUrl",function(){
|
||||
testGit.httpsUrl
|
||||
.should.equal("https://github.com/pushrocks/smartstring.git");
|
||||
});
|
||||
it("should return a .sshUrl",function(){
|
||||
testGit.sshUrl
|
||||
.should.equal("git@github.com:pushrocks/smartstring.git");
|
||||
});
|
||||
})
|
||||
describe(".docker",function(){
|
||||
describe(".makeEnvObject",function(){
|
||||
it("should create a Env Object",function(){
|
||||
let envStringArray = ["VIRTUAL_HOST=sub.domain.tld","DEFAULT_HOST=some.domain.com"];
|
||||
let envObject = smartstring.docker.makeEnvObject(envStringArray);
|
||||
envObject.VIRTUAL_HOST.should.equal("sub.domain.tld");
|
||||
envObject.DEFAULT_HOST.should.equal("some.domain.com");
|
||||
})
|
||||
})
|
||||
})
|
||||
describe(".typescript",function(){
|
||||
describe(".referenceRegex",function(){
|
||||
it("should match reference paths",function(){
|
||||
smartstring.typescript.regexReferencePath.test("/// <reference path=\"\" />")
|
||||
.should.be.true();
|
||||
smartstring.typescript.regexReferencePath.test("/// <reference path='' />")
|
||||
.should.be.true();
|
||||
smartstring.typescript.regexReferencePath.test("/// <referencepath=\"\" />")
|
||||
.should.be.false();
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
18
ts/index.ts
18
ts/index.ts
@ -1,12 +1,10 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import SmartstringGit = require("./smartstring.git");
|
||||
import SmartstringDocker = require("./smartstring.docker");
|
||||
import SmartstringTypescript = require("./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';
|
||||
|
||||
let smartstring = {
|
||||
git : SmartstringGit,
|
||||
docker: SmartstringDocker,
|
||||
typescript: SmartstringTypescript
|
||||
};
|
||||
export { create, docker, normalize, indent };
|
||||
|
||||
export = smartstring;
|
||||
export { Base64, base64 } from './smartstring.base64';
|
||||
export { Domain } from './smartstring.domain';
|
||||
export { GitRepo } from './smartstring.git';
|
||||
|
69
ts/smartstring.base64.ts
Normal file
69
ts/smartstring.base64.ts
Normal file
@ -0,0 +1,69 @@
|
||||
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 = base64.decode(inputStringArg);
|
||||
break;
|
||||
case 'base64uri':
|
||||
this.refString = base64.decode(inputStringArg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the simple string (unencoded)
|
||||
*/
|
||||
get simpleString() {
|
||||
return this.refString;
|
||||
}
|
||||
|
||||
/**
|
||||
* the base64 encoded version of the original string
|
||||
*/
|
||||
get base64String() {
|
||||
return base64.encode(this.refString);
|
||||
}
|
||||
|
||||
/**
|
||||
* the base64uri encoded version of the original string
|
||||
*/
|
||||
get base64UriString() {
|
||||
return base64.encodeUri(this.refString);
|
||||
}
|
||||
}
|
||||
|
||||
export let base64 = {
|
||||
/**
|
||||
* encodes the string
|
||||
*/
|
||||
encode: (stringArg: string) => {
|
||||
return plugins.jsBase64.encode(stringArg);
|
||||
},
|
||||
|
||||
/**
|
||||
* encodes a stringArg to base64 uri style
|
||||
*/
|
||||
encodeUri: (stringArg: string) => {
|
||||
return plugins.jsBase64.encodeURI(stringArg);
|
||||
},
|
||||
|
||||
/**
|
||||
* decodes a base64 encoded string
|
||||
*/
|
||||
decode: (stringArg: string) => {
|
||||
return plugins.jsBase64.decode(stringArg);
|
||||
}
|
||||
};
|
29
ts/smartstring.create.ts
Normal file
29
ts/smartstring.create.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import * as plugins from './smartstring.plugins';
|
||||
|
||||
/**
|
||||
* creates a random string
|
||||
*
|
||||
* ```ts
|
||||
* createRandomString('AAAA')
|
||||
* //=> 'AGHR'
|
||||
* ```
|
||||
*
|
||||
* @param patternArg the pattern argument to use, Aa0!* are viable pattern descritors
|
||||
* @param lengthArg the length of the random string
|
||||
* @param optionsArg options
|
||||
*/
|
||||
export const createRandomString = (
|
||||
patternArg: string,
|
||||
lengthArg?: number,
|
||||
optionsArg?: any
|
||||
): string => {
|
||||
return plugins.randomatic(patternArg, lengthArg, optionsArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* creates a crytic string in the speicifed length
|
||||
* @param lengthArg the length of the crypto string
|
||||
*/
|
||||
export const createCryptoRandomString = (lengthArg: number): string => {
|
||||
return plugins.cryptoRandomString(lengthArg);
|
||||
};
|
@ -1,17 +1,18 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./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 let makeEnvObject = function(envArrayArg:string[]){
|
||||
let returnObject = {};
|
||||
let regexString = /(.*)=(.*)/;
|
||||
for(let envKey in envArrayArg){
|
||||
let regexMatches = regexString.exec(envArrayArg[envKey]);
|
||||
returnObject[regexMatches[1]] = regexMatches[2];
|
||||
};
|
||||
return returnObject;
|
||||
};
|
||||
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];
|
||||
}
|
||||
}
|
||||
return returnObject;
|
||||
};
|
||||
|
61
ts/smartstring.domain.ts
Normal file
61
ts/smartstring.domain.ts
Normal file
@ -0,0 +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;
|
||||
// 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]) {
|
||||
let localMatch = regexMatches[i - 1];
|
||||
this['level' + i.toString()] = localMatch;
|
||||
if (this.fullName === '') {
|
||||
this.fullName = localMatch;
|
||||
} else {
|
||||
this.fullName = localMatch + '.' + this.fullName;
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
let protocolRegex = function(stringArg: string) {
|
||||
let regexString = /^([a-zA-Z0-9]*):\/\//;
|
||||
let regexMatches = regexString.exec(stringArg);
|
||||
if (regexMatches) {
|
||||
return regexMatches[1];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
@ -1,63 +1,56 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./smartstring.plugins");
|
||||
import * as plugins from './smartstring.plugins';
|
||||
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ classes ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
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");
|
||||
};
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ helpers ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
let gitRegex = function(stringArg:string){
|
||||
let regexString = /(?:git\+|git\@|https\:\/\/|)(?:https\:\/\/|)([^\/|\:]*)(?:\/|:)([^\/]+)*(?:\/|:)([^\.]+)/;
|
||||
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;
|
||||
};
|
||||
|
||||
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;
|
||||
default:
|
||||
plugins.beautylog.error("Link Type " + linkTypeArg + " not known");
|
||||
break;
|
||||
}
|
||||
return returnString;
|
||||
const 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;
|
||||
default:
|
||||
console.error('Link Type ' + linkTypeArg + ' not known');
|
||||
break;
|
||||
}
|
||||
return returnString;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ exports ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
let git = function(stringArg:string,tokenArg?:string){
|
||||
let localGitRepo = new gitRepo(stringArg,tokenArg);
|
||||
return localGitRepo;
|
||||
};
|
||||
|
||||
export = git;
|
92
ts/smartstring.indent.ts
Normal file
92
ts/smartstring.indent.ts
Normal file
@ -0,0 +1,92 @@
|
||||
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);
|
||||
};
|
||||
|
||||
/**
|
||||
* joins a string together again
|
||||
* @param stringArrayArg
|
||||
*/
|
||||
const joinStringWithLineBreaks = (stringArrayArg: string[]): string => {
|
||||
let resultString: string = '';
|
||||
for (let line of stringArrayArg) {
|
||||
resultString = resultString + line + '\n'; // add new line at end
|
||||
}
|
||||
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();
|
||||
}
|
||||
if (testRegex.test(stringArrayArg[stringArrayArg.length - 1])) {
|
||||
stringArrayArg.pop();
|
||||
}
|
||||
return stringArrayArg;
|
||||
};
|
||||
|
||||
/**
|
||||
* indent an array
|
||||
* @param stringArg
|
||||
* @param spaceAmount
|
||||
*/
|
||||
export const indent = (stringArg: string, spaceAmount: number): string => {
|
||||
let localStringArray = splitStringAtLineBreak(stringArg);
|
||||
for (let stringArg of localStringArray) {
|
||||
stringArg = ' '.repeat(spaceAmount) + stringArg;
|
||||
}
|
||||
let resultString = joinStringWithLineBreaks(localStringArray);
|
||||
return resultString;
|
||||
};
|
||||
|
||||
/**
|
||||
* indents a string with prefix
|
||||
* @param stringArg
|
||||
* @param prefixArg
|
||||
*/
|
||||
export const indentWithPrefix = (stringArg: string, prefixArg: string): string => {
|
||||
let resultString: string;
|
||||
let stringArray = splitStringAtLineBreak(stringArg);
|
||||
let resultArray: string[] = [];
|
||||
for (let stringItem of stringArray) {
|
||||
resultArray.push(prefixArg + stringItem);
|
||||
}
|
||||
resultString = joinStringWithLineBreaks(resultArray);
|
||||
return resultString;
|
||||
};
|
||||
|
||||
export const normalize = (stringArg: string): string => {
|
||||
let resultString: string;
|
||||
let splitStringArray: string[] = splitStringAtLineBreak(stringArg);
|
||||
let minCommonLeftOffset: number;
|
||||
|
||||
const deIndentRegex = /^(\s*)/;
|
||||
const emptyLineRegex = /^(\s*)$/;
|
||||
|
||||
for (let stringItem of splitStringArray) {
|
||||
let offsetString = deIndentRegex.exec(stringItem)[1];
|
||||
if (
|
||||
(typeof minCommonLeftOffset === 'undefined' || offsetString.length < minCommonLeftOffset) &&
|
||||
!emptyLineRegex.test(stringItem)
|
||||
) {
|
||||
minCommonLeftOffset = offsetString.length;
|
||||
}
|
||||
}
|
||||
let resultSplitStringArray = [];
|
||||
for (let stringItem of splitStringArray) {
|
||||
resultSplitStringArray.push(stringItem.substr(minCommonLeftOffset));
|
||||
}
|
||||
resultString = joinStringWithLineBreaks(resultSplitStringArray);
|
||||
return resultString;
|
||||
};
|
22
ts/smartstring.normalize.ts
Normal file
22
ts/smartstring.normalize.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import * as plugins from './smartstring.plugins';
|
||||
|
||||
/**
|
||||
* replaces all occurences of something in a string
|
||||
* @param stringArg
|
||||
* @param searchPattern
|
||||
* @param replacementString
|
||||
*/
|
||||
export const replaceAll = (stringArg: string, searchPattern: string, replacementString: string) => {
|
||||
return stringArg.replace(new RegExp(searchPattern, '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;
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
let plugins = {
|
||||
beautylog: require("beautylog")
|
||||
};
|
||||
export let jsBase64 = require('js-base64').Base64;
|
||||
|
||||
export = plugins;
|
||||
export let stripIndent = require('strip-indent');
|
||||
export let normalizeNewline = require('normalize-newline');
|
||||
export let randomatic = require('randomatic');
|
||||
export let cryptoRandomString = require('crypto-random-string');
|
||||
|
@ -1,3 +0,0 @@
|
||||
import plugins = require("./smartstring.plugins");
|
||||
|
||||
export let regexReferencePath = /\/\/\/\s*<reference\s+path\s*=\s*["|'].*["|']\s*\/>\s*[\\n]?/
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"ambientDependencies": {
|
||||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts",
|
||||
"mocha": "github:Bartvds/tsd-deftools/typings/DefinitelyTyped/mocha/mocha.d.ts",
|
||||
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts"
|
||||
}
|
||||
}
|
17
tslint.json
Normal file
17
tslint.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user