Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
65fc64f6aa | |||
8cda8c55c0 | |||
ec0b82de00 | |||
5e69664f59 | |||
f5838f6d6a | |||
fb4a03ad37 | |||
ceb6962a1c | |||
ffe757d820 | |||
60eb4b6b6e | |||
f73d394d35 | |||
212f41e00b | |||
59847dd287 | |||
7fa2fb1e74 | |||
355f7442ca | |||
88af0ab9aa | |||
5b5bcd804f |
@ -26,6 +26,7 @@ mirror:
|
|||||||
snyk:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install -g snyk
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
@ -33,24 +34,39 @@ snyk:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
|
sast:
|
||||||
|
stage: security
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||||
|
variables:
|
||||||
|
DOCKER_DRIVER: overlay2
|
||||||
|
allow_failure: true
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||||
|
- docker run
|
||||||
|
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
||||||
|
--volume "$PWD:/code"
|
||||||
|
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
||||||
|
artifacts:
|
||||||
|
reports:
|
||||||
|
sast: gl-sast-report.json
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install legacy
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -62,6 +78,7 @@ testLTS:
|
|||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -118,6 +135,7 @@ pages:
|
|||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci command npm install -g typedoc typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
@ -130,13 +148,3 @@ pages:
|
|||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
windowsCompatibility:
|
|
||||||
image: stefanscherer/node-windows:10-build-tools
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npm install & npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- windows
|
|
||||||
allow_failure: true
|
|
||||||
|
3
LICENSE
3
LICENSE
@ -1,6 +1,7 @@
|
|||||||
The MIT License (MIT)
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"@gitzone/npmts"
|
|
||||||
],
|
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
},
|
||||||
"npmdocker": {
|
"npmdocker": {
|
||||||
|
1095
package-lock.json
generated
1095
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstring",
|
"name": "@pushrocks/smartstring",
|
||||||
"version": "3.0.0",
|
"version": "3.0.8",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "handle strings in smart ways. TypeScript ready.",
|
"description": "handle strings in smart ways. TypeScript ready.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tsrun test/test.base64.ts",
|
"test": "(tstest test/)",
|
||||||
"build": "(npmts)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,14 +24,17 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartstring#readme",
|
"homepage": "https://gitlab.com/pushrocks/smartstring#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsrun": "^1.1.9",
|
"@gitzone/tsbuild": "^2.1.4",
|
||||||
"@pushrocks/tapbundle": "^3.0.1"
|
"@gitzone/tsrun": "^1.1.17",
|
||||||
|
"@gitzone/tstest": "^1.0.18",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
|
"@types/node": "^10.12.18"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"crypto-random-string": "^1.0.0",
|
"crypto-random-string": "^1.0.0",
|
||||||
"js-base64": "^2.4.8",
|
"js-base64": "^2.5.0",
|
||||||
"normalize-newline": "^3.0.0",
|
"normalize-newline": "^3.0.0",
|
||||||
"randomatic": "^3.0.0",
|
"randomatic": "^3.1.1",
|
||||||
"strip-indent": "^2.0.0"
|
"strip-indent": "^2.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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()
|
@ -1,16 +0,0 @@
|
|||||||
import * as smartstring from '../ts/index';
|
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
|
||||||
|
|
||||||
// typscript
|
|
||||||
tap.test('expect match reference paths', async () => {
|
|
||||||
// tslint:disable-next-line:no-unused-expression
|
|
||||||
expect(smartstring.typescript.regexReferencePath.test('/// <reference path="" />')).to.be.true;
|
|
||||||
|
|
||||||
// tslint:disable-next-line:no-unused-expression
|
|
||||||
expect(smartstring.typescript.regexReferencePath.test("/// <reference path='' />")).to.be.true;
|
|
||||||
|
|
||||||
// tslint:disable-next-line:no-unused-expression
|
|
||||||
expect(smartstring.typescript.regexReferencePath.test('/// <referencepath="" />')).to.be.false;
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
@ -2,10 +2,11 @@ import * as create from './smartstring.create';
|
|||||||
import * as docker from './smartstring.docker';
|
import * as docker from './smartstring.docker';
|
||||||
import * as indent from './smartstring.indent';
|
import * as indent from './smartstring.indent';
|
||||||
import * as normalize from './smartstring.normalize';
|
import * as normalize from './smartstring.normalize';
|
||||||
import * as typescript from './smartstring.typescript';
|
|
||||||
|
|
||||||
export { create, docker, typescript, normalize, indent };
|
export { create, docker, normalize, indent };
|
||||||
|
|
||||||
export { Base64, base64 } from './smartstring.base64';
|
export { Base64, base64 } from './smartstring.base64';
|
||||||
export { Domain } from './smartstring.domain';
|
export { Domain } from './smartstring.domain';
|
||||||
export { GitRepo } from './smartstring.git';
|
export { GitRepo } from './smartstring.git';
|
||||||
|
|
||||||
|
export { Cryptr } from './smartstring.encryption';
|
||||||
|
@ -1,13 +1,29 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
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 = (
|
export const createRandomString = (
|
||||||
patternArg: string,
|
patternArg: string,
|
||||||
lengthArg: number,
|
lengthArg?: number,
|
||||||
optionsArg: any
|
optionsArg?: any
|
||||||
): string => {
|
): string => {
|
||||||
return plugins.randomatic(patternArg, lengthArg, optionsArg);
|
return plugins.randomatic(patternArg, lengthArg, optionsArg);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createCryptoRandomString = (lengthArg): string => {
|
/**
|
||||||
|
* 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);
|
return plugins.cryptoRandomString(lengthArg);
|
||||||
};
|
};
|
||||||
|
43
ts/smartstring.encryption.ts
Normal file
43
ts/smartstring.encryption.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
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');
|
||||||
|
}
|
||||||
|
}
|
@ -3,11 +3,11 @@ import * as plugins from './smartstring.plugins';
|
|||||||
/**
|
/**
|
||||||
* replaces all occurences of something in a string
|
* replaces all occurences of something in a string
|
||||||
* @param stringArg
|
* @param stringArg
|
||||||
* @param searchRegExp
|
* @param searchPattern
|
||||||
* @param replacementString
|
* @param replacementString
|
||||||
*/
|
*/
|
||||||
export const replaceAll = (stringArg: string, searchRegExp: any, replacementString: string) => {
|
export const replaceAll = (stringArg: string, searchPattern: string, replacementString: string) => {
|
||||||
return stringArg.replace(new RegExp(searchRegExp, 'g'), replacementString);
|
return stringArg.replace(new RegExp(searchPattern, 'g'), replacementString);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,6 +17,6 @@ export const replaceAll = (stringArg: string, searchRegExp: any, replacementStri
|
|||||||
export const standard = (stringArg: string): string => {
|
export const standard = (stringArg: string): string => {
|
||||||
let fix1 = plugins.stripIndent(stringArg); // fix indention
|
let fix1 = plugins.stripIndent(stringArg); // fix indention
|
||||||
let fix2 = plugins.normalizeNewline(fix1); // fix newlines
|
let fix2 = plugins.normalizeNewline(fix1); // fix newlines
|
||||||
let fix3 = replaceAll(fix2, /\t/, ' '); // fix tabs
|
let fix3 = replaceAll(fix2, '\t/', ' '); // fix tabs
|
||||||
return fix3;
|
return fix3;
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
import 'typings-global';
|
// node native
|
||||||
|
import * as crypto from 'crypto';
|
||||||
|
|
||||||
|
export {
|
||||||
|
crypto
|
||||||
|
}
|
||||||
|
|
||||||
|
// third party
|
||||||
export let jsBase64 = require('js-base64').Base64;
|
export let jsBase64 = require('js-base64').Base64;
|
||||||
|
|
||||||
export let stripIndent = require('strip-indent');
|
export let stripIndent = require('strip-indent');
|
||||||
export let normalizeNewline = require('normalize-newline');
|
export let normalizeNewline = require('normalize-newline');
|
||||||
export let randomatic = require('randomatic');
|
export let randomatic = require('randomatic');
|
||||||
export let cryptoRandomString = require('crypto-random-string');
|
export let cryptoRandomString = require('crypto-random-string');
|
||||||
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
import * as plugins from './smartstring.plugins';
|
|
||||||
|
|
||||||
export const regexReferencePath = /\/\/\/\s*<reference\s+path\s*=\s*["|'].*["|']\s*\/>\s*[\\n]?/;
|
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"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