패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.5

num_utilities

숫자, 정수 및 더블에 대한 확장 메서드 모음; 그리고 숫자, 정수 및 더블의 반복 가능한 컬렉션입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
3.2천
좋아요
2
Pub 점수
150

패키지 설치

flutter pub add num_utilities

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

num_utilities는 숫자 유형(int, double)과 그 반복 가능한 요소에 유용한 확장 메서드를 제공하는 Dart 패키지입니다. 수학 연산, 변환, 데이터 조작을 위한 편리한 유틸리티를 제공하여 코드의 가독성을 높이고 반복적인 코드를 줄여줍니다. 이 패키지는 가볍고 모든 주요 플랫폼에서 Flutter 및 Dart 프로젝트에 원활하게 통합될 수 있도록 설계되었습니다. 계산이나 통계 처리가 필요한 앱에서 수치 데이터를 다루는 개발자에게 이상적입니다.

사용 사례

  • 숫자 목록에 대한 배치 수학 연산 수행
  • 숫자 유형 변환 간소화
  • 산술 표현식의 가독성 향상
  • 수치 계산에서 경계 사례 처리
  • 컬렉션에서 통계 함수 구현
  • 데이터 전처리 간소화

주요 기능

  • int 및 double의 확장 메서드
  • 숫자 컬렉션을 위한 Iterable 지원
  • 클린하고 체인 가능한 구문
  • 크로스 플랫폼 호환성
  • 최소 종속성
  • pub add를 통한 간편한 통합

적합한 대상

  • 수학 보조 도구가 필요한 플러터 개발자
  • 모바일 및 웹 앱에서의 데이터 처리
  • 수치 분석을 포함하는 프로젝트
  • 클린하고 가독성 높은 코드를 우선시하는 팀
  • 교육용 또는 프로토타입 애플리케이션

고려 사항

  • 숫자 유형만 제한됨
  • 극단적인 값에 대한 내장된 오류 처리 없음
  • 대규모 수치 계산에 최적화되지 않음
  • 경계 사례에 대한 수동 테스트가 필요합니다
  • 'math_expressions'와 같은 완전한 수학 라이브러리를 대체하지 않습니다
  • 간단한부터 중간 수준의 수치 작업에 가장 적합

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

num_utilities

A collection of extension methods for [num]s, [int]s, and [double]s; and iterables of [num]s, [int]s, and [double]s.

See: list_utilities

Usage

import 'package:num_utilities/num_utilities.dart';

Numbers

[num]s, [int]s, and [double]s were extended with the following methods/getters:

isPositive

[isPositive] returns true if the number's sign is positive.

final numA = 5;
print(numA.isPositive); // true

final numB = -5;
print(numB.isPositive); // false
equals

[equals] is equivalent to the == operator, but has an optional parameter to round the numbers before comparing them, by calling [roundTo] (see below.)

final numA = 5.556;
final numB = 5.557;
print(numA.equals(numB)); // false
print(numA.equals(numB, 100)); // true
isWithin

[isWithin] returns true if the number matches or is within the range of any of the parts defined in the provided [expression].

The provided [expression] must be a string of numbers and/or ranges separated by commas.

final value = 7;
print(value.isWithin('0,2,4,6')); // false
print(value.isWithin('1,2,6-8,10')); // true
print(value.isWithin('0-4,7,12-15')); // true
isWithinRange

[isWithinRange] returns true if this number is within the range of the provided [start] and [end] values.

final value = 7;
print(value.isWithinRange(4, 8)); // true
print(value.isWithinRange(8, 4)); // true
print(value.isWithinRange(2, 6)); // false
roundTo

[roundTo] rounds the number by the value: (number * value).round() / value

final number = 5.556;
print(number.roundTo(10)); // 5.6
roundToPrecision

[roundToPrecision] rounds the number to the specified number of decimal points.

final number = 5.5567893;
print(number.roundToPrecision(3)); // 5.557

Iterables

Iterables of [num]s, [int]s, and [double]s were extended with the following methods:

sum

The [sum] method returns the sum of all of the values in the iterable.

final list = [1, 2, 3, 4, 5];
print(list.sum()); // 15
absSum

The [absSum] method returns the sum of all of the absolute values in the iterable.

[absSum] has an optional parameter to invert the returned value.

final list = [1, -2, 3, -4, 5];
print(list.absSum()); // 15
print(list.absSum(false)); // 15
print(list.absSum(true)); // -15
print(list.sum()); // 3
highest

The [highest] getter returns the highest value in the iterable.

final list = [1, 2, 3, 4, 5];
print(list.highest); // 5
lowest

The [lowest] getter returns the lowest value in the iterable.

final list = [1, 2, 3, 4, 5];
print(list.lowest); // 1

Range

The [Range] object defines a range of numbers between specified [min] and [max] values, and has convienence methods for generating numbers within the range and for interpolating values within the range.

final range = Range(5, 15);
print(range.min); // 5
print(range.max); // 15

span

The [span] getter returns the difference between the [min] and [max] values.

print(range.span); // 10

random

The [random] method will output a number between the [min] value, inclusive, and the [max] value, exclusive.

[random] accepts an optional [seed] value.

print(range.random());
print(range.random(seed));

secureRandom

The [secureRandom] method will output a cryptographically secure number between the [min] value, inclusive, and [max] value, exclusive.

print(range.secureRandom());

interpolate

The [interpolate] method returns a [List] of numbers spanning a defined number of [steps] between the [min] and [max] values.

print(range.interpolate(5)); // [5.0, 7.0, 9.0, 11.0, 13.0]
inclusive

[interpolate]'s inclusive parameter can be used to include the [max] number within the output [List].

print(range.interpolate(5, inclusive: true)); // [5.0, 7.0, 9.0, 11.0, 13.0, 15.0]
randomize

[interpolate]'s randomize parameter can be used to apply randomness to the output numbers, where a value of 0.0 doesn't apply any randomness to the numbers, while a value of 1.0 will randomize the output numbers within the entire range of the radius around each step.

print(range.interpolate(5, randomize: 1.0)); // [5.23, 6.18, 8.27, 10.27, 13.46]

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.