Compare commits
137 Commits
Author | SHA1 | Date | |
---|---|---|---|
5825a602ed | |||
5e961f7a5b | |||
36bcb9265a | |||
53bf2f3569 | |||
523ab7ee77 | |||
d60cc5430f | |||
c0035bb4f3 | |||
976f81420f | |||
1be144d099 | |||
9d4b7a5292 | |||
563d6f0ac3 | |||
4da0aeb871 | |||
931defe98a | |||
1e6077ce34 | |||
8b1769d65e | |||
48878c0b38 | |||
76cfc8bec0 | |||
7f3118c525 | |||
9d189d1b59 | |||
0266afca8e | |||
bef836fc83 | |||
2bd1741893 | |||
bd20512b10 | |||
25d0ba8036 | |||
c517652122 | |||
bf3e640307 | |||
08cb2392fa | |||
4e1fa4efab | |||
26d00bb9d3 | |||
fd27ed1a56 | |||
1f31fe9dc5 | |||
bd7888f7ce | |||
201812e182 | |||
8dfa3f8965 | |||
43d50b746b | |||
a1ee8f37d6 | |||
8d9c75e113 | |||
8ff2a9d64a | |||
8665464416 | |||
e773644256 | |||
71fd0e614c | |||
55a5948a51 | |||
979375f08d | |||
95d5c6ceee | |||
c92ece79ff | |||
7c625c4390 | |||
65fc64f6aa | |||
8cda8c55c0 | |||
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 | |||
203a31addd | |||
2db9ba50d2 |
25
.gitignore
vendored
25
.gitignore
vendored
@ -1,7 +1,20 @@
|
||||
.idea/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
docs/
|
||||
node_modules
|
||||
ts/**/*.js
|
||||
ts/**/*.js.map
|
||||
ts/typings/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
128
.gitlab-ci.yml
Normal file
128
.gitlab-ci.yml
Normal file
@ -0,0 +1,128 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- 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
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
11
dist/index.js
vendored
11
dist/index.js
vendored
@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
var SmartstringGit = require("./smartstring.git");
|
||||
var SmartstringDocker = require("./smartstring.docker");
|
||||
var smartstring = {
|
||||
git: SmartstringGit,
|
||||
docker: SmartstringDocker
|
||||
};
|
||||
module.exports = smartstring;
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDNUMsSUFBTyxjQUFjLFdBQVcsbUJBQW1CLENBQUMsQ0FBQztBQUNyRCxJQUFPLGlCQUFpQixXQUFXLHNCQUFzQixDQUFDLENBQUM7QUFFM0QsSUFBSSxXQUFXLEdBQUc7SUFDZCxHQUFHLEVBQUcsY0FBYztJQUNwQixNQUFNLEVBQUUsaUJBQWlCO0NBQzVCLENBQUM7QUFFRixpQkFBUyxXQUFXLENBQUMiLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzQ29udGVudCI6WyIvLy8gPHJlZmVyZW5jZSBwYXRoPVwiLi90eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgU21hcnRzdHJpbmdHaXQgPSByZXF1aXJlKFwiLi9zbWFydHN0cmluZy5naXRcIik7XG5pbXBvcnQgU21hcnRzdHJpbmdEb2NrZXIgPSByZXF1aXJlKFwiLi9zbWFydHN0cmluZy5kb2NrZXJcIik7XG5cbmxldCBzbWFydHN0cmluZyA9IHtcbiAgICBnaXQgOiBTbWFydHN0cmluZ0dpdCxcbiAgICBkb2NrZXI6IFNtYXJ0c3RyaW5nRG9ja2VyXG59O1xuXG5leHBvcnQgPSBzbWFydHN0cmluZzsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
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,eyJ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PSB7fTtcbiAgICBsZXQgcmVnZXhTdHJpbmcgPSAvKC4qKT0oLiopLztcbiAgICBmb3IobGV0IGVudktleSBpbiBlbnZBcnJheUFyZyl7XG4gICAgICAgIGxldCByZWdleE1hdGNoZXMgPSByZWdleFN0cmluZy5leGVjKGVudkFycmF5QXJnW2VudktleV0pO1xuICAgICAgICByZXR1cm5PYmplY3RbcmVnZXhNYXRjaGVzWzFdXSA9IHJlZ2V4TWF0Y2hlc1syXTtcbiAgICB9O1xuICAgIHJldHVybiByZXR1cm5PYmplY3Q7XG59OyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
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=
|
@ -1,6 +1,7 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Push.Rocks
|
||||
Copyright (c) 2014 Maurice Butler
|
||||
Copyright (c) 2016 Lossless GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
22
npmextra.json
Normal file
22
npmextra.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"npmdocker": {
|
||||
"baseImage": "hosttoday/ht-docker-node:npmci",
|
||||
"command": "npmci node install stable && npmci npm install && npmci npm test",
|
||||
"dockerSock": false
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartstring",
|
||||
"description": "handle strings in smart ways. TypeScript ready.",
|
||||
"npmPackagename": "@pushrocks/smartstring",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
13336
package-lock.json
generated
Normal file
13336
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
58
package.json
58
package.json
@ -1,14 +1,19 @@
|
||||
{
|
||||
"name": "smartstring",
|
||||
"version": "1.0.0",
|
||||
"description": "bundles a bunch of (regex) matching and altering methods.",
|
||||
"main": "dist/index.js",
|
||||
"name": "@pushrocks/smartstring",
|
||||
"version": "4.0.5",
|
||||
"private": false,
|
||||
"description": "handle strings in smart ways. TypeScript ready.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pushrocks/smartstring.git"
|
||||
"url": "git+https://gitlab.com/pushrocks/smartstring.git"
|
||||
},
|
||||
"keywords": [
|
||||
"regex",
|
||||
@ -17,14 +22,43 @@
|
||||
"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.65",
|
||||
"@gitzone/tsrun": "^1.2.37",
|
||||
"@gitzone/tstest": "^1.0.73",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.7.17",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"beautylog": "^4.1.2"
|
||||
}
|
||||
"@pushrocks/isounique": "^1.0.5",
|
||||
"@pushrocks/smartenv": "^5.0.3",
|
||||
"@types/randomatic": "^3.1.3",
|
||||
"buffer": "^6.0.3",
|
||||
"crypto-random-string": "^4.0.0",
|
||||
"js-base64": "^3.7.2",
|
||||
"normalize-newline": "^4.1.0",
|
||||
"randomatic": "^3.1.1",
|
||||
"strip-indent": "^4.0.0",
|
||||
"url": "^0.11.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
77
readme.md
Normal file
77
readme.md
Normal file
@ -0,0 +1,77 @@
|
||||
# @pushrocks/smartstring
|
||||
handle strings in smart ways. TypeScript ready.
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartstring)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartstring)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartstring)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartstring/)
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## 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
|
||||
```
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
23
test/test.base64.both.ts
Normal file
23
test/test.base64.both.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import * as smartstring from '../ts/index.js';
|
||||
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).toBeInstanceOf(smartstring.Base64);
|
||||
});
|
||||
|
||||
tap.test('expect read output a file as base64 and base64uri', async () => {
|
||||
expect(testBase64.base64String).not.toEqual(testBase64.base64UriString);
|
||||
let testBase64_2 = new smartstring.Base64(testBase64.base64UriString, 'base64uri');
|
||||
expect(testBase64_2.simpleString).toEqual(testBase64.simpleString);
|
||||
});
|
||||
|
||||
tap.test('should test for a valid base64 token', async () => {
|
||||
const result = smartstring.base64.isBase64('dGVzdA==');
|
||||
expect(result).toBeTrue();
|
||||
});
|
||||
|
||||
tap.start();
|
12
test/test.docker.both.ts
Normal file
12
test/test.docker.both.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import * as smartstring from '../ts/index.js';
|
||||
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).toEqual('sub.domain.tld');
|
||||
expect(envObject.DEFAULT_HOST).toEqual('some.domain.com');
|
||||
});
|
||||
|
||||
tap.start();
|
37
test/test.domain.both.ts
Normal file
37
test/test.domain.both.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import * as smartstring from '../ts/index.js';
|
||||
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).toBeInstanceOf(smartstring.Domain);
|
||||
console.log(testDomain);
|
||||
});
|
||||
tap.test('expect have a .topLevel', async () => {
|
||||
expect(testDomain.topLevel).toEqual('level1D');
|
||||
});
|
||||
tap.test('expect have a .level2', async () => {
|
||||
expect(testDomain.level2).toEqual('level2D');
|
||||
});
|
||||
tap.test('expect have a .level3', async () => {
|
||||
expect(testDomain.level3).toEqual('level3D');
|
||||
});
|
||||
tap.test('expect have the correct dns zone name', async () => {
|
||||
expect(testDomain.zoneName).toEqual('level2D.level1D');
|
||||
});
|
||||
tap.test('expect have the correct protocol', async () => {
|
||||
expect(testDomain.protocol).toEqual('https');
|
||||
});
|
||||
tap.test('testDomain2 expect be a basic domain', async () => {
|
||||
testDomain2 = new smartstring.Domain('testing.bleu.de');
|
||||
console.log(testDomain2);
|
||||
});
|
||||
|
||||
tap.test('should parse complex domains', async () => {
|
||||
testDomain2 = new smartstring.Domain('https://sub1.sub2.lossless.com/some/path:5431');
|
||||
console.log(testDomain2);
|
||||
});
|
||||
|
||||
tap.start();
|
26
test/test.git.both.ts
Normal file
26
test/test.git.both.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import * as smartstring from '../ts/index.js';
|
||||
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).toBeInstanceOf(smartstring.GitRepo);
|
||||
});
|
||||
tap.test('expect return a .host', async () => {
|
||||
expect(testGit.host).toEqual('github.com');
|
||||
});
|
||||
tap.test('expect return a .user', async () => {
|
||||
expect(testGit.user).toEqual('pushrocks');
|
||||
});
|
||||
tap.test('expect return a .repo', async () => {
|
||||
expect(testGit.repo).toEqual('smartstring');
|
||||
});
|
||||
tap.test('expect return a .httpsUrl', async () => {
|
||||
expect(testGit.httpsUrl).toEqual('https://github.com/pushrocks/smartstring.git');
|
||||
});
|
||||
tap.test('expect return a .sshUrl', async () => {
|
||||
expect(testGit.sshUrl).toEqual('git@github.com:pushrocks/smartstring.git');
|
||||
});
|
||||
|
||||
tap.start();
|
28
test/test.indent.both.ts
Normal file
28
test/test.indent.both.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import * as smartstring from '../ts/index.js';
|
||||
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();
|
40
test/test.js
40
test/test.js
@ -1,40 +0,0 @@
|
||||
/// <reference path="../ts/typings/main.d.ts" />
|
||||
var smartstring = require("../dist/index.js");
|
||||
var should = require("should");
|
||||
describe("smartstring", function () {
|
||||
describe(".git()", function () {
|
||||
var 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 () {
|
||||
var envStringArray = ["VIRTUAL_HOST=sub.domain.tld", "DEFAULT_HOST=some.domain.com"];
|
||||
var envObject = smartstring.docker.makeEnvObject(envStringArray);
|
||||
envObject.VIRTUAL_HOST.should.equal("sub.domain.tld");
|
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FwiKTtcbiAgICAgICAgfSk7XG4gICAgfSlcbiAgICBkZXNjcmliZShcIi5kb2NrZXJcIixmdW5jdGlvbigpe1xuICAgICAgICBkZXNjcmliZShcIi5tYWtlRW52T2JqZWN0XCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgIGl0KFwic2hvdWxkIGNyZWF0ZSBhIEVudiBPYmplY3RcIixmdW5jdGlvbigpe1xuICAgICAgICAgICAgICAgIGxldCBlbnZTdHJpbmdBcnJheSA9IFtcIlZJUlRVQUxfSE9TVD1zdWIuZG9tYWluLnRsZFwiLFwiREVGQVVMVF9IT1NUPXNvbWUuZG9tYWluLmNvbVwiXTtcbiAgICAgICAgICAgICAgICBsZXQgZW52T2JqZWN0ID0gc21hcnRzdHJpbmcuZG9ja2VyLm1ha2VFbnZPYmplY3QoZW52U3RyaW5nQXJyYXkpO1xuICAgICAgICAgICAgICAgIGVudk9iamVjdC5WSVJUVUFMX0hPU1Quc2hvdWxkLmVxdWFsKFwic3ViLmRvbWFpbi50bGRcIik7XG4gICAgICAgICAgICAgICAgZW52T2JqZWN0LkRFRkFVTFRfSE9TVC5zaG91bGQuZXF1YWwoXCJzb21lLmRvbWFpbi5jb21cIik7XG4gICAgICAgICAgICB9KVxuICAgICAgICB9KVxuICAgIH0pXG59KTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
@ -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.both.ts
Normal file
19
test/test.normalize.both.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartstring from '../ts/index.js';
|
||||
|
||||
tap.test('should normalize a string', async () => {
|
||||
const testString = `
|
||||
myawesome string;
|
||||
is indented with two spaces
|
||||
`;
|
||||
const normalizedString = smartstring.normalize.standard(testString);
|
||||
expect(normalizedString).toEqual(
|
||||
`
|
||||
myawesome string;
|
||||
is indented with two spaces
|
||||
`
|
||||
);
|
||||
});
|
||||
|
||||
tap.start();
|
39
test/test.ts
39
test/test.ts
@ -1,39 +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");
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
14
test/test.type.both.ts
Normal file
14
test/test.type.both.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as smartstring from '../ts/index.js';
|
||||
|
||||
tap.test('should state valuid utf8', async () => {
|
||||
expect(smartstring.type.isUtf8('hithere')).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('should state wether base64 string is valid', async () => {
|
||||
const base64String = smartstring.base64.encode('hi there');
|
||||
expect(smartstring.type.isBase64(base64String)).toBeTrue();
|
||||
expect(smartstring.type.isBase64('hi there')).toBeFalse();
|
||||
});
|
||||
|
||||
tap.start();
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartstring',
|
||||
version: '4.0.5',
|
||||
description: 'handle strings in smart ways. TypeScript ready.'
|
||||
}
|
17
ts/index.ts
17
ts/index.ts
@ -1,10 +1,11 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import SmartstringGit = require("./smartstring.git");
|
||||
import SmartstringDocker = require("./smartstring.docker");
|
||||
import * as create from './smartstring.create.js';
|
||||
import * as docker from './smartstring.docker.js';
|
||||
import * as indent from './smartstring.indent.js';
|
||||
import * as normalize from './smartstring.normalize.js';
|
||||
import * as type from './smartstring.type.js';
|
||||
|
||||
let smartstring = {
|
||||
git : SmartstringGit,
|
||||
docker: SmartstringDocker
|
||||
};
|
||||
export { create, docker, normalize, indent, type };
|
||||
|
||||
export = smartstring;
|
||||
export { Base64, base64 } from './smartstring.base64.js';
|
||||
export { Domain } from './smartstring.domain.js';
|
||||
export { GitRepo } from './smartstring.git.js';
|
||||
|
79
ts/smartstring.base64.ts
Normal file
79
ts/smartstring.base64.ts
Normal file
@ -0,0 +1,79 @@
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
/**
|
||||
* the type for base 64
|
||||
*/
|
||||
export type TStringInputType = 'string' | 'base64' | 'base64uri';
|
||||
|
||||
/**
|
||||
* handle base64 strings
|
||||
*/
|
||||
export class Base64 {
|
||||
private refString: string;
|
||||
constructor(inputStringArg, typeArg: TStringInputType) {
|
||||
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);
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param stringArg
|
||||
* checks wether the string is base64 encoded
|
||||
*/
|
||||
isBase64: (stringArg: string) => {
|
||||
const regex = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/;
|
||||
return regex.test(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.js';
|
||||
|
||||
/**
|
||||
* 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 = (): string => {
|
||||
return plugins.isounique.uni();
|
||||
};
|
@ -1,17 +1,18 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./smartstring.plugins");
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
|
87
ts/smartstring.domain.ts
Normal file
87
ts/smartstring.domain.ts
Normal file
@ -0,0 +1,87 @@
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
export class Domain {
|
||||
public fullName: string;
|
||||
public level1: string;
|
||||
public level2: string;
|
||||
public level3: string;
|
||||
public level4: string;
|
||||
public level5: string;
|
||||
public protocol: string;
|
||||
public zoneName: string;
|
||||
// aliases
|
||||
public topLevel: string;
|
||||
public domainName;
|
||||
public subDomain;
|
||||
public port;
|
||||
public nodeParsedUrl: plugins.url.UrlWithStringQuery;
|
||||
constructor(domainStringArg: string) {
|
||||
// lets do the node standard stuff first
|
||||
this.protocol = this._protocolRegex(domainStringArg);
|
||||
if (!this.protocol) {
|
||||
domainStringArg = `https://${domainStringArg}`;
|
||||
}
|
||||
this.nodeParsedUrl = plugins.url.parse(domainStringArg);
|
||||
this.port = this.nodeParsedUrl.port;
|
||||
|
||||
// lets do the rest after
|
||||
const regexMatches = this._domainRegex(
|
||||
domainStringArg.replace(this.nodeParsedUrl.pathname, '')
|
||||
);
|
||||
this.fullName = '';
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
if (regexMatches[i - 1]) {
|
||||
const 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.zoneName = this.level2 + '.' + this.level1;
|
||||
|
||||
// aliases
|
||||
this.topLevel = this.level1;
|
||||
this.domainName = this.level2;
|
||||
this.subDomain = this.level3;
|
||||
}
|
||||
|
||||
// helper functions
|
||||
|
||||
/** */
|
||||
private _domainRegex(stringArg: string) {
|
||||
const 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}$/;
|
||||
const 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
|
||||
const regexMatchesFiltered = regexMatches.filter(function (stringArg: string) {
|
||||
return stringArg !== '';
|
||||
});
|
||||
return regexMatchesFiltered;
|
||||
}
|
||||
|
||||
private _protocolRegex(stringArg: string) {
|
||||
const regexString = /^([a-zA-Z0-9]*):\/\//;
|
||||
const regexMatches = regexString.exec(stringArg);
|
||||
if (regexMatches) {
|
||||
return regexMatches[1];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private _portRegex(stringArg: string) {
|
||||
const regexString = /^([a-zA-Z0-9]*):\/\//;
|
||||
const regexMatches = regexString.exec(stringArg);
|
||||
if (regexMatches) {
|
||||
return regexMatches[1];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,63 +1,57 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./smartstring.plugins");
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ 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.js';
|
||||
|
||||
/**
|
||||
* 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.js';
|
||||
|
||||
/**
|
||||
* 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,22 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
let plugins = {
|
||||
beautylog: require("beautylog")
|
||||
};
|
||||
// node native
|
||||
import * as smartenv from '@pushrocks/smartenv';
|
||||
const smartenvInstance = new smartenv.Smartenv();
|
||||
import * as isounique from '@pushrocks/isounique';
|
||||
|
||||
export = plugins;
|
||||
export { isounique };
|
||||
|
||||
import { Buffer } from 'buffer';
|
||||
if (smartenvInstance.isBrowser) {
|
||||
globalThis.Buffer = Buffer;
|
||||
}
|
||||
import * as url from 'url';
|
||||
export { url };
|
||||
|
||||
// third party
|
||||
import { Base64 as jsBase64 } from 'js-base64';
|
||||
|
||||
import stripIndent from 'strip-indent';
|
||||
import normalizeNewline from 'normalize-newline';
|
||||
import randomatic from 'randomatic';
|
||||
|
||||
export { jsBase64, stripIndent, normalizeNewline, randomatic };
|
||||
|
99
ts/smartstring.type.ts
Normal file
99
ts/smartstring.type.ts
Normal file
@ -0,0 +1,99 @@
|
||||
import * as plugins from './smartstring.plugins.js';
|
||||
import * as base64 from './smartstring.base64.js';
|
||||
|
||||
export const isUtf8 = (stringArg: string) => {
|
||||
const bytes = Buffer.from(stringArg);
|
||||
let i = 0;
|
||||
while (i < bytes.length) {
|
||||
if (
|
||||
// ASCII
|
||||
bytes[i] === 0x09 ||
|
||||
bytes[i] === 0x0a ||
|
||||
bytes[i] === 0x0d ||
|
||||
(0x20 <= bytes[i] && bytes[i] <= 0x7e)
|
||||
) {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
// non-overlong 2-byte
|
||||
0xc2 <= bytes[i] &&
|
||||
bytes[i] <= 0xdf &&
|
||||
0x80 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0xbf
|
||||
) {
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
// excluding overlongs
|
||||
(bytes[i] === 0xe0 &&
|
||||
0xa0 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0xbf &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf) || // straight 3-byte
|
||||
(((0xe1 <= bytes[i] && bytes[i] <= 0xec) || bytes[i] === 0xee || bytes[i] === 0xef) &&
|
||||
0x80 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0xbf &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf) || // excluding surrogates
|
||||
(bytes[i] === 0xed &&
|
||||
0x80 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0x9f &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf)
|
||||
) {
|
||||
i += 3;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
// planes 1-3
|
||||
(bytes[i] === 0xf0 &&
|
||||
0x90 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0xbf &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf &&
|
||||
0x80 <= bytes[i + 3] &&
|
||||
bytes[i + 3] <= 0xbf) || // planes 4-15
|
||||
(0xf1 <= bytes[i] &&
|
||||
bytes[i] <= 0xf3 &&
|
||||
0x80 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0xbf &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf &&
|
||||
0x80 <= bytes[i + 3] &&
|
||||
bytes[i + 3] <= 0xbf) || // plane 16
|
||||
(bytes[i] === 0xf4 &&
|
||||
0x80 <= bytes[i + 1] &&
|
||||
bytes[i + 1] <= 0x8f &&
|
||||
0x80 <= bytes[i + 2] &&
|
||||
bytes[i + 2] <= 0xbf &&
|
||||
0x80 <= bytes[i + 3] &&
|
||||
bytes[i + 3] <= 0xbf)
|
||||
) {
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const isBase64 = (stringArg: string) => {
|
||||
const notBase64 = /[^A-Z0-9+\/=]/i;
|
||||
const len = stringArg.length;
|
||||
if (!len || len % 4 !== 0 || notBase64.test(stringArg)) {
|
||||
return false;
|
||||
}
|
||||
const firstPaddingChar = stringArg.indexOf('=');
|
||||
return (
|
||||
firstPaddingChar === -1 ||
|
||||
firstPaddingChar === len - 1 ||
|
||||
(firstPaddingChar === len - 2 && stringArg[len - 1] === '=')
|
||||
);
|
||||
};
|
@ -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"
|
||||
}
|
||||
}
|
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user