Skip to content

Commit ed506f8

Browse files
authored
Merge pull request #27 from sevensc/updatedeps
Implement methods without using "String".
2 parents 5f83616 + 5d4b76a commit ed506f8

18 files changed

+1691
-3055
lines changed

.circleci/config.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ version: 2.1
33
executors:
44
nodejs:
55
docker:
6-
- image: circleci/node:7.10
6+
- image: cimg/node:18.7.0
77

88
commands:
9-
ceckout-and-restore-cache:
9+
checkout-and-restore-cache:
1010
description: "restore cache"
1111
steps:
1212
- checkout
@@ -22,26 +22,37 @@ commands:
2222
- node_modules
2323

2424
jobs:
25+
lint:
26+
executor: nodejs
27+
steps:
28+
- checkout-and-restore-cache
29+
- run: yarn install
30+
- save-node-modules-cache
31+
- run: yarn lint
32+
2533
build:
2634
executor: nodejs
2735
steps:
28-
- ceckout-and-restore-cache
29-
- run: npm install
36+
- checkout-and-restore-cache
37+
- run: yarn install
3038
- save-node-modules-cache
31-
- run: npm run build
39+
- run: yarn build
3240

3341
test:
3442
executor: nodejs
3543
steps:
36-
- ceckout-and-restore-cache
37-
- run: npm install
38-
- run: npm run build
39-
- run: npm run test
44+
- checkout-and-restore-cache
45+
- run: yarn install
46+
- run: yarn build
47+
- run: yarn test
4048

4149
workflows:
4250
build-and-deploy:
4351
jobs:
44-
- build
52+
- lint
53+
- build:
54+
requires:
55+
- lint
4556
- test:
4657
requires:
4758
- build

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.js
2+
*.d.ts

.eslintrc.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es2021": true,
6+
"node": true
7+
},
8+
"extends": [
9+
"eslint:recommended",
10+
"plugin:@typescript-eslint/recommended"
11+
],
12+
"overrides": [],
13+
"parser": "@typescript-eslint/parser",
14+
"parserOptions": {
15+
"ecmaVersion": "latest"
16+
},
17+
"plugins": [
18+
"@typescript-eslint"
19+
],
20+
"rules": {
21+
"@typescript-eslint/no-explicit-any": [
22+
"off"
23+
],
24+
"@typescript-eslint/no-var-requires": [
25+
"off"
26+
],
27+
"@typescript-eslint/no-inferrable-types": [
28+
"off"
29+
],
30+
"indent": [
31+
"off",
32+
"tab"
33+
],
34+
"linebreak-style": [
35+
"warn",
36+
"unix"
37+
],
38+
"no-mixed-spaces-and-tabs": [
39+
"warn",
40+
"smart-tabs"
41+
],
42+
"quotes": [
43+
"warn",
44+
"single",
45+
{
46+
"allowTemplateLiterals": true
47+
}
48+
],
49+
"semi": [
50+
"warn",
51+
"always"
52+
],
53+
"comma-dangle": [
54+
"warn",
55+
"always-multiline"
56+
]
57+
}
58+
}

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
node_modules
22
.vscode/*
3-
4-
dist/*.js
3+
ui
54

65
# Compiled source #
76
###################
@@ -12,7 +11,8 @@ dist/*.js
1211
*.o
1312
*.so
1413
*.min.js
15-
14+
*.d.ts.map
15+
dist
1616
# Packages #
1717
############
1818
# it's better to unpack these files and commit the raw source
@@ -40,4 +40,4 @@ dist/*.js
4040
.Spotlight-V100
4141
.Trashes
4242
ehthumbs.db
43-
Thumbs.db
43+
Thumbs.db

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@
88
- feature: added `AppendLine` and `AppendLineFormat`
99
- feature: added hexadecimal conversion specifier
1010
- bugfix: `StringBuilder` initialization without parameter adds empty string to internal Values Array.
11-
- bugfix: When there is no placeholder in the template passed to String.Format it should return the original template
11+
- bugfix: When there is no placeholder in the template passed to String.format it should return the original template
12+
13+
#### 1.5.0
14+
- Using latest typescript version, please check if your environment still works with this version before upgrading!
15+
- feature: !IMPORTANT methods/properties starting with uppercase are marked deprecated now and will be removed in future versions! Check the deprecated infos
16+
- feature: added class `$String` for everybody who is facing issues when `String` is used.
17+
- feature: `String.isNullOrWhiteSpace` accepts null or undefined now
18+
- chore: Updated packages
19+
- chore: added linting

CONTRIBUTING.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# Readme for developers
1+
# Contributing
22

33
## Getting Started
44

55
1. clone this repo
6-
1. execute `npm install -g gulp`
7-
1. execute `npm install`
6+
1. execute `yarn install (not npm!)`
87
1. code!
9-
1. build using `npm run build`
10-
1. test using `npm run test`
8+
1. build using `yarn build`
9+
1. test using `yarn test`

readme.md renamed to README.md

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,65 @@
11

2+
[![CircleCI](https://circleci.com/gh/sevensc/typescript-string-operations.svg?style=shield)](https://app.circleci.com/pipelines/github/sevensc/typescript-string-operations)
3+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sevensc_typescript-string-operations&metric=alert_status)](https://sonarcloud.io/dashboard?id=sevensc_typescript-string-operations)
4+
![npm](https://img.shields.io/npm/v/typescript-string-operations)
5+
![npm](https://img.shields.io/npm/dw/typescript-string-operations)
6+
27

3-
![CircleCI](https://img.shields.io/circleci/build/github/iwt-svenulrich/typescript-string-operations?logo=circleci&token=9234d9f6803b37ebfcd4887fa2d6d51aa2cf5214)
4-
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sevensc_typescript-string-operations&metric=alert_status)](https://sonarcloud.io/dashboard?id=sevensc_typescript-string-operations)![npm](https://img.shields.io/npm/v/typescript-string-operations)![npm](https://img.shields.io/npm/dw/typescript-string-operations)
58
# Simple lightweight string operation library for Typescript.
69
## No jQuery required! Unit tested, works with Angular.
710

11+
812
```typescript
9-
import { String, StringBuilder } from 'typescript-string-operations';
13+
import { StringBuilder, join, format, isNullOrWhiteSpace } from 'typescript-string-operations';
1014
```
15+
16+
When migrating from Version 1.4.1 or lower, you can also import the class `String`. Using this String class would override the native `String` object from JavaScript. We will remove this declaration with the next major release
17+
18+
```typescript
19+
import { String } from 'typescript-string-operations';
20+
```
1121

1222
#### USAGE:
1323

14-
### String.Empty
24+
### String.empty
1525
```typescript
16-
var id = String.Empty;
26+
var id = emptyString; // or String.empty
27+
// output: id = '';
1728
```
1829

19-
### String.IsNullOrWhiteSpace():
30+
### String.isNullOrWhiteSpace():
2031
```typescript
2132
var id = image.GetId();
22-
if(String.IsNullOrWhiteSpace(id))
33+
if(isNullOrWhiteSpace(id)) // String.isNullOrWhiteSpace(id)
2334
return image;
2435
```
25-
### String.Format():
36+
### String.format():
2637

2738
```typescript
2839
var id = image.GetId()
29-
String.Format("image_{0}.jpg", id)
40+
formatString("image_{0}.jpg", id) // or String.format()
3041
output: "image_2db5da20-1c5d-4f1a-8fd4-b41e34c8c5b5.jpg";
3142
```
3243

3344
Specifier available!
3445
```typescript
35-
var value = String.Format("{0:L}", "APPLE"); //output "apple"
36-
37-
value = String.Format("{0:U}", "apple"); // output "APPLE"
46+
var value = formatString("{0:L}", "APPLE"); //output "apple"
3847

39-
value = String.Format("{0:d}", "2017-01-23 00:00"); //output "23.01.2017"
48+
value = formatString("{0:U}", "apple"); // output "APPLE"
4049

50+
value = formatString("{0:d}", "2017-01-23 00:00"); //output "23.01.2017"
4151

42-
value = String.Format("{0:s}", "21.03.2017 22:15:01") //output "2017-03-21T22:15:01"
52+
value = formatString("{0:s}", "21.03.2017 22:15:01") //output "2017-03-21T22:15:01"
4353

44-
value = String.Format("{0:n}", 1000000);
54+
value = formatString("{0:n}", 1000000);
4555
//output "1.000.000"
4656

47-
value = String.Format("{0:00}", 1);
57+
value = formatString("{0:00}", 1);
4858
//output "01"
4959
```
5060

5161
## UPDATE
52-
#### String Format for Objects including specifiers
62+
#### String.format for Objects including specifiers
5363

5464
```typescript
5565
var fruit = new Fruit();
@@ -58,7 +68,7 @@ fruit.color = "RED";
5868
fruit.shippingDate = new Date(2018, 1, 1);
5969
fruit.amount = 10000;
6070

61-
String.Format("the {type:U} is {color:L} shipped on {shippingDate:s} with an amount of {amount:n}", fruit);
71+
format("the {type:U} is {color:L} shipped on {shippingDate:s} with an amount of {amount:n}", fruit);
6272
// output: the APPLE is red shipped on 2018-01-01 with an amount of 10.000
6373

6474
```
@@ -75,33 +85,33 @@ String.Format("the {type:U} is {color:L} shipped on {shippingDate:s} with an amo
7585

7686

7787

78-
### String.Join():
88+
### String.join():
7989

8090
```typescript
81-
var value = String.Join("; ", "Apple", "Banana");
91+
var value = joinString("; ", "Apple", "Banana"); // or String.join()
8292
//output: "Apple; Banana";
8393
```
8494
#### OR
8595

8696
```typescript
8797
let object = { Name: "Foo", Value: "Bar" };
88-
var value = String.Join('.', object);
98+
var value = joinString('.', object);
8999
//output: "Foo.Bar";
90100

91101
var array = ['Apple', 'Banana']
92-
var value = String.Join("; ", array);
102+
var value = joinString("; ", array);
93103
//output: "Apple; Banana";
94104
```
95105

96106
## Methods
97107

98108
| Method | Type | Description | Parameter |
99109
| :------------------------:|:-----------:|:--------------------------:|:----------:|
100-
| `Empty` | `Property` | simply returns `""`. |
101-
| `IsNullOrWhiteSpace` | `Method` | returns true value if given parameter is either null, empty or undefined. | `format`, `args`
102-
| `Format` | `Method` | Converts the value of objects to strings based on the formats specified and inserts them into another string. | `format`, `args`
103-
| `Join` | `Method` | Combines arguments delimited by given seperator.| `delimiter`,`args`
104-
| `Join` | `Method` | Combines arguments delimited by given seperator from array. | `delimiter`,`array` |
110+
| `empty` | `Property` | simply returns `""`. |
111+
| `isNullOrWhiteSpace` | `Method` | returns true value if given parameter is either null, empty or undefined. | `format`, `...args`
112+
| `format`/`formatString` | `Method` | Converts the value of objects to strings based on the formats specified and inserts them into another string. | `format`, `...args`
113+
| `join`/`joinString` | `Method` | Combines arguments delimited by given seperator.| `delimiter`,`...args`
114+
| `join`/`joinString` | `Method` | Combines arguments delimited by given seperator from array. | `delimiter`,`array` |
105115

106116

107117
### StringBuilder
@@ -117,7 +127,7 @@ var builder = new StringBuilder("My favorite fruits are: ");
117127
builder.Append("Apples, ");
118128
builder.Append("Bananas ");
119129

120-
// of course using String.Format()
130+
// using String.format() internally
121131
builder.AppendFormat("and especially {0:U}!", favoriteFruit);
122132
builder.AppendFormat(" I eat {0} every day!", 10);
123133

@@ -131,8 +141,8 @@ var fruits = builder.ToString();
131141
| Method | Type | Description | Parameter |
132142
| :------------------------:|:-----------:|:--------------------------:|:----------:|
133143
| `Append` | `Method` | appends a string. | `value` |
134-
| `AppendFormat` | `Method` | see description for `String.Format()`| `format`, `args`|
144+
| `AppendFormat` | `Method` | see description for `format()`| `format`, `args`|
135145
| `AppendLine` | `Method` | appends a string in a new line. | `format`, `args`|
136-
| `AppendLineFormat` | `Method` | like `String.Format()` in a new line | `format`, `args`|
146+
| `AppendLineFormat` | `Method` | like `format()` in a new line | `format`, `args`|
137147
| `Clear` | `Method` | clears the `StringBuilder` | |
138148
| `ToString` | `Method` | creates the actual string. | |

dist/string.d.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

dist/stringbuilder.d.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

gulpfile.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)