Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit eb34349

Browse files
committed
Update docs to include JS Utils examples
1 parent 53e9fa8 commit eb34349

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

README.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ServiceStack.Text is an **independent, dependency-free** serialization library c
1414
- [Fast Reflection Utils](http://docs.servicestack.net/reflection-utils)
1515
- Several String Extensions, Collection extensions, Reflection Utils and lots more.
1616

17-
### [Portable Class Library Support](https://github.com/ServiceStackApps/HelloMobile#portable-class-library-support)
17+
### [Mobile Apps Support](https://github.com/ServiceStackApps/HelloMobile)
1818

1919
### Try out [ServiceStack.Text Live](http://gistlyn.com/text)
2020

@@ -151,25 +151,55 @@ Also a thin **.NET 4.0 Dynamic JSON** wrapper around ServiceStack's JSON library
151151
[ServiceStack.Razor](https://github.com/ServiceStack/ServiceStack.Text/blob/master/src/ServiceStack.Text/Pcl.Dynamic.cs)
152152
project. It provides a dynamic, but more succinct API than the above options.
153153

154-
## Install ServiceStack.Text
154+
### JS Utils
155155

156-
PM> Install-Package ServiceStack.Text
156+
ServiceStack.Text APIs for deserializing arbitrary JSON requires specifying the the Type to deserialize into. An alternative flexible approach to read any arbitrary JavaScript or JSON data structures is to use the high-performance and memory efficient JSON utils in
157+
[ServiceStack Templates](http://templates.servicestack.net) implementation of JavaScript.
157158

158-
> From v4.0.62+ [ServiceStack.Text is now free!](https://github.com/ServiceStack/ServiceStack/blob/master/docs/2016/v4.0.62.md#servicestacktext-is-now-free)
159+
```csharp
160+
JSON.parse("1") //= int 1
161+
JSON.parse("1.1") //= double 1.1
162+
JSON.parse("'a'") //= string "a"
163+
JSON.parse("{a:1}") //= new Dictionary<string, object> { {"a", 1 } }
164+
```
159165

160-
Support for PCL platfroms requires PCL adapters in:
166+
#### Eval
167+
168+
Since JS Utils is an essential part of [ServiceStack Template language](http://templates.servicestack.net) it allows for advanced scenarios like implementing a text DSL or scripting language for executing custom logic or business rules you want to be able to change without having to compile or redeploy your App. It uses [Templates Sandbox](http://templates.servicestack.net/docs/sandbox) which lets you evaluate the script within a custom scope that defines what functions
169+
and arguments it has access to, e.g:
170+
171+
```csharp
172+
public class CustomFilter : TemplateFilter
173+
{
174+
public string reverse(string text) => new string(text.Reverse().ToArray());
175+
}
161176

162-
PM> Install-Package ServiceStack.Client
177+
var scope = JS.CreateScope(
178+
args: new Dictionary<string, object> { { "arg", "value"} },
179+
functions: new CustomFilter());
163180

164-
### [Docs and Downloads for older v3 BSD releases](https://github.com/ServiceStackV3/ServiceStackV3)
181+
JS.eval("arg", scope) //= "value"
182+
JS.eval("reverse(arg)", scope) //= "eulav"
183+
JS.eval("itemsOf(3, padRight(reverse(arg), 8, '_'))", scope) //= ["eulav___", "eulav___", "eulav___"]
184+
185+
//= { a: ["eulav___", "eulav___", "eulav___"] }
186+
JS.eval("{a: itemsOf(3, padRight(reverse(arg), 8, '_')) }", scope)
187+
```
188+
189+
ServiceStack's JS Utils is available in the [ServiceStack.Common](https://www.nuget.org/packages/ServiceStack.Common) NuGet package.
190+
191+
## Install ServiceStack.Text
192+
193+
PM> Install-Package ServiceStack.Text
194+
195+
> From v4.0.62+ [ServiceStack.Text is now free!](https://github.com/ServiceStack/ServiceStack/blob/master/docs/2016/v4.0.62.md#servicestacktext-is-now-free)
165196
166197
## Copying
167198

168199
Since September 2013, ServiceStack source code is available under GNU Affero General Public License/FOSS License Exception, see license.txt in the source. Alternative commercial licensing is also available, contact [email protected] for details.
169200

170201
## Contributing
171202

172-
Commits can be made to either the **master** (v4) or **v3** release branches.
173203
Contributors need to approve the [Contributor License Agreement](https://docs.google.com/forms/d/16Op0fmKaqYtxGL4sg7w_g-cXXyCoWjzppgkuqzOeKyk/viewform) before any code will be reviewed, see the [Contributing wiki](https://github.com/ServiceStack/ServiceStack/wiki/Contributing) for more details.
174204

175205
## ServiceStack.JsonSerializer

0 commit comments

Comments
 (0)