Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drafakiller/carvable-dart
Allows you to remove and change parts of something, without modifying the original, builder-like. Carve objects such as Strings and AstNodes, or implement the generic interface.
https://github.com/drafakiller/carvable-dart
builder dart package
Last synced: 25 days ago
JSON representation
Allows you to remove and change parts of something, without modifying the original, builder-like. Carve objects such as Strings and AstNodes, or implement the generic interface.
- Host: GitHub
- URL: https://github.com/drafakiller/carvable-dart
- Owner: DrafaKiller
- License: mit
- Created: 2023-01-09T11:03:33.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-12T15:30:27.000Z (almost 2 years ago)
- Last Synced: 2023-08-09T13:59:21.784Z (over 1 year ago)
- Topics: builder, dart, package
- Language: Dart
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Pub.dev package](https://img.shields.io/badge/pub.dev-carvable-blue)](https://pub.dev/packages/carvable)
[![GitHub repository](https://img.shields.io/badge/GitHub-Carvable--dart-blue?logo=github)](https://github.com/DrafaKiller/Carvable-dart)# Carvable
Allows you to remove and change parts of something, without modifying the original, builder-like.
The carvable object returns a result with the changes applied.With this, it's possible to hide sections of a string that would be created by objects.
For instance, hiding child nodes inside AstNode.```dart
final AstNode node;
print( node.remove(node.childEntities.elementAt(0)).apply() );
```The position of the child could change at any time, and it would still hide the correct section in the string.
## Features
- Carvable generic interface
- Carvable String
- Carvable Analyzer objects, such as AstNode, Element and LibraryElement## Getting Started
```
dart pub add carvable
```And import the package:
```dart
import 'package:carvable/carvable.dart';
```## Usage
Get the carvable object of a String.
```dart
final CarvableString carvable = 'abcd'.carvable;
```You may add carving zones, such as a carving range:
```dart
carvable.remove(1, 3);
```The range is inclusive in the first value and exclusive in the second value.
After carving all zones, you can apply to get the result:
```dart
print(carvable.apply()); // 'ad'
```### Carvable
Carvable objects are objects which receive carvings to be used to delimit how the result will be modified, builder-like.
This object may accept any carving type, but might not apply all of them, depending on the Carvable implementation.
After adding the carvings you may apply those to get the result.
```dart
class CarvableStringExample extends Carvable> {
final String input = 'abcd';@override
String apply() => carvings.fold(input, (value, element) => element.apply(value));
}
```### Carvings
Carvings are data structures with the information needed to carve a part of the object.
They can also carve themselves into an object, using the `apply()` method.They have an input type, and a result type. Those delimit what the carving will do to the object, and what objects accept.
For instance, a string carving will have an input and result of String, and that way can be chained.```dart
class CarvingRemove extends Carving {
final int start;
final int end;CarvingRemove(this.start, this.end);
@override
String apply(String input) => input.replaceRange(start, end, '');
}
```## Example
Carvable String
(/example/main.dart)
```dart
import 'package:carvable/carvable.dart';void main() {
final carvable = CarvableString('abcd');
carvable.remove(1, 2);
print(carvable.apply()); // 'acd'print('abcde'.carvable.remove(1, 2).remove(3, 4).apply()); // 'ace'
print('abd'.carvable.remove(2, 3).append('c').apply()); // 'abc'
}```
## Contributing
Contributions are welcome! Please open an [issue](https://github.com/DrafaKiller/Carvable-dart/issues) or [pull request](https://github.com/DrafaKiller/Carvable-dart/pulls) if you find a bug or have a feature request.