Skip to content
Merged
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
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

5 changes: 0 additions & 5 deletions .eslintrc.yml

This file was deleted.

5 changes: 3 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ jobs:
# Documentation: https://github.com/zakodium/workflows#nodejs-ci
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
with:
node-version-matrix: '[12, 14, 16]'
npm-setup-command: 'npm install && npm run prepare && npm run build'
lint-check-types: true
disable-test-package: true # Monorepo, root not publishable

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@ typings/
.env

.idea

# Lib (ts) artifacts

/packages/*/lib/
/packages/*/lib-es6/
/packages/*/*.tsbuildinfo
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CHANGELOG.md
coverage
lib
docs
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Functional utilities to transform and compute stats on arrays
## Packages

| Name | Description |
|--------------------------------------------------------------------|------------------------------------------------|
| ------------------------------------------------------------------ | ---------------------------------------------- |
| [ml-array-sequential-fill](./packages/array-sequential-fill) | Fill / create an array with sequential numbers |
| [ml-array-min](./packages/array-min) | Get the minimum value in an array |
| [ml-array-max](./packages/array-max) | Get the maximum value in an array |
Expand Down
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

52 changes: 52 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { defineConfig, globalIgnores } from 'eslint/config';
import ts from 'eslint-config-cheminfo-typescript/base';
import unicorn from 'eslint-config-cheminfo-typescript/unicorn';
import vitest from 'eslint-config-cheminfo-typescript/vitest';

export default defineConfig(
globalIgnores([
'**/coverage',
'**/lib',
'**/lib-internal',
'**/docs',
'**/CHANGELOG.md',
'/src/',
]),
ts,
unicorn,
vitest,
createNoExtraneousConfigs(),
{
// it uses an old `median-quickselect` package, which does not have types,
// so triple-slash-reference is used to declare `median-quickselect` module.
files: ['packages/array-median/src/index.ts'],
rules: {
'@typescript-eslint/triple-slash-reference': 'off',
},
},
);

function createNoExtraneousConfigs() {
const configs = [];
for (const pkg of fs.readdirSync('packages')) {
configs.push({
files: [`packages/${pkg}/**`],
rules: {
'import/no-extraneous-dependencies': [
'error',
{
packageDir: [
fileURLToPath(new URL(`packages/${pkg}`, import.meta.url)),
path.dirname(fileURLToPath(import.meta.url)),
],
},
],
},
});
}
return configs;
}
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"conventionalCommits": true,
"packages": ["packages/*"],
"command": {
Expand Down
56 changes: 30 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
{
"private": true,
"name": "ml-array-utils",
"main": "lib/index.js",
"module": "src/index.js",
"private": true,
"version": "1.0.0",
"description": "Functional utilities to transform and compute stats on arrays",
"type": "module",
"workspaces": [
"packages/*"
],
"scripts": {
"bootstrap": "lerna bootstrap --no-ci",
"build": "npm run build-clean && lerna exec -- rollup -c ../../rollup.config.js",
"build-clean": "rimraf ./packages/*/lib/ && rimraf ./packages/*/lib-es6/",
"eslint": "eslint packages/**/*.js --cache",
"build": "npm run build-clean && npm run tsc",
"build-clean": "rimraf packages/*/lib packages/*/*.tsbuildinfo",
"check-types": "tsc --noEmit",
"coverage-clean": "rimraf coverage",
"eslint": "eslint . --cache",
"eslint-fix": "npm run eslint -- --fix",
"prepare": "npm run bootstrap",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"publish": "git pull --rebase && npm run build && npm run test-publish && lerna publish",
"test": "run-s build test-only eslint prettier",
"test-watch": "jest --watch",
"test-publish": "run-s test-only eslint",
"test-only": "jest --coverage"
"full-clean": "npm run build-clean && npm run coverage-clean && npm run install-clean",
"install-clean": "rimraf node_modules packages/*/node_modules",
"prettier": "prettier --check .",
"prettier-write": "prettier --write .",
"publish": "npm run test && npm run build && npm run test && lerna publish -y --no-verify-access",
"test": "npm run test-only && tsc --noEmit && npm run eslint && npm run prettier",
"test-only": "vitest --run --coverage",
"tsc": "tsc --build",
"tsc-watch": "tsc --build --watch"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.16.8",
"@babel/preset-env": "^7.16.11",
"@rollup/plugin-babel": "^5.3.1",
"eslint": "^8.10.0",
"eslint-config-cheminfo": "^7.2.2",
"jest": "^27.5.1",
"lerna": "^4.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"rimraf": "^3.0.2",
"rollup": "^2.68.0"
"@types/node": "^25.6.0",
"@vitest/coverage-v8": "^4.1.4",
"@zakodium/tsconfig": "^1.0.5",
"eslint": "^9.39.4",
"eslint-config-cheminfo-typescript": "^21.2.0",
"lerna": "^9.0.5",
"prettier": "^3.8.2",
"rimraf": "^6.1.3",
"typescript": "^6.0.2",
"vitest": "^4.1.4"
}
}
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
16 changes: 9 additions & 7 deletions packages/array-max/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"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": {
".": {
"ml-array-internal": "./src/index.ts",
"default": "./lib/index.js"
}
},
"files": [
"lib",
"lib-es6",
"src",
"types.d.ts"
"src"
],
"repository": {
"type": "git",
Expand All @@ -23,6 +25,6 @@
},
"homepage": "https://github.com/mljs/array/tree/master/packages/array-max#readme",
"dependencies": {
"is-any-array": "^2.0.0"
"is-any-array": "^3.0.0"
}
}
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,16 @@ 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 ArrayMaxOptions {
/**
* 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 max(
input: ArrayLike<number>,
options: ArrayMaxOptions = {},
): number {
if (!isAnyArray(input)) {
throw new TypeError('input must be an array');
}
Expand Down
8 changes: 8 additions & 0 deletions packages/array-max/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": true
},
"include": ["src"],
"exclude": ["**/*.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 @@
{
"files": [],
"compilerOptions": {
"composite": true
},
"references": [
{ "path": "./tsconfig.build.json" },
{ "path": "./tsconfig.test.json" }
]
}
7 changes: 7 additions & 0 deletions packages/array-max/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.build.json",
"exclude": [],
"compilerOptions": {
"noEmit": true
}
}
22 changes: 0 additions & 22 deletions packages/array-max/types.d.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/array-mean/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# array-mean

[![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 average value in an array.

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

## License

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

[npm-image]: https://img.shields.io/npm/v/ml-array-mean.svg?style=flat-square
[npm-url]: https://npmjs.org/package/ml-array-mean
Expand Down
14 changes: 8 additions & 6 deletions packages/array-mean/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"name": "ml-array-mean",
"version": "1.1.6",
"description": "Get the average value in an array",
"main": "lib/index.js",
"module": "lib-es6/index.js",
"types": "types.d.ts",
"type": "module",
"exports": {
".": {
"ml-array-internal": "./src/index.ts",
"default": "./lib/index.js"
}
},
"files": [
"lib",
"lib-es6",
"src",
"types.d.ts"
"src"
],
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import mean from '..';
import { describe, expect, it } from 'vitest';

import mean from '../index.ts';

describe('array-mean', () => {
let typedArray = new Uint16Array(3);
const typedArray = new Uint16Array(3);
typedArray[0] = 1;
typedArray[1] = 2;
typedArray[2] = 3;
Expand All @@ -16,6 +18,7 @@ describe('array-mean', () => {
});

it('should throw on invalid value', () => {
// @ts-expect-error ensure implementation catch missing input
expect(() => mean()).toThrow(/input must be an array/);
expect(() => mean([])).toThrow(/input must not be empty/);
});
Expand Down
Loading
Loading