Skip to content

Commit 3348fd6

Browse files
author
Sven Ulrich
committed
Merge branch 'feature/hexadecimal'
2 parents 46edd4b + 0dc0fc6 commit 3348fd6

File tree

8 files changed

+44
-3146
lines changed

8 files changed

+44
-3146
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
node_modules/*
1+
node_modules
22
.vscode/*
33

44
dist/*.js

.npmignore

-8
This file was deleted.

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# CHANGELOG
2+
3+
#### 1.4.0
4+
- feature: added `AppendLine` and `AppendLineFormat`
5+
- feature: added hexadecimal conversion specifier
6+
- bugfix: `StringBuilder` initialization without parameter adds empty string to internal Values Array.
7+
- bugfix: When there is no placeholder in the template passed to String.Format it should return the original template
File renamed without changes.

dist/index.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ export class String {
170170
return arg;
171171
}
172172

173-
private static decimalToHexString(number: number, upperCase: boolean = false) {
174-
const hexNumber = number.toString(16);
173+
private static decimalToHexString(value: string, upperCase: boolean = false) {
174+
const parsed = parseFloat(value as string);
175+
const hexNumber = parsed.toString(16);
175176
return upperCase ? hexNumber.toLocaleUpperCase() : hexNumber;
176177
}
177178

@@ -258,10 +259,14 @@ export class String {
258259
}
259260

260261
export class StringBuilder {
261-
public Values: string[] = [];
262+
public Values: string[];
262263

263-
constructor(value: string = String.Empty) {
264-
this.Values = new Array(value);
264+
constructor(value?: string) {
265+
this.Values = [];
266+
267+
if (!String.IsNullOrWhiteSpace(value)) {
268+
this.Values = new Array(value);
269+
}
265270
}
266271

267272
public ToString() {

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"version": "1.4.0",
44
"description": "Simple lightweight string operation library for Typescript, works with Angular",
55
"main": "dist/index.min.js",
6+
"files": [
7+
"dist/**/*.js",
8+
"**/*.d.ts"
9+
],
610
"scripts": {
711
"test": "mocha -r ts-node/register tests/**/tests.ts",
812
"build": "gulp default && gulp compress"

tests/tests.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,27 @@ describe('String.Join', () => {
269269
});
270270
});
271271

272-
describe('String.Append', () => {
272+
describe('StringBuilder initialization', () => {
273+
it('should not add empty string if there is no ctor parameter', () => {
274+
var builder = new StringBuilder();
275+
builder.Append('First Part... ');
276+
builder.Append('Second Part...');
277+
278+
expect(builder.ToString()).to
279+
.equal('First Part... Second Part...');
280+
});
281+
282+
it('should add a string if there is ctor parameter', () => {
283+
var builder = new StringBuilder(String.Format("First {0}... ", "Part"));
284+
builder.AppendFormat('Second {0}...', 'Part');
285+
286+
console.log(builder.ToString());
287+
expect(builder.ToString()).to
288+
.equal('First Part... Second Part...');
289+
});
290+
});
291+
292+
describe('StringBuilderng.Append', () => {
273293
it('should append characters', () => {
274294
var builder = new StringBuilder();
275295
builder.Append('First Part... ');
@@ -290,7 +310,7 @@ describe('String.Append', () => {
290310
});
291311
});
292312

293-
describe('String.AppendLine', () => {
313+
describe('StringBuilder.AppendLine', () => {
294314
it('should append characters and new line', () => {
295315
var builder = new StringBuilder();
296316
builder.AppendLine('First Line...');

0 commit comments

Comments
 (0)