Coder Social home page Coder Social logo

speed_up's Introduction

speed_up

pub package likes codecov style: lint Dart

Package to speed up your productivity.

Usage

Object

someObj.isNull;
someObj.isNotNull;

String extensions

Check String is null or empty

'Some String'.isNullOrEmpty
'Some String'.isNotNullOrEmpty

Capitalization

'flutter'.capitalized; // 'Flutter'

'flutter is awesome'.titleCased; // 'Flutter Is Awesome'

Equality

str1.isEqualTo(str2);
str1.isEqualTo(str2, ignoreCase: true);

Collection extension

 final sum = [1, 2, 3].sum(); // 6

 final sum = [Product(price: 100.99), Product(price: 49.99)].sum((p) => p.price);
final ordered = orders.orderBy((x) => x.amount, desc: true);
final groups = people.groupBy((p) => p.age, map: (p) => p.name);

mapWithIndex

const arr = [1, 2, 3];
final arr2 =
    arr.mapWithIndex((index, item, isFirst, isLast) => '$index - $item');
print(arr2); // ['0 - 1', '1- 2', '2 -3']

Next After

Random

replaceWhere

// Given array
const arr = [1, 2, 3];

// replace by index
final newArray = arr.replaceWhere((index, _) => index == 1, withNewItem: 13);
newArray.should.be([1, 13 ,3]);

// or replace by prop
final newArray = arr.replaceWhere((_, number) => number.isOdd, withNewItem: 13);
newArray.should.be([ 13, 2, 13]);

Reorder list

const list = [1, 2, 3, 4, 5];

list.reorderByIndexes(oldIndex: 1, newIndex: 0);  // [2, 1, 3, 4, 5]
list.reorder(5, newIndex: 0).toList();          // [5, 1, 2, 3, 4]

split_on_pages_by_count

test('split_on_pages_by_count - full pages', () {
  final pages = arr.splitOnPagesBy(2).toList();
  pages.length.should.be(5);
  for (final page in pages) {
    page.length.should.be(2);
  }
});

intersperse

Puts [element] between every element in list.

Example:

final list1 = intersperse(2, <int>[]); // [];
final list2 = intersperse(2, [0]); // [0];
final list3 = intersperse(2, [0, 0]); // [0, 2, 0];

Get image file size

const fileSize = 1024 * 1024;

// Get file size in closest size suffix
final sizeInMb = FileSizeInfo.getSize(bytes);
log(sizeInKb.getTitle())); // prints '1.oo MB'
log(sizeInKb.getTitle(decimals: 0))); // prints '1 MB'

// Convert to desired suffix
final sizeInKb = sizeInMb.asSuffix(FileSizeSuffix.KB);
log(sizeInKb.getTitle())); // prints '1024 KB'

log();

RangeValue type

final numRange = RangeValue(1, 10);
print(numRange.isValid); // true

final start = DateTime.now();
final end = DateTime.now().add(Duration(days: 1));
final dateTimeRange = RangeValue(end, start);

print(dateTimeRange.isValid); // false

Debouncer

Declare it

final debounce = Debounce(delay: const Duration(milliseconds: 100));

and trigger it

onTextChange(String text) {
  _debounce(() => print(text));
}

Contributing

We accept the following contributions:

Maintainers

Buy Me A Coffee

speed_up's People

Contributors

andrewpiterov avatar

Stargazers

 avatar

Watchers

 avatar

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.