Git Product home page Git Product logo

stringr's Introduction

stringr 🧵

String manipulation in dart/flutter on steroids! ⚡⚡ This dart plugin is null safety compliant 😎😎

codecov codemagic License: MIT

This dart plugin is inspired 🧠 by Voca js library. This plugin includes all the nifty functions required for powerful string manipulations.

How powerful? Glad you asked!!

This plugin works on both latin and non latin strings, and uses complex regular expressions to extract words from strings on manipulations, rather than just calling split(" ") on a string.

import 'package:stringr/stringr.dart';

void main(){
 print("camel case".camelCase()); // Output - "camelCase"
 print("HTMLview".camelCase(preserveAcronym=true)); // Output - "HTMLView"
 print("/this/is/a/directory".camelCase()); // Output - "thisIsADirectory"
 print("полет птицы".kebabCase()); // Output - "полет_птицы"
 print("La variété la plus fréquente est la blanche".prune(12)); // Output - La variété
print("2infinity*@#@AND93beyond".words()); // Output - ["2", "infinity", "AND", "93", "beyond"]
 print("gravity".words(pattern: r"\w{1,2}")); // Output - ['gr', 'av', 'it', 'y']
}
 

Convert a string to its latin counterpart! Can reverse not only pure strings, but strings with grapheme clusters as well😎

import 'package:stringr/stringr.dart';

void main(){
print("cafe\u0301".latinize()); // Output - cafe
print("anglikonų šiurkščios užrašinėti".latinize());// Output - 'anglikonu siurkscios uzrasineti'
print("𝌆 bar mañana mañana".reverse()); // Output - 'anañam anañam rab 𝌆'
// Splitting and reversing normally would give this as output
// anãnam anañam rab ��
}
 

Support for graphemes is also included in this plugin. characters plugin is used to facilitate some of the functionalities.

import 'package:stringr/stringr.dart';

void main(){
 print("cafe\u0301".countGrapheme()); // Output - 4
 print("\uD835\uDC00\uD835\uDC01".countGrapheme()); // Output - 2
 print("\uD835\uDC00\uD835\uDC01".graphemeAt(1)); // Output - "\uD835\uDC01"
print("stellar bomb".codePoints()); // Output - [0x73, 0x74, 0x65, 0x6c, 0x6c, 0x61, 0x72, 0x20, 0x62, 0x6f, 0x6d, 0x62]
 print('man\u0303ana'.graphemes()); // Output - ['m','a', 'n\u0303', 'a', 'n', 'a']
}
 

HTML strings can be escaped!

import 'package:stringr/stringr.dart';

void main(){
print('<>&"\'`'.escapeHTML()); // Output - '&lt;&gt;&amp;&quot;&#x27;&#x60;'
print('<p>wonderful world</p>'.escapeHTML());// Output - '&lt;p&gt;wonderful world&lt;/p&gt;'
}
 

You can count on stringr to count the words, latin, non latin, or strings with grapheme clusters!

import 'package:stringr/stringr.dart';

void main(){
print("a year without rain".count()); // Output - 19
print("foo\uD834\uDF06\u0303\u035C\u035D\u035Ebar".countGrapheme());// Output - 7
print("to be or not to be".countOccurences("to")); // Output - 2
print("aBCdeFgH".countWhere((character) => character.isAlphabet())); // Output - 8
print("NewYork".countWords()); // Output - 2
}
 
  • Some of the functionalities, like char() and codePoints are either simple enough to implement or were available in the characters package. But still I decided to add them to make bundle everything under a similar syntax ( i.e- calling the extension functions on string).
  • For functions like padLeft() and trim() which already are extension functions and inbuilt in dart, I have not included them in this plugin as the syntax would be similar to that of this plugin.

stringr's People

Contributors

chinmay-kb avatar colt005 avatar

Stargazers

Norman Tomalon avatar  avatar  avatar Andy Chentsov avatar Graciliano Monteiro Passos avatar Smarak Das avatar

Watchers

James Cloos avatar Graciliano Monteiro Passos avatar  avatar

Forkers

colt005 gumbarros

stringr's Issues

Need a way to unescape regexp

Currently there is a function to escape a regex string

'500-200'.escapeRegExp() returns --> r"500\-200"

Similarly, add a new function unEscapeRegExp() that will un-escape the regex and return it as a regular string.

'r"500\\-200"'.unEscapeRegExp() should return --> '500-200'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.