Compare commits
89 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 |
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
|
130
.gitlab-ci.yml
130
.gitlab-ci.yml
@ -1,35 +1,137 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci test legacy
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
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
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci test lts
|
||||
- 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
|
||||
|
||||
testSTABLE:
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- 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 publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
4
.snyk
Normal file
4
.snyk
Normal file
@ -0,0 +1,4 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.13.5
|
||||
ignore: {}
|
||||
patch: {}
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
}
|
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
3
LICENSE
3
LICENSE
@ -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
|
||||
|
39
README.md
39
README.md
@ -1,39 +0,0 @@
|
||||
# smartstring
|
||||
handle strings in smart ways. TypeScript ready.
|
||||
|
||||
## Status
|
||||
[](https://travis-ci.org/pushrocks/smartstring)
|
||||
[](https://ci.appveyor.com/project/philkunz/smartstring/branch/master)
|
||||
[](https://david-dm.org/pushrocks/smartstring)
|
||||
[](https://www.bithound.io/github/pushrocks/smartstring/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartstring)
|
||||
|
||||
## Usage
|
||||
Use TypeScript for intellisense.
|
||||
|
||||
```typescript
|
||||
import * as smartstring from "smartstring";
|
||||
|
||||
// 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.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"
|
||||
|
||||
```
|
||||
|
||||
## About the authors:
|
||||
[](https://lossless.com/)
|
||||
|
||||
[](https://paypal.me/lossless)
|
10
appveyor.yml
10
appveyor.yml
@ -1,10 +0,0 @@
|
||||
environment:
|
||||
nodejs_version: "4"
|
||||
install:
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
- npm install
|
||||
test_script:
|
||||
- node --version
|
||||
- npm --version
|
||||
- npm test
|
||||
build: off
|
7
dist/index.d.ts
vendored
7
dist/index.d.ts
vendored
@ -1,7 +0,0 @@
|
||||
import "typings-global";
|
||||
import SmartstringDocker = require("./smartstring.docker");
|
||||
import SmartstringTypescript = require("./smartstring.typescript");
|
||||
export { Domain } from "./smartstring.domain";
|
||||
export { GitRepo } from "./smartstring.git";
|
||||
export declare let docker: typeof SmartstringDocker;
|
||||
export declare let typescript: typeof SmartstringTypescript;
|
12
dist/index.js
vendored
12
dist/index.js
vendored
@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
var SmartstringDocker = require("./smartstring.docker");
|
||||
var SmartstringTypescript = require("./smartstring.typescript");
|
||||
var smartstring_domain_1 = require("./smartstring.domain");
|
||||
exports.Domain = smartstring_domain_1.Domain;
|
||||
var smartstring_git_1 = require("./smartstring.git");
|
||||
exports.GitRepo = smartstring_git_1.GitRepo;
|
||||
exports.docker = SmartstringDocker;
|
||||
exports.typescript = SmartstringTypescript;
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUNQLENBQUMsQ0FEc0I7QUFDdkIsSUFBTyxpQkFBaUIsV0FBVyxzQkFBc0IsQ0FBQyxDQUFDO0FBQzNELElBQU8scUJBQXFCLFdBQVcsMEJBQTBCLENBQUMsQ0FBQztBQUVuRSxtQ0FBcUIsc0JBQXNCLENBQUM7QUFBcEMsNkNBQW9DO0FBQzVDLGdDQUFzQixtQkFBbUIsQ0FBQztBQUFsQyw0Q0FBa0M7QUFDL0IsY0FBTSxHQUFHLGlCQUFpQixDQUFDO0FBQzNCLGtCQUFVLEdBQUcscUJBQXFCLENBQUMiLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiXG5pbXBvcnQgU21hcnRzdHJpbmdEb2NrZXIgPSByZXF1aXJlKFwiLi9zbWFydHN0cmluZy5kb2NrZXJcIik7XG5pbXBvcnQgU21hcnRzdHJpbmdUeXBlc2NyaXB0ID0gcmVxdWlyZShcIi4vc21hcnRzdHJpbmcudHlwZXNjcmlwdFwiKTtcblxuZXhwb3J0IHtEb21haW59IGZyb20gXCIuL3NtYXJ0c3RyaW5nLmRvbWFpblwiO1xuZXhwb3J0IHtHaXRSZXBvfSBmcm9tIFwiLi9zbWFydHN0cmluZy5naXRcIjtcbmV4cG9ydCBsZXQgZG9ja2VyID0gU21hcnRzdHJpbmdEb2NrZXI7XG5leHBvcnQgbGV0IHR5cGVzY3JpcHQgPSBTbWFydHN0cmluZ1R5cGVzY3JpcHQ7Il19
|
7
dist/smartstring.docker.d.ts
vendored
7
dist/smartstring.docker.d.ts
vendored
@ -1,7 +0,0 @@
|
||||
import "typings-global";
|
||||
/**
|
||||
* converts an erray of env strings from docker remote api to an usable object.
|
||||
* @param envArrayArg
|
||||
* @returns {}
|
||||
*/
|
||||
export declare let makeEnvObject: (envArrayArg: string[]) => {};
|
19
dist/smartstring.docker.js
vendored
19
dist/smartstring.docker.js
vendored
@ -1,19 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
/**
|
||||
* 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]]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mV4cG9ydCBsZXQgbWFrZUVudk9iamVjdCA9IGZ1bmN0aW9uKGVudkFycmF5QXJnOnN0cmluZ1tdKXtcbiAgICBsZXQgcmV0dXJuT2JqZWN0ID0ge307XG4gICAgbGV0IHJlZ2V4U3RyaW5nID0gLyguKik9KC4qKS87XG4gICAgZm9yKGxldCBlbnZLZXkgaW4gZW52QXJyYXlBcmcpe1xuICAgICAgICBsZXQgcmVnZXhNYXRjaGVzID0gcmVnZXhTdHJpbmcuZXhlYyhlbnZBcnJheUFyZ1tlbnZLZXldKTtcbiAgICAgICAgcmV0dXJuT2JqZWN0W3JlZ2V4TWF0Y2hlc1sxXV0gPSByZWdleE1hdGNoZXNbMl07XG4gICAgfTtcbiAgICByZXR1cm4gcmV0dXJuT2JqZWN0O1xufTsiXX0=
|
15
dist/smartstring.domain.d.ts
vendored
15
dist/smartstring.domain.d.ts
vendored
@ -1,15 +0,0 @@
|
||||
import "typings-global";
|
||||
export declare class Domain {
|
||||
fullName: string;
|
||||
level1: string;
|
||||
level2: string;
|
||||
level3: string;
|
||||
level4: string;
|
||||
level5: string;
|
||||
protocol: string;
|
||||
zoneName: string;
|
||||
topLevel: string;
|
||||
domainName: any;
|
||||
subDomain: any;
|
||||
constructor(domainStringArg: string);
|
||||
}
|
55
dist/smartstring.domain.js
vendored
55
dist/smartstring.domain.js
vendored
File diff suppressed because one or more lines are too long
10
dist/smartstring.git.d.ts
vendored
10
dist/smartstring.git.d.ts
vendored
@ -1,10 +0,0 @@
|
||||
import "typings-global";
|
||||
export declare class GitRepo {
|
||||
host: string;
|
||||
user: string;
|
||||
repo: string;
|
||||
accessToken: string;
|
||||
sshUrl: string;
|
||||
httpsUrl: string;
|
||||
constructor(stringArg: string, tokenArg?: string);
|
||||
}
|
51
dist/smartstring.git.js
vendored
51
dist/smartstring.git.js
vendored
@ -1,51 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
var plugins = require("./smartstring.plugins");
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ classes ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
var GitRepo = (function () {
|
||||
function GitRepo(stringArg, tokenArg) {
|
||||
var 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");
|
||||
}
|
||||
;
|
||||
return GitRepo;
|
||||
}());
|
||||
exports.GitRepo = GitRepo;
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ helpers ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
var gitRegex = function (stringArg) {
|
||||
var regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-]*)(?:\/)([a-zA-Z0-9\-]*)(?:\.git)/;
|
||||
var regexMatches = regexString.exec(stringArg);
|
||||
return regexMatches;
|
||||
};
|
||||
var gitLink = function (hostArg, userArg, repoArg, tokenArg, linkTypeArg) {
|
||||
if (tokenArg === void 0) { tokenArg = ""; }
|
||||
var 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;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLmdpdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQ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XNlIFwic3NoXCI6XG4gICAgICAgICAgICByZXR1cm5TdHJpbmcgPSBcImdpdEBcIiArXG4gICAgICAgICAgICAgICAgaG9zdEFyZyArIFwiOlwiICsgdXNlckFyZyArIFwiL1wiICsgcmVwb0FyZyArIFwiLmdpdFwiO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgICBwbHVnaW5zLmJlYXV0eWxvZy5lcnJvcihcIkxpbmsgVHlwZSBcIiArIGxpbmtUeXBlQXJnICsgXCIgbm90IGtub3duXCIpO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgfVxuICAgIHJldHVybiByZXR1cm5TdHJpbmc7XG59OyJdfQ==
|
2
dist/smartstring.plugins.d.ts
vendored
2
dist/smartstring.plugins.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
5
dist/smartstring.plugins.js
vendored
5
dist/smartstring.plugins.js
vendored
@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBRVAsQ0FBQyxDQUZzQjtBQUVULGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUMiLCJmaWxlIjoic21hcnRzdHJpbmcucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCJcblxuZXhwb3J0IGltcG9ydCBiZWF1dHlsb2cgPSByZXF1aXJlKFwiYmVhdXR5bG9nXCIpOyJdfQ==
|
2
dist/smartstring.typescript.d.ts
vendored
2
dist/smartstring.typescript.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import "typings-global";
|
||||
export declare let regexReferencePath: RegExp;
|
5
dist/smartstring.typescript.js
vendored
5
dist/smartstring.typescript.js
vendored
@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.regexReferencePath = /\/\/\/\s*<reference\s+path\s*=\s*["|'].*["|']\s*\/>\s*[\\n]?/;
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLnR5cGVzY3JpcHQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQUdaLDBCQUFrQixHQUFHLDhEQUE4RCxDQUFBIiwiZmlsZSI6InNtYXJ0c3RyaW5nLnR5cGVzY3JpcHQuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiXG5pbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3NtYXJ0c3RyaW5nLnBsdWdpbnNcIik7XG5cbmV4cG9ydCBsZXQgcmVnZXhSZWZlcmVuY2VQYXRoID0gL1xcL1xcL1xcL1xccyo8cmVmZXJlbmNlXFxzK3BhdGhcXHMqPVxccypbXCJ8J10uKltcInwnXVxccypcXC8+XFxzKltcXFxcbl0/LyJdfQ==
|
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",
|
||||
"shortDescription": "handle strings in smart ways. TypeScript ready.",
|
||||
"npmPackagename": "@pushrocks/smartstring",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
11049
package-lock.json
generated
Normal file
11049
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
48
package.json
48
package.json
@ -1,11 +1,13 @@
|
||||
{
|
||||
"name": "smartstring",
|
||||
"version": "2.0.10",
|
||||
"name": "@pushrocks/smartstring",
|
||||
"version": "3.0.23",
|
||||
"private": false,
|
||||
"description": "handle strings in smart ways. TypeScript ready.",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -22,12 +24,36 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartstring#readme",
|
||||
"devDependencies": {
|
||||
"npmts-g": "^5.2.6",
|
||||
"should": "^9.0.2",
|
||||
"typings-test": "^1.0.1"
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tsrun": "^1.2.12",
|
||||
"@gitzone/tstest": "^1.0.52",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^14.14.17",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"beautylog": "^5.0.12",
|
||||
"typings-global": "^1.0.3"
|
||||
}
|
||||
"@pushrocks/smartenv": "^4.0.16",
|
||||
"crypto-random-string": "^3.3.0",
|
||||
"js-base64": "^2.5.1",
|
||||
"normalize-newline": "^3.0.0",
|
||||
"randomatic": "^3.1.1",
|
||||
"strip-indent": "^3.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)
|
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();
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
||||
import "typings-test";
|
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();
|
37
test/test.domain.ts
Normal file
37
test/test.domain.ts
Normal file
@ -0,0 +1,37 @@
|
||||
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.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.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();
|
85
test/test.js
85
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();
|
83
test/test.ts
83
test/test.ts
@ -1,83 +0,0 @@
|
||||
import "typings-test"
|
||||
import * as smartstring from "../dist/index";
|
||||
let should = require("should");
|
||||
|
||||
describe("smartstring",function(){
|
||||
describe(".Domain class",function(){
|
||||
let testDomain:smartstring.Domain;
|
||||
let testDomain2:smartstring.Domain;
|
||||
it("should create a new Domain object",function(){
|
||||
testDomain = new smartstring.Domain("https://level3D.level2D.level1D");
|
||||
testDomain.should.be.instanceof(smartstring.Domain);
|
||||
console.log(testDomain);
|
||||
});
|
||||
it("should have a .topLevel",function(){
|
||||
testDomain.topLevel.should.equal("level1D");
|
||||
});
|
||||
it("should have a .level2",function(){
|
||||
testDomain.level2.should.equal("level2D");
|
||||
});
|
||||
it("should have a .level3",function(){
|
||||
testDomain.level3.should.equal("level3D");
|
||||
});
|
||||
it("should have the correct dns zone name",function(){
|
||||
testDomain.zoneName.should.equal("level2D.level1D");
|
||||
})
|
||||
it ("should have the correct protocol",function(){
|
||||
testDomain.protocol.should.equal("https");
|
||||
})
|
||||
it("testDomain2 should be a basic domain",function(){
|
||||
testDomain2 = new smartstring.Domain("bleu.de");
|
||||
console.log(testDomain2);
|
||||
});
|
||||
})
|
||||
describe(".Git class",function(){
|
||||
let testGit:smartstring.GitRepo;
|
||||
it("should create a new Git class GitRepo",function(){
|
||||
testGit = new smartstring.GitRepo("git+https://github.com/pushrocks/smartstring.git");
|
||||
testGit.should.be.instanceof(smartstring.GitRepo);
|
||||
})
|
||||
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:any = 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();
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
14
test/test.type.ts
Normal file
14
test/test.type.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as smartstring from '../ts';
|
||||
|
||||
tap.test('should state valuid utf8', async () => {
|
||||
expect(smartstring.type.isUtf8('hithere')).to.be.true;
|
||||
});
|
||||
|
||||
tap.test('should state wether base64 string is valid', async () => {
|
||||
const base64String = smartstring.base64.encode('hi there');
|
||||
expect(smartstring.type.isBase64(base64String)).to.be.true;
|
||||
expect(smartstring.type.isBase64('hi there')).to.be.false;
|
||||
});
|
||||
|
||||
tap.start();
|
19
ts/index.ts
19
ts/index.ts
@ -1,8 +1,13 @@
|
||||
import "typings-global"
|
||||
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';
|
||||
import * as type from './smartstring.type';
|
||||
|
||||
export {Domain} from "./smartstring.domain";
|
||||
export {GitRepo} from "./smartstring.git";
|
||||
export let docker = SmartstringDocker;
|
||||
export let typescript = SmartstringTypescript;
|
||||
export { create, docker, normalize, indent, type };
|
||||
|
||||
export { Base64, base64 } from './smartstring.base64';
|
||||
export { Domain } from './smartstring.domain';
|
||||
export { GitRepo } from './smartstring.git';
|
||||
|
||||
export { Cryptr } from './smartstring.encryption';
|
||||
|
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 @@
|
||||
import "typings-global"
|
||||
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;
|
||||
};
|
||||
|
@ -1,63 +1,81 @@
|
||||
import "typings-global"
|
||||
import plugins = require("./smartstring.plugins");
|
||||
import * as plugins from './smartstring.plugins';
|
||||
|
||||
export class Domain {
|
||||
fullName:string;
|
||||
level1:string;
|
||||
level2:string;
|
||||
level3:string;
|
||||
level4:string;
|
||||
level5:string;
|
||||
protocol:string;
|
||||
zoneName:string;
|
||||
//aliases
|
||||
topLevel:string;
|
||||
domainName;
|
||||
subDomain;
|
||||
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;
|
||||
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.nodeParsedUrl = plugins.url.parse(domainStringArg);
|
||||
this.port = this.nodeParsedUrl.port;
|
||||
|
||||
// lets do the rest after
|
||||
const regexMatches = this._domainRegex(domainStringArg.replace(this.nodeParsedUrl.path, ''));
|
||||
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.protocol = this._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);
|
||||
// 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
|
||||
let regexMatchesFiltered = regexMatches.filter(function(stringArg:string){
|
||||
return(stringArg != "");
|
||||
const 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];
|
||||
private _protocolRegex(stringArg: string) {
|
||||
const regexString = /^([a-zA-Z0-9]*):\/\//;
|
||||
const regexMatches = regexString.exec(stringArg);
|
||||
if (regexMatches) {
|
||||
return regexMatches[1];
|
||||
} else {
|
||||
return undefined;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
ts/smartstring.encryption.ts
Normal file
40
ts/smartstring.encryption.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import * as plugins from './smartstring.plugins';
|
||||
|
||||
const algorithm = 'aes-256-ctr';
|
||||
|
||||
export class Cryptr {
|
||||
private key: Buffer;
|
||||
|
||||
constructor(secret) {
|
||||
if (!secret || typeof secret !== 'string') {
|
||||
throw new Error('Cryptr: secret must be a non-0-length string');
|
||||
}
|
||||
|
||||
this.key = plugins.crypto.createHash('sha256').update(String(secret)).digest();
|
||||
}
|
||||
|
||||
encrypt(value: string) {
|
||||
if (value == null) {
|
||||
throw new Error('value must not be null or undefined');
|
||||
}
|
||||
|
||||
const iv = plugins.crypto.randomBytes(16);
|
||||
const cipher = plugins.crypto.createCipheriv(algorithm, this.key, iv);
|
||||
const encrypted = cipher.update(String(value), 'utf8', 'hex') + cipher.final('hex');
|
||||
|
||||
return iv.toString('hex') + encrypted;
|
||||
}
|
||||
|
||||
decrypt(value: string) {
|
||||
if (value == null) {
|
||||
throw new Error('value must not be null or undefined');
|
||||
}
|
||||
|
||||
const stringValue = String(value);
|
||||
const iv = Buffer.from(stringValue.slice(0, 32), 'hex');
|
||||
const encrypted = stringValue.slice(32);
|
||||
|
||||
const decipher = plugins.crypto.createDecipheriv(algorithm, this.key, iv);
|
||||
return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
|
||||
}
|
||||
}
|
@ -1,53 +1,56 @@
|
||||
import "typings-global"
|
||||
import plugins = require("./smartstring.plugins");
|
||||
import * as plugins from './smartstring.plugins';
|
||||
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ classes ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
export class GitRepo {
|
||||
host:string;
|
||||
user:string;
|
||||
repo:string;
|
||||
accessToken:string;
|
||||
sshUrl:string;
|
||||
httpsUrl:string;
|
||||
constructor(stringArg:string,tokenArg?:string){
|
||||
let regexMatches = gitRegex(stringArg);
|
||||
this.host = regexMatches[1];
|
||||
this.user = regexMatches[2];
|
||||
this.repo = regexMatches[3];
|
||||
this.accessToken = tokenArg;
|
||||
this.sshUrl = gitLink(this.host,this.user,this.repo,this.accessToken, "ssh");
|
||||
this.httpsUrl = gitLink(this.host,this.user,this.repo,this.accessToken, "https");
|
||||
};
|
||||
host: string;
|
||||
user: string;
|
||||
repo: string;
|
||||
accessToken: string;
|
||||
sshUrl: string;
|
||||
httpsUrl: string;
|
||||
constructor(stringArg: string, tokenArg?: string) {
|
||||
let regexMatches = gitRegex(stringArg);
|
||||
this.host = regexMatches[1];
|
||||
this.user = regexMatches[2];
|
||||
this.repo = regexMatches[3];
|
||||
this.accessToken = tokenArg;
|
||||
this.sshUrl = gitLink(this.host, this.user, this.repo, this.accessToken, 'ssh');
|
||||
this.httpsUrl = gitLink(this.host, this.user, this.repo, this.accessToken, 'https');
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- *
|
||||
* ------------------ helpers ------------------- *
|
||||
* ---------------------------------------------- */
|
||||
let gitRegex = function(stringArg:string){
|
||||
let regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-]*)(?:\/)([a-zA-Z0-9\-]*)(?:\.git)/;
|
||||
let regexMatches = regexString.exec(stringArg);
|
||||
return regexMatches;
|
||||
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;
|
||||
};
|
||||
|
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,3 +1,18 @@
|
||||
import "typings-global"
|
||||
// node native
|
||||
import * as smartenv from '@pushrocks/smartenv';
|
||||
const smartenvInstance = new smartenv.Smartenv();
|
||||
const crypto = smartenvInstance.getSafeNodeModule('crypto');
|
||||
|
||||
export import beautylog = require("beautylog");
|
||||
import * as url from 'url';
|
||||
|
||||
export { crypto, url };
|
||||
|
||||
// third party
|
||||
const jsBase64 = require('js-base64').Base64;
|
||||
|
||||
const stripIndent = require('strip-indent');
|
||||
const normalizeNewline = require('normalize-newline');
|
||||
const randomatic = smartenvInstance.getSafeNodeModule('randomatic');
|
||||
const cryptoRandomString = smartenvInstance.getSafeNodeModule('crypto-random-string');
|
||||
|
||||
export { jsBase64, stripIndent, normalizeNewline, randomatic, cryptoRandomString };
|
||||
|
99
ts/smartstring.type.ts
Normal file
99
ts/smartstring.type.ts
Normal file
@ -0,0 +1,99 @@
|
||||
import * as plugins from './smartstring.plugins';
|
||||
import * as base64 from './smartstring.base64';
|
||||
|
||||
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,4 +0,0 @@
|
||||
import "typings-global"
|
||||
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