Skip to content

Commit

Permalink
fix: add explicit return types to missing fns
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanga-Ganapathy committed Apr 6, 2024
1 parent df3ca63 commit dabd6c4
Show file tree
Hide file tree
Showing 27 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion jsr.json → packages/std/jsr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@opentf/std",
"version": "0.5.0",
"exports": "./packages/std/src/index.ts"
"exports": "./src/index.ts"
}
2 changes: 1 addition & 1 deletion packages/std/src/array/arrIns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function arrIns<T>(
arr: T[] = [],
index: number | null | undefined,
...items: T[]
) {
): T[] {
const idx = index ?? arr.length;
const a = [...arr];
a.splice(idx, 0, ...items);
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/arrReplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function arrReplace<T>(
arr: T[] = [],
index?: number | null,
...replacements: T[]
) {
): T[] {
const idx = index ?? arr.length - 1;
const a = [...arr];

Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/arrRm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function arrRm<T>(
arr: T[] = [],
index?: number,
count: number = 1
) {
): T[] {
const idx = index ?? arr.length - 1;
const a = [...arr];

Expand Down
3 changes: 2 additions & 1 deletion packages/std/src/array/bounds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { max, min } from '..';
import max from './max';
import min from './min';
import isEmpty from '../assert/isEmpty';
import compact from './compact';

Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import isArr from '../types/isArr';
*
* chunk([1, 2, 3, 4, 5], 2) //=> [[1, 2], [3, 4], [5]]
*/
export default function chunk<T>(arr: T[] = [], size = 1) {
export default function chunk<T>(arr: T[] = [], size = 1): unknown[] {
if (size < 1 || !isArr(arr)) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/countBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import isFn from '../types/isFn';
export default function countBy<T>(
arr: T[] = [],
by: ((val: T) => string) | string
) {
): { [k: string]: number } {
return arr.reduce((acc: Record<string, number>, cur: T) => {
const k = isFn(by) ? by(cur) : (cur[by as keyof T] as string);
const count = acc[k] ? acc[k] + 1 : 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import isFn from '../types/isFn';
export default function diff(
collections: unknown[][] = [],
by?: (val: unknown) => unknown
) {
): unknown[] {
const byFlag = isFn(by);
return collections.slice(1).reduce(
(acc, cur) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function drop<T>(
arr: T[],
limit: number | null = 1,
cb?: (val: T) => boolean
) {
): Partial<T[]> {
if (!isNull(limit) && (!Number.isInteger(limit) || limit < 0)) {
throw RangeError('The limit must be positive');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/intersection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import uniq from './uniq';
export default function intersection(
collections: unknown[][] = [],
by?: (val: unknown) => unknown
) {
): unknown[] {
const byFlag = isFn(by);
const out = collections.reduce((acc, cur) => {
const _intersection = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function range(
start: number,
end: number,
options?: number | { step: number; inclusive: boolean }
) {
): number[] {
if (Number.isNaN(start) || Number.isNaN(end)) {
throw new RangeError();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/symDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import uniq from './uniq';
export default function symDiff(
collections: unknown[][] = [],
by?: (val: unknown) => unknown
) {
): unknown[] {
const byFlag = isFn(by);
const out = collections.slice(1).reduce(
(acc, cur) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/take.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function take<T>(
arr: T[],
limit: number | null = 1,
cb?: (val: T) => boolean
) {
): Partial<T[]> {
if (!isNull(limit) && (!Number.isInteger(limit) || limit < 0)) {
throw RangeError('The limit must be positive');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/array/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import uniq from './uniq';
export default function union(
collections: unknown[][] = [],
by?: (val: unknown) => unknown
) {
): unknown[] {
const byFlag = isFun(by);
const out = collections.reduce((acc, cur) => {
for (const val of cur) {
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/maths/clamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
* clamp(1500, 1000, 1366) //=> 1366
*/

export default function clamp(val: number, min: number, max: number) {
export default function clamp(val: number, min: number, max: number): number {
return Math.min(Math.max(val, min), max);
}
2 changes: 1 addition & 1 deletion packages/std/src/maths/median.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import isEven from './isEven';
export default function median(
arr: number[] = [],
cb?: (val: number, index: number) => number
) {
): number {
let a = cb ? arr.map(cb) : arr;
a = sort(arr);

Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/maths/prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export default function prod(
arr: number[] = [],
cb?: (val: number, index: number) => number
) {
): number {
const a = cb ? arr.map(cb) : arr;
return a.reduce((prev, cur) => {
return prev * cur;
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/maths/sum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export default function sum(
arr: number[] = [],
cb?: (val: number, index: number) => number
) {
): number {
const a = cb ? arr.map(cb) : arr;
return a.reduce((prev, cur) => {
return prev + cur;
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/object/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type IterableObj = {
* const b = { a: { c: 2 } };
* merge(a, b); //=> {a: { b: 1, c: 2 } }
*/
export default function merge(...objs: object[]) {
export default function merge(...objs: object[]): object {
const filteredObjs = objs.filter((v) => isArr(v) || isObj(v));
const initialVal = isArr(filteredObjs[0]) ? [] : {};

Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/object/mergeAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type IterableObj = {
* const b = { a: [3, 4], b: 5 };
* mergeAll(a, b) //=> {a: [1, 2, 3, 4], b: 5}
*/
export default function mergeAll(...objs: object[]) {
export default function mergeAll(...objs: object[]): object {
const filteredObjs = objs.filter((v) => isArr(v) || isObj(v));
const initialVal = isArr(filteredObjs[0]) ? [] : {};

Expand Down
5 changes: 4 additions & 1 deletion packages/std/src/object/omit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function walk(
*
* omit({a: 1, b: 2}, 'a') //=> {b: 2}
*/
export default function omit(obj: object, ...paths: (string | unknown[])[]) {
export default function omit(
obj: object,
...paths: (string | unknown[])[]
): object {
let c = clone(obj);
const arrPathSet = new Set();

Expand Down
5 changes: 4 additions & 1 deletion packages/std/src/object/pick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import toPath from './toPath';
*
* pick({a: 1, b: 2}, 'a') //=> {a: 1}
*/
export default function pick(obj: object, ...paths: (string | unknown[])[]) {
export default function pick(
obj: object,
...paths: (string | unknown[])[]
): object {
const outObj = isArr(obj) ? [] : {};

for (const path of paths) {
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/object/shallowMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import isArr from '../types/isArr';
* const b = { b: 2 };
* shallowMerge(a, b); //=> { a: 1, b: 2 }
*/
export default function shallowMerge(...objs: object[]) {
export default function shallowMerge(...objs: object[]): object {
return objs.reduce((acc, cur) => {
if (isArr(cur) && isArr(acc)) {
return Object.assign([], acc, cur);
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/object/shallowMergeAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import isArr from '../types/isArr';
* const c = [3];
* shallowMergeAll(a, b, c); //=> [1, 2, 3]
*/
export default function shallowMergeAll(...objs: object[]) {
export default function shallowMergeAll(...objs: object[]): object {
return objs.reduce((acc, cur) => {
if (isArr(cur) && isArr(acc)) {
return [...acc, ...cur];
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/object/toPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import isSym from '../types/isSym';
* @example
* toPath('a.b.c') //=> ['a', 'b', 'c']
*/
export default function toPath(val: string | unknown | unknown[]) {
export default function toPath(val: string | unknown | unknown[]): unknown[] {
if (isStr(val)) {
const res = [];
const regex = /\[(\d+)\]|\[(-?\d+\.?\d+)\]|([^.[\]]+)/g;
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/string/strReplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function strReplace(
pattern: string | RegExp,
replacement: string,
options: StrReplaceOptions
) {
): string {
const defaultOptions: StrReplaceOptions = { all: false, case: false };
const opts = shallowMerge(defaultOptions, options) as StrReplaceOptions;
let flags = '';
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/types/isJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import isObj from './isObj';
* isJSON("{}") //=> true
*/

export default function isJSON(str: string) {
export default function isJSON(str: string): boolean {
try {
const o = JSON.parse(str);
return isObj(o);
Expand Down

0 comments on commit dabd6c4

Please sign in to comment.