Skip to content

Commit e3e85db

Browse files
committed
add helper function docs
1 parent 20badcd commit e3e85db

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

assets/images/helping-hand.jpg

29.5 KB
Loading

documentation/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ description: Documentation and developer's resources for Fano Framework, web app
5353
- [Sending email](/utilities/sending-email)
5454
- [Identifying client user-agent](/utilities/identifying-client-user-agent)
5555
- [Working with regular expression](/utilities/regular-expression)
56+
- [Helper functions](/utilities/helper-functions)
5657
- [Rate limiting request](/utilities/rate-limit)
5758

5859
## Database

utilities/helper-functions/index.md

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,84 @@ description: Tutorial on how to use helper functions provided by Fano Framework
77

88
## About Helper function
99

10-
![Rate limiting](/assets/images/rate-limit.jpg){:class="image fit"}
10+
![Helper illustration](/assets/images/helping-hand.jpg){:class="image fit"}
1111

12-
(Image by Ludovic Charlet [unsplash.com](https://unsplash.com/photos/CGWK6k2RduY)).
12+
Photo by [Austin Kehmeier](https://unsplash.com/@a_kehmeier?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/helping-hand?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)
1313

14+
Fano Framework provides helper functions to simplify common tasks such as generate slug string, join string with delimiter or read file content.
1415

16+
All helpers functions are declared in `fano.pas` unit.
17+
18+
## Read file content to string
19+
20+
`readFile()` reads file content and output is as string. It accepts one parameter file path of filename to load.
21+
22+
```
23+
(*!------------------------------------------------
24+
* read file to string
25+
*-----------------------------------------------
26+
* @param filepath file to load
27+
* @returns contents of file as string
28+
*-----------------------------------------------*)
29+
function readFile(const filepath : string) : string;
30+
```
31+
32+
Please note, it may consume a lot of memories if file size is big.
33+
34+
```
35+
var fileContent : string;
36+
...
37+
38+
fileContent := readFile('/tmp/myfile');
39+
```
40+
41+
## Join array of string as string
42+
43+
`join()` function concatenates array of string as a single string with delimiter.
44+
45+
```
46+
(*!------------------------------------------------
47+
* join array of string with a delimiter
48+
*-----------------------------------------------
49+
* @param delimiter string to separate each
50+
* @param values array of string to join
51+
*-----------------------------------------------*)
52+
function join(const delimiter : string; const values : array of string) : string;
53+
```
54+
55+
For example
56+
```
57+
var joinedStr : string;
58+
...
59+
60+
//joinedStr = 'hello#good#people';
61+
joinedStr := join('#', ['hello', 'good', 'people']);
62+
```
63+
64+
## Generate slug
65+
66+
`slug()` function generates string consists of alpha numeric characters separated by dash characters and strips everything else.
67+
68+
```
69+
(*!------------------------------------------------
70+
* generate slug
71+
*-----------------------------------------------
72+
* @param originalStr input string
73+
* @return slug
74+
*-----------------------------------------------*)
75+
function slug(const originalStr : string) : string;
76+
```
77+
78+
For example
79+
80+
```
81+
var slugStr : string;
82+
...
83+
84+
//slugStr = 'hello-good-people';
85+
slugStr := slug('hello good @##@$$@$people']);
86+
```
87+
88+
## Explore more
89+
90+
- [Regular expression](/utilities/regular-expression)

utilities/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ description: Tutorial on how to work with some utilities provided by Fano Framew
2525

2626
- [Working with regular expression](/utilities/regular-expression)
2727

28+
## Helper functions
29+
30+
- [Helper functions](/utilities/helper-functions)
31+
2832
## Rate limiting request
2933

3034
- [Rate limiting request](/utilities/rate-limit)

0 commit comments

Comments
 (0)