Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/array-max/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CHANGELOG.md
coverage
lib
6 changes: 3 additions & 3 deletions packages/array-max/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# array-max

[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]
[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]

Get the maximum value in an array.

Expand All @@ -20,7 +20,7 @@ const result = max([1, 5, 3, 2, 4]);

## License

[MIT](./LICENSE)
[MIT](./LICENSE)

[npm-image]: https://img.shields.io/npm/v/ml-array-max.svg?style=flat-square
[npm-url]: https://npmjs.org/package/ml-array-max
Expand Down
4 changes: 4 additions & 0 deletions packages/array-max/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig, globalIgnores } from 'eslint/config';
import ts from 'eslint-config-cheminfo-typescript/base';

export default defineConfig(globalIgnores(['coverage', 'lib']), ts);
31 changes: 26 additions & 5 deletions packages/array-max/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"name": "ml-array-max",
"version": "1.2.4",
"description": "Get the maximum value in an array",
"main": "lib/index.js",
"module": "lib-es6/index.js",
"types": "types.d.ts",
"type": "module",
"exports": {
".": "./lib/index.js"
},
"types": "./types.d.ts",
"files": [
"lib",
"lib-es6",
"src",
"types.d.ts"
],
Expand All @@ -22,7 +23,27 @@
"url": "https://github.com/mljs/array/issues"
},
"homepage": "https://github.com/mljs/array/tree/master/packages/array-max#readme",
"scripts": {
"check-types": "tsc --noEmit",
"clean": "rimraf coverage lib",
"eslint": "eslint . --cache",
"eslint-fix": "npm run eslint -- --fix",
"prepack": "npm run tsc",
"prettier": "prettier --check .",
"prettier-write": "prettier --write .",
"test": "npm run test-only && npm run check-types && npm run eslint && npm run prettier",
"test-only": "vitest run --coverage",
"tsc": "npm run clean && npm run tsc-build",
"tsc-build": "tsc --project tsconfig.build.json"
},
"dependencies": {
"is-any-array": "^2.0.0"
"is-any-array": "^3.0.0"
},
"devDependencies": {
"@vitest/coverage-v8": "^4.1.4",
"@zakodium/tsconfig": "^1.0.5",
"eslint-config-cheminfo-typescript": "^21.2.0",
"typescript": "^6.0.2",
"vitest": "^4.1.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import max from '..';
import { describe, expect, it } from 'vitest';

describe('array-max', () => {
let typedArray = new Uint16Array(3);
typedArray[0] = 1;
typedArray[1] = 2;
typedArray[2] = 3;
import max from '../index.ts';

describe('array-max', () => {
it('should return the max', () => {
expect(max([0])).toBe(0);
expect(max([1])).toBe(1);
Expand All @@ -17,11 +14,15 @@ describe('array-max', () => {
expect(max([3, 2, 1], { fromIndex: 1, toIndex: 3 })).toBe(2);
expect(max([3, 2, 1], { fromIndex: 0, toIndex: 2 })).toBe(3);
expect(max([3, 2, 1], { fromIndex: 2, toIndex: 3 })).toBe(1);

const typedArray = Uint16Array.of(1, 2, 3);

expect(max(typedArray)).toBe(3);
expect(max(typedArray, { fromIndex: 0, toIndex: 2 })).toBe(2);
expect(max(typedArray, { fromIndex: 0, toIndex: 3 })).toBe(3);
});
it('should throw on invalid value', () => {
// @ts-expect-error ensure implementation catch missing input
expect(() => max()).toThrow(/input must be an array/);
expect(() => max([])).toThrow(/input must not be empty/);
expect(() => max([1, 2, 3], { fromIndex: -1, toIndex: 2 })).toThrow(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
import { isAnyArray } from 'is-any-array';

export default function max(input, options = {}) {
export interface MlArrayMaxOptions {
/**
* Start index (inclusive) for the slice within which we look for the maximum.
* @default 0
*/
fromIndex?: number;

/**
* End index (exclusive) for the slice within which we look for the maximum.
* @default input.length
*/
toIndex?: number;
}

/**
* Computes the maximum of the given values.
*
* @param input
* @param options
*/
export default function mlArrayMax(
input: ArrayLike<number>,
options: MlArrayMaxOptions = {},
): number {
if (!isAnyArray(input)) {
throw new TypeError('input must be an array');
}
Expand Down
6 changes: 6 additions & 0 deletions packages/array-max/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": { "rootDir": "src" },
"include": ["src"],
"exclude": ["**/__tests__", "**/*.test.*"]
}
10 changes: 10 additions & 0 deletions packages/array-max/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@zakodium/tsconfig",
"compilerOptions": {
"rootDir": ".",
"noUncheckedIndexedAccess": false,
"outDir": "lib",
"types": ["node"]
},
"include": ["src", "vite*.ts"]
}
22 changes: 0 additions & 22 deletions packages/array-max/types.d.ts

This file was deleted.

9 changes: 9 additions & 0 deletions packages/array-max/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
coverage: {
include: ['src/**/*.ts'],
},
},
});
Loading