Giter Site home page Giter Site logo

birjuvachhani / screwdriver Goto Github PK

View Code? Open in Web Editor NEW
30.0 3.0 5.0 4.91 MB

A dart package aiming to provide useful extensions and helper functions to ease and speed up development.

Home Page: https://pub.dev/packages/screwdriver

License: BSD 3-Clause "New" or "Revised" License

Dart 100.00%
dart dartlang dart2 dart-library dart-package helper extensions extension-methods extension-pack pubdev

screwdriver's Introduction

banner

Screwdriver

A dart package aiming to provide useful extensions and helper functions to ease and speed up development.

Tests Code Quality Codecov Pub Version Docs

  • ๐Ÿ“‹ Well Documented
  • โš”๏ธ Fully Tested
  • ๐Ÿ‘Œ Follows Code Quality Guidelines
  • ๐Ÿฆพ Production Ready
  • collection included for extra extensions.

Stats

Check out EXTENSIONS.md for a complete list of all the available extensions.

Extensions:                    238
Helper Classes:                5
Helper Functions & Getters:    21
Typedefs:                      8
Mixins:                        2

Last Updated: Mon, Jun 17, 2024 - 12:36 PM

Stats auto generated using Github Workflow.


To checkout all the available extensions, helper functions & classes, see documentation.

Installation

  1. Add as a dependency in your project's pub spec.yaml.
dependencies:
  screwdriver: <latest_version>

Note: Screwdriver exports collection package as well. So, you don't need to add collection as a dependency in your project.

  1. Import library into your code.
import 'package:screwdriver/screwdriver.dart';
  1. Use this import for using IO extensions.
import 'package:screwdriver/screwdriver_io.dart';

A Glimpse of Screwdriver

String

'hello'.capitalized; // Hello
'   '.isBlankl // true;
'45'.toIntOrNull(); // 45
'html'.wrap('<','>'); // <html>
'1010111010001'.isBinary; // true
'[email protected]'.isEmail; // true
'abcd'.reversed; // dcba
'This is a test'.words; // ['this', 'is', 'a', 'test']
'{"name":"John"}'.parseJson(); // map: {name:John}
'#hello'.removePrefix('#'); // hello

Map

final Map<String, dynamic> map = {
  'name': 'John',
  'age': 24,
};

for(final (key, value) in map.records) {
  print('$key: $value');
}

Int

20.isDivisibleBy(5); // true
0.asBool; // false
6.twoDigits; // '06'
2020.isLeapYear; // true
10.repeat((count) => print(count));

DateTime & Duration

now().isMonday;
final DateTime fiveDaysAgo = 5.daysAgo;
final Duration nineMinutes = 9.minutes;
45.minutes.isInHours; // false
15.daysAgo < 5.days.ago; // true
20.minutes.ago >= 50.minutes.ago; // true
now().previousDay; // yesterday
10.days.ago.isBetween(15.days.ago, now()); // true

Double and Bool

randomDouble(max: 50); // random double value between 0 and 50
56.0.isWhole; // true
true.toggled; // false
false.toInt(); // 0

Scope Functions

final User user = User(name: 'John').apply((user){
  user.age = 24;
  user.email = '[email protected]';
});
final String age = user.run((u)=> (u.age + 20).toString());

Collections

users << User(name: 'John'); // appends user to users list
users.firstOrNull;
users.drop(5);
users.takeLast(3);
user.all((u) => u.age > 18); // returns bool
cars.groupBy((car) => car.color);
cars.count((car) => car.isPorsche);
cars.random();
cars.maxBy((car) => car.price);
cars.intersect(otherCars);
{'name': 'John'} << Pair('email','[email protected]');

Future

postDelayed(2000,(){
  print('after 2 seconds');
});

IO

file.onModified(() => print('file modified'));
file.clear(); // flushes all the data of file
file.isEmpty;
file.appendString('hello');
file << 'some text';
file1 + file2; // appends file2 content at the end of file1

Some More

check(divider != 0);
runCaching((){
  count / 0;
});
TODO('find a way to implement this properly'); // throws UnimplementedError on invocation
Triple(45,true, 'Hello World');
user.takeIf((u) => u.age > 18)?.allowAccess();
person.takeUnless((p) => p > 18)?.areTeenagers();
final DateTime date = tomorrow;
yesterday.isInDecember;

Check out EXTENSIONS.md for a complete list of all the available extensions.

Checkout documentation for more details.

Features and bugs

Please file feature requests and bugs at the issue tracker.

Liked Screwdriver?

Show some love and support by starring the repository.

Or You can

Buy Me A Coffee

License

Copyright (c) 2020, Birju Vachhani
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

screwdriver's People

Contributors

birjuvachhani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

screwdriver's Issues

Null and empty checks for Strings and collections

Hey,
Very nice package!

Would be awesome to have a way to check if a string or a collection are null or empty.
Strings:

'123'.isNullOrWhiteSpace // returns false
''.isNullOrEmpty // return true

Collections:

List<String> words = null;
words.isNullOrEmpty // return true
words = ['123'];
words.isNullOrEmpty // returns false

I know dart have an isEmpty or isNotEmpty fields but you also need to check for nulls which is kind of annoying to deal with.
I hope you will consider adding this to your package.
Thanks a lot!

Null safety

Hi I saw your commits about null safe but you didn't publish them to pub.dev.
Please update the package to support null safety.
Thanks

Error: Can't compile for web

Describe the bug
Can't compile for web.

Error: The integer literal 9223372036854775807 can't be represented exactly in JavaScript.
const int MAX_INT_VALUE = 9223372036854775807;

To Reproduce
Steps to reproduce the behavior:

  1. Try to compile while using the package

Expected behavior
Should compile without errors.

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.