https://github.com/terran-source/dart-interpolation
A Dart package to handle dynamic String & Json interpolation.
https://github.com/terran-source/dart-interpolation
dart flutter interpolate interpolation json-interpolation
Last synced: about 1 year ago
JSON representation
A Dart package to handle dynamic String & Json interpolation.
- Host: GitHub
- URL: https://github.com/terran-source/dart-interpolation
- Owner: Terran-Source
- License: mit
- Created: 2020-04-03T14:47:31.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-09-14T09:49:15.000Z (over 4 years ago)
- Last Synced: 2024-10-31T21:36:17.547Z (over 1 year ago)
- Topics: dart, flutter, interpolate, interpolation, json-interpolation
- Language: Dart
- Homepage: https://pub.dev/packages/interpolation
- Size: 96.7 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# interpolation [](https://pub.dev/packages/extend) [](LICENSE)
A Dart package to handle dynamic String & Json interpolation.
## Usage
A simple usage example:
#### Add the dependency in pubspec.yaml
```yaml
# pubspec.yaml
# add dependencies
dependencies:
interpolation:
```
#### Now the code
```dart
import 'package:interpolation/interpolation.dart';
void main() {
var interpolation = Interpolation();
var str =
"Hi, my name is '{name}'. I'm {age}. I am {education.degree} {education.profession}.";
print(interpolation.eval(str, {
'name': 'David',
'age': 29,
'education': {'degree': 'M.B.B.S', 'profession': 'Doctor'}
}));
// output: Hi, my name is 'David'. I'm 29. I am M.B.B.S Doctor.
var obj = {
'a': 'a',
'b': 10,
'c': {
'd': 'd',
'e': 'Hello {c.d}',
'f': 'Hi "{a}", am I deep enough, or need to show "{c.e}" with {b}'
}
};
// traverse the object
print(interpolation.traverse(obj, 'b'));
// output: 10
print(interpolation.traverse(obj, 'c.e'));
// output: Hello {c.d}
print(interpolation.traverse(obj, 'c.g')); // not present
// output: (empty string)
print(interpolation.traverse(obj, 'c.g', true)); // not present but keepAlive
// output: {c.g}
// resolve the object
print(interpolation.resolve(obj));
// output: {a: a, b: 10, c: {d: d, e: Hello d, f: Hi "a", am I deep enough, or need to show "Hello d" with 10}}
print(obj);
// original object is not changed
// output: {a: a, b: 10, c: {d: d, e: Hello {c.d}, f: Hi "{a}", am I deep enough, or need to show "{c.e}" with {b}}}
}
```
## Features and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
[tracker]: https://github.com/Terran-Source/dart-interpolation/issues