Skip to content

NEWLINE: added eol for different environments and updated dependencies #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 69 additions & 69 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
export declare const emptyString = "";
export declare function isNullOrWhiteSpace(value: string | null): boolean;
export declare function joinString(delimiter: string, ...args: (string | object | Array<any>)[]): string;
export declare function formatString(format: string, ...args: any[]): string;
export declare class String {
private static readonly regexNumber;
private static readonly regexObject;
static empty: string;
/**
* @deprecated The property should not be used, and will be removed in future versions! Use `String.empty` instead.
*/
static Empty: string;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `String.isNullOrWhiteSpace()` instead.
*/
static IsNullOrWhiteSpace(value: string | null | undefined): boolean;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `String.join()` instead.
*/
static Join(delimiter: string, ...args: (string | object | Array<any>)[]): string;
/**
* @deprecated The method should not be used, and will be removed in future version!s Use `String.format()` instead.
*/
static Format(format: string, ...args: any[]): string;
static isNullOrWhiteSpace(value: string | null): boolean;
static join(delimiter: string, ...args: (string | object | Array<any>)[]): string;
static format(format: string, ...args: any[]): string;
private static formatString;
private static parsePattern;
private static decimalToHexString;
private static getDisplayDateFromString;
private static getSortableDateFromString;
private static formatNumber;
private static joinString;
}
export declare class StringBuilder {
Values: string[];
constructor(value?: string);
toString(): string;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `toString()` instead.
*/
ToString(): string;
append(value: string): void;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `append()` instead.
*/
Append(value: string): void;
appendLine(value: string): void;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `appendLine()` instead.
*/
AppendLine(value: string): void;
appendFormat(format: string, ...args: any[]): void;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `appendFormat()` instead.
*/
AppendFormat(format: string, ...args: any[]): void;
appendLineFormat(format: string, ...args: any[]): void;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `appendLineFormat()` instead.
*/
AppendLineFormat(format: string, ...args: any[]): void;
clear(): void;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `clear()` instead.
*/
Clear(): void;
}
export declare const emptyString = "";
export declare function isNullOrWhiteSpace(value: string | null): boolean;
export declare function joinString(delimiter: string, ...args: (string | object | Array<any>)[]): string;
export declare function formatString(format: string, ...args: any[]): string;
export declare class String {
private static readonly regexNumber;
private static readonly regexObject;
static empty: string;
/**
* @deprecated The property should not be used, and will be removed in future versions! Use `String.empty` instead.
*/
static Empty: string;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `String.isNullOrWhiteSpace()` instead.
*/
static IsNullOrWhiteSpace(value: string | null | undefined): boolean;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `String.join()` instead.
*/
static Join(delimiter: string, ...args: (string | object | Array<any>)[]): string;
/**
* @deprecated The method should not be used, and will be removed in future version!s Use `String.format()` instead.
*/
static Format(format: string, ...args: any[]): string;
static isNullOrWhiteSpace(value: string | null): boolean;
static join(delimiter: string, ...args: (string | object | Array<any>)[]): string;
static format(format: string, ...args: any[]): string;
private static formatString;
private static parsePattern;
private static decimalToHexString;
private static getDisplayDateFromString;
private static getSortableDateFromString;
private static formatNumber;
private static joinString;
}
export declare class StringBuilder {
Values: string[];
constructor(value?: string);
toString(): string;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `toString()` instead.
*/
ToString(): string;
append(value: string): void;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `append()` instead.
*/
Append(value: string): void;
appendLine(value: string): void;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `appendLine()` instead.
*/
AppendLine(value: string): void;
appendFormat(format: string, ...args: any[]): void;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `appendFormat()` instead.
*/
AppendFormat(format: string, ...args: any[]): void;
appendLineFormat(format: string, ...args: any[]): void;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `appendLineFormat()` instead.
*/
AppendLineFormat(format: string, ...args: any[]): void;
clear(): void;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `clear()` instead.
*/
Clear(): void;
}
17 changes: 14 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
const EOL = '\r\n';

let newLine = '\r\n';
const isNode = new Function('try {return this===global;}catch(e){return false;}');

if (isNode()) {
console.log('running under node.js');
const isWindows = typeof process != 'undefined' && 'win32' === process.platform;

if (!isWindows) {
newLine = '\n';
}
}

export const emptyString = '';

Expand Down Expand Up @@ -331,7 +342,7 @@ export class StringBuilder {
}

public appendLine(value: string) {
this.Values.push(EOL + value);
this.Values.push(newLine + value);
}

/**
Expand All @@ -353,7 +364,7 @@ export class StringBuilder {
}

public appendLineFormat(format: string, ...args: any[]) {
this.Values.push(EOL + String.format(format, ...args));
this.Values.push(newLine + String.format(format, ...args));
}

/**
Expand Down
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@
},
"homepage": "https://github.com/sevensc/typescript-string-operations#readme",
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/mocha": "^9.1.1",
"@types/node": "^18.7.11",
"@typescript-eslint/eslint-plugin": "^5.34.0",
"@typescript-eslint/parser": "^5.34.0",
"chai": "^4.2.0",
"eslint": "^8.22.0",
"mocha": "^10.0.0",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^18.15.3",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"chai": "^4.3.7",
"eslint": "^8.36.0",
"mocha": "^10.2.0",
"ts-node": "^10.9.1",
"typescript": "^4.7.4",
"uglify-js": "^3.17.0"
},
"directories": {
"typescript": "^4.9.5",
"uglify-js": "^3.17.4"
},
"directories": {},
"resolutions": {
"natives": "1.1.3"
}
}
}
19 changes: 15 additions & 4 deletions tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ import { Fruit } from './fruit';
import { expect } from 'chai';
import 'mocha';

export const EOL = '\r\n';
let newLine = '\r\n';
const isNode = new Function('try {return this===global;}catch(e){return false;}');

if (isNode()) {
console.log('running under node.js');
const isWindows = typeof process != 'undefined' && 'win32' === process.platform;

if (!isWindows) {
newLine = '\n';
}
}


describe('String.IsNullOrWhitespace', () => {

Expand Down Expand Up @@ -452,7 +463,7 @@ describe('StringBuilder.AppendLine', () => {
builder.AppendLine('Second Line...');

expect(builder.ToString()).to
.equal(`${EOL}First Line...${EOL}Second Line...`);
.equal(`${newLine}First Line...${newLine}Second Line...`);
});

it('should append characters and new line', () => {
Expand All @@ -462,7 +473,7 @@ describe('StringBuilder.AppendLine', () => {

console.log(builder.ToString());
expect(builder.ToString()).to
.equal(`${EOL}First Line...${EOL}Second Line...`);
.equal(`${newLine}First Line...${newLine}Second Line...`);
});

it('should append characters and new line', () => {
Expand All @@ -472,6 +483,6 @@ describe('StringBuilder.AppendLine', () => {

console.log(builder.ToString());
expect(builder.ToString()).to
.equal(`${EOL}First Line...${EOL}Second Line...`);
.equal(`${newLine}First Line...${newLine}Second Line...`);
});
});
Loading