bluesky_text 0.2.4 bluesky_text: ^0.2.4 copied to clipboard
Provides the easiest and most powerful way to analyze the text on Bluesky Social.
Provides the easiest and most powerful way to analyze the text on Bluesky Social 🎯
1. Guide 🌎 #
Provides the easiest and most powerful way to analyze the text on Bluesky Social in Dart and Flutter apps.
Have you ever had trouble parsing mentions or links in the text you post when using Bluesky Social's API? If so, this is the library you are looking for!
Show some ❤️ and star the repo to support the project.
Also if you need more sample codes, please check examples.
1.1. Getting Started ⚡ #
1.1.1. Install Library #
With Dart:
dart pub add bluesky_text
Or With Flutter:
flutter pub add bluesky_text
1.1.2. Import #
import 'package:bluesky_text/bluesky_text.dart';
1.1.3. Implementation #
import 'package:bluesky_text/bluesky_text.dart';
void main() {
//! You just need to pass text to parse.
final text = BlueskyText(
'I speak 日本語 and English 🚀 @shinyakato.dev and @shinyakato.bsky.social. '
'Visit 🚀 https://shinyakato.dev.',
);
//! The character limit for Bluesky Social posts is 300 characters.
//! You need to split it before call some properties.
if (text.isLengthLimitExceeded) {
//! Let's split.
final texts = text.split();
for (final text in texts) {
print(text.handles);
print(text.links);
print(text.entities);
}
} else {
//! If it is less than 300 characters, it can simply be parsed.
// [{type: handle, value: @shinyakato.dev, indices: {start: 35, end: 50}},
// {type: handle, value: @shinyakato.bsky.social, indices: {start: 55, end: 78}}]
print(text.handles);
// [{type: link, value: https://shinyakato.dev, indices: {start: 91, end: 113}}]
print(text.links);
// [{type: handle, value: @shinyakato.dev, indices: {start: 35, end: 50}},
// {type: handle, value: @shinyakato.bsky.social, indices: {start: 55, end: 78}},
// {type: link, value: https://shinyakato.dev, indices: {start: 91, end: 113}}]
print(text.entities);
}
}
1.2. Tips 🏄 #
1.2.1. Instantiate #
You simply pass any text to the BlueskyText object to create an instance like following.
final text = BlueskyText(
'I speak 日本語 and English 🚀 @shinyakato.dev and @shinyakato.bsky.social. '
'Visit 🚀 https://shinyakato.dev.',
);
The length of the string passed to BlueskyText can be longer than 300 characters in grapheme. But, if there is a possibility that more than 300 characters of text will be passed, be sure to check if the character count is exceeded and split the BlueskyText using the split method as follows.
final text = BlueskyText(
'I speak 日本語 and English 🚀 @shinyakato.dev and @shinyakato.bsky.social. '
'Visit 🚀 https://shinyakato.dev.',
);
if (text.isLengthLimitExceeded) {
final texts = text.split();
for (final text in texts) {
print(text.handles);
print(text.links);
print(text.entities);
}
} else {
print(text.handles);
print(text.links);
print(text.entities);
}
1.2.2. Analyze Entities #
This package makes it easy to analyze all the entities contained in the text, such as Handles and Links.
The following methods can be used to analyze entities. The Lists returned from these methods are also
sorted in ascending order based on the value of start
in Indices
object.
Method | Description |
---|---|
handles | Extracts all handles and byte string unit Indices in the text. |
links | Extracts all links and byte string unit Indices in the text. |
entities | Extracts all handles and links and byte string unit Indices in the text. |
And it's very easy to call, just call like followings.
final text = BlueskyText(
'I speak 日本語 and English 🚀 @shinyakato.dev and @shinyakato.bsky.social. '
'Visit 🚀 https://shinyakato.dev.',
);
print(text.handles);
print(text.links);
print(text.entities);
Also, the entities
method will return a mixture of several types of entity.
In this case, the type of Entity can be easily determined as follows.
final text = BlueskyText(
'I speak 日本語 and English 🚀 @shinyakato.dev and @shinyakato.bsky.social. '
'Visit 🚀 https://shinyakato.dev.',
);
final entities = text.entities;
for (final entity in entities) {
switch (entity.type) {
case EntityType.handle:
// Do something for handle.
break;
case EntityType.link:
// Do something for link.
break;
}
}
1.2.3. With bluesky Package #
This package can be easily integrated with bluesky package.
import 'package:bluesky/bluesky.dart' as bsky;
import 'package:bluesky_text/bluesky_text.dart';
Future<void> main() async {
//! You just need to pass text to parse.
final text = BlueskyText(
'I speak 日本語 and English 🚀 @shinyakato.dev and @shinyakato.bsky.social. '
'Visit 🚀 https://shinyakato.dev.',
);
final bluesky = bsky.Bluesky.fromSession(await _session);
// Just use "toFacets".
final facets = await text.entities.toFacets();
await bluesky.feeds.createPost(
text: text.value,
// And convert to `bsky.Facet`.
facets: facets.map((e) => bsky.Facet.fromJson(e)).toList(),
);
}
Future<bsky.Session> get _session async {
final session = await bsky.createSession(
service: 'SERVICE_NAME', //! The default is `bsky.social`
identifier: 'YOUR_HANDLE_OR_EMAIL', //! Like `shinyakato.bsky.social`
password: 'YOUR_PASSWORD',
);
return session.data;
}
1.3. Contribution 🏆 #
If you would like to contribute to bluesky_text, please create an issue or create a Pull Request.
There are many ways to contribute to the OSS. For example, the following subjects can be considered:
- There are request parameters or response fields that are not implemented.
- Documentation is outdated or incomplete.
- Have a better way or idea to achieve the functionality.
- etc...
You can see more details from resources below:
Or you can create a discussion if you like.
Feel free to join this development, diverse opinions make software better!
1.4. Support ❤️ #
The simplest way to show us your support is by giving the project a star at GitHub and Pub.dev.
You can also support this project by becoming a sponsor on GitHub:
You can also show on your repository that your app is made with bluesky_text by using one of the following badges:
[![Powered by bluesky_text](https://img.shields.io/badge/Powered%20by-bluesky_text-00acee.svg)](https://github.com/myConsciousness/atproto.dart)
[![Powered by bluesky_text](https://img.shields.io/badge/Powered%20by-bluesky_text-00acee.svg?style=flat-square)](https://github.com/myConsciousness/atproto.dart)
[![Powered by bluesky_text](https://img.shields.io/badge/Powered%20by-bluesky_text-00acee.svg?style=for-the-badge)](https://github.com/myConsciousness/atproto.dart)
1.5. License 🔑 #
All resources of bluesky_text is provided under the BSD-3
license.
Copyright 2023 Shinya Kato. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided the conditions.
Note
License notices in the source are strictly validated based on.github/header-checker-lint.yml
. Please check header-checker-lint.yml for the permitted standards.
1.6. More Information 🧐 #
bluesky_text was designed and implemented by Shinya Kato (@myConsciousness).