diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 0e20de0..0000000 --- a/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -packages/*/node_modules -packages/*/docs -packages/*/lib -packages/*/lib-es6 diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index b1ff0f6..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,5 +0,0 @@ -root: true -extends: - - cheminfo -parserOptions: - sourceType: module diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 0bd20be..b1939df 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -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 + diff --git a/.gitignore b/.gitignore index a7590e2..6d05c9c 100644 --- a/.gitignore +++ b/.gitignore @@ -58,5 +58,8 @@ typings/ .env .idea + +# Lib (ts) artifacts + /packages/*/lib/ -/packages/*/lib-es6/ +/packages/*/*.tsbuildinfo diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..d443d86 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +CHANGELOG.md +coverage +lib +docs diff --git a/README.md b/README.md index 805f00f..c2227ce 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index 18b6e17..0000000 --- a/babel.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - plugins: ['@babel/plugin-transform-modules-commonjs'], -}; diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..114fee8 --- /dev/null +++ b/eslint.config.js @@ -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; +} diff --git a/lerna.json b/lerna.json index b82bf78..3a98548 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,5 @@ { + "$schema": "node_modules/lerna/schemas/lerna-schema.json", "conventionalCommits": true, "packages": ["packages/*"], "command": { diff --git a/package.json b/package.json index 7ad065b..146a35d 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/packages/array-max/README.md b/packages/array-max/README.md index aecc55e..90c5cf5 100644 --- a/packages/array-max/README.md +++ b/packages/array-max/README.md @@ -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. @@ -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 diff --git a/packages/array-max/package.json b/packages/array-max/package.json index 7746712..4e2b5d6 100644 --- a/packages/array-max/package.json +++ b/packages/array-max/package.json @@ -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", @@ -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" } } diff --git a/packages/array-max/src/__tests__/max.test.js b/packages/array-max/src/__tests__/max.test.ts similarity index 91% rename from packages/array-max/src/__tests__/max.test.js rename to packages/array-max/src/__tests__/max.test.ts index 620b2e8..cd8ba22 100644 --- a/packages/array-max/src/__tests__/max.test.js +++ b/packages/array-max/src/__tests__/max.test.ts @@ -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); @@ -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( diff --git a/packages/array-max/src/index.js b/packages/array-max/src/index.ts similarity index 62% rename from packages/array-max/src/index.js rename to packages/array-max/src/index.ts index 019dafe..f090b7e 100644 --- a/packages/array-max/src/index.js +++ b/packages/array-max/src/index.ts @@ -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, + options: ArrayMaxOptions = {}, +): number { if (!isAnyArray(input)) { throw new TypeError('input must be an array'); } diff --git a/packages/array-max/tsconfig.build.json b/packages/array-max/tsconfig.build.json new file mode 100644 index 0000000..c63438b --- /dev/null +++ b/packages/array-max/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-max/tsconfig.json b/packages/array-max/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-max/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-max/tsconfig.test.json b/packages/array-max/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-max/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-max/types.d.ts b/packages/array-max/types.d.ts deleted file mode 100644 index 9137a59..0000000 --- a/packages/array-max/types.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -declare namespace mlArrayMax { - export interface ArrayMaxOptions { - /** - * Start index (inclusive) for the slice within which we look for the maximum. - */ - fromIndex?: number; - /** - * End index (exclusive) for the slice within which we look for the maximum - */ - toIndex?: number; - } -} - -/** - * Computes the maximum of the given values. - */ -declare function mlArrayMax( - array: ArrayLike, - options?: mlArrayMax.ArrayMaxOptions, -): number; - -export = mlArrayMax; diff --git a/packages/array-mean/README.md b/packages/array-mean/README.md index c2c26ef..472de59 100644 --- a/packages/array-mean/README.md +++ b/packages/array-mean/README.md @@ -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. @@ -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 diff --git a/packages/array-mean/package.json b/packages/array-mean/package.json index 996a13a..4a3550b 100644 --- a/packages/array-mean/package.json +++ b/packages/array-mean/package.json @@ -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", diff --git a/packages/array-mean/src/__tests__/mean.test.js b/packages/array-mean/src/__tests__/mean.test.ts similarity index 74% rename from packages/array-mean/src/__tests__/mean.test.js rename to packages/array-mean/src/__tests__/mean.test.ts index 6a88085..c05ed3b 100644 --- a/packages/array-mean/src/__tests__/mean.test.js +++ b/packages/array-mean/src/__tests__/mean.test.ts @@ -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; @@ -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/); }); diff --git a/packages/array-mean/src/index.js b/packages/array-mean/src/index.js deleted file mode 100644 index f050c9f..0000000 --- a/packages/array-mean/src/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import sum from 'ml-array-sum'; - -export default function mean(input) { - return sum(input) / input.length; -} diff --git a/packages/array-mean/src/index.ts b/packages/array-mean/src/index.ts new file mode 100644 index 0000000..c8b3750 --- /dev/null +++ b/packages/array-mean/src/index.ts @@ -0,0 +1,8 @@ +import sum from 'ml-array-sum'; + +/** + * Computes the mean of the given values. + */ +export default function mean(array: ArrayLike): number { + return sum(array) / array.length; +} diff --git a/packages/array-mean/tsconfig.build.json b/packages/array-mean/tsconfig.build.json new file mode 100644 index 0000000..ad33d93 --- /dev/null +++ b/packages/array-mean/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "references": [{ "path": "../array-sum/tsconfig.json" }], + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-mean/tsconfig.json b/packages/array-mean/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-mean/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-mean/tsconfig.test.json b/packages/array-mean/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-mean/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-mean/types.d.ts b/packages/array-mean/types.d.ts deleted file mode 100644 index c45e07c..0000000 --- a/packages/array-mean/types.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module 'ml-array-mean' { - /** - * Computes the mean of the given values. - */ - function arrayMean(array: ArrayLike): number; - export = arrayMean; -} diff --git a/packages/array-median/README.md b/packages/array-median/README.md index 49026e2..4251212 100644 --- a/packages/array-median/README.md +++ b/packages/array-median/README.md @@ -1,7 +1,7 @@ # array-median - [![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 median value in an array, this median use the [Floyd-Rivest algorithm](https://en.wikipedia.org/wiki/Floyd%E2%80%93Rivest_algorithm). @@ -9,7 +9,6 @@ Thanks to [mad-gooze](https://github.com/mad-gooze) for his median-quickselect [ Some benchmarks [here](https://jsperf.com/median-inplace/1). - ## Installation `$ npm install --save ml-array-median` @@ -25,9 +24,9 @@ const result = median([1, 5, 3, 2, 4]); ## License - [MIT](./LICENSE) +[MIT](./LICENSE) [npm-image]: https://img.shields.io/npm/v/ml-array-median.svg?style=flat-square [npm-url]: https://npmjs.org/package/ml-array-median [download-image]: https://img.shields.io/npm/dm/ml-array-median.svg?style=flat-square -[download-url]: https://npmjs.org/package/ml-array-median \ No newline at end of file +[download-url]: https://npmjs.org/package/ml-array-median diff --git a/packages/array-median/package.json b/packages/array-median/package.json index 01581b2..916e25d 100644 --- a/packages/array-median/package.json +++ b/packages/array-median/package.json @@ -2,14 +2,16 @@ "name": "ml-array-median", "version": "1.1.6", "description": "Get the median 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", @@ -23,7 +25,7 @@ }, "homepage": "https://github.com/mljs/array/tree/master/packages/array-median#readme", "dependencies": { - "is-any-array": "^2.0.0", + "is-any-array": "^3.0.0", "median-quickselect": "^1.0.1" } } diff --git a/packages/array-median/src/__tests__/median.test.js b/packages/array-median/src/__tests__/median.test.ts similarity index 77% rename from packages/array-median/src/__tests__/median.test.js rename to packages/array-median/src/__tests__/median.test.ts index ba748f4..4f99eb9 100644 --- a/packages/array-median/src/__tests__/median.test.js +++ b/packages/array-median/src/__tests__/median.test.ts @@ -1,7 +1,9 @@ -import median from '..'; +import { describe, expect, it } from 'vitest'; + +import median from '../index.ts'; describe('array-median', () => { - let data = []; + const data: number[] = []; for (let i = 0; i < 1000; i++) { data.push(Math.random()); } @@ -14,18 +16,21 @@ describe('array-median', () => { expect(median([3, 2, 1])).toBe(2); expect(median(data)).toBeCloseTo(0.5, 1); }); + it('should return the median with typed array', () => { - let array = new Uint16Array(5); + const array = new Uint16Array(5); array[0] = 4; array[1] = 1; array[2] = 2; array[3] = 3; array[4] = 0; + expect(median(array)).toBe(2); }); it('should throw on invalid value', () => { expect(() => median([])).toThrow(/input must not be empty/); + // @ts-expect-error ensure implementation catch missing input expect(() => median()).toThrow(/input must be an array/); }); }); diff --git a/packages/array-median/src/index.js b/packages/array-median/src/index.ts similarity index 72% rename from packages/array-median/src/index.js rename to packages/array-median/src/index.ts index b7f85d6..4cf10a7 100644 --- a/packages/array-median/src/index.js +++ b/packages/array-median/src/index.ts @@ -1,7 +1,8 @@ +/// import { isAnyArray } from 'is-any-array'; import quickSelectMedian from 'median-quickselect'; -export default function median(input) { +export default function median(input: ArrayLike): number { if (!isAnyArray(input)) { throw new TypeError('input must be an array'); } diff --git a/packages/array-median/src/median-quickselect.d.ts b/packages/array-median/src/median-quickselect.d.ts new file mode 100644 index 0000000..6eaa2ca --- /dev/null +++ b/packages/array-median/src/median-quickselect.d.ts @@ -0,0 +1,7 @@ +declare module 'median-quickselect'; + +declare module 'median-quickselect' { + function quickSelectMedian(arr: ArrayLike): number; + + export = quickSelectMedian; +} diff --git a/packages/array-median/tsconfig.build.json b/packages/array-median/tsconfig.build.json new file mode 100644 index 0000000..c63438b --- /dev/null +++ b/packages/array-median/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-median/tsconfig.json b/packages/array-median/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-median/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-median/tsconfig.test.json b/packages/array-median/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-median/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-median/types.d.ts b/packages/array-median/types.d.ts deleted file mode 100644 index 315ffd7..0000000 --- a/packages/array-median/types.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module 'ml-array-median' { - /** - * Computes the median of the given values. - */ - function arrayMedian(array: ArrayLike): number; - export = arrayMedian; -} diff --git a/packages/array-min/README.md b/packages/array-min/README.md index 327f3fa..0744a74 100644 --- a/packages/array-min/README.md +++ b/packages/array-min/README.md @@ -1,7 +1,7 @@ # array-min - [![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 minimum value in an array. @@ -20,7 +20,7 @@ const result = min([1, 5, 3, 2, 4]); ## License - [MIT](./LICENSE) +[MIT](./LICENSE) [npm-image]: https://img.shields.io/npm/v/ml-array-min.svg?style=flat-square [npm-url]: https://npmjs.org/package/ml-array-min diff --git a/packages/array-min/package.json b/packages/array-min/package.json index 4c4bc69..8b60278 100644 --- a/packages/array-min/package.json +++ b/packages/array-min/package.json @@ -2,14 +2,16 @@ "name": "ml-array-min", "version": "1.2.3", "description": "Get the minimum 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", @@ -23,6 +25,6 @@ }, "homepage": "https://github.com/mljs/array/tree/master/packages/array-min#readme", "dependencies": { - "is-any-array": "^2.0.0" + "is-any-array": "^3.0.0" } } diff --git a/packages/array-min/src/__tests__/min.test.js b/packages/array-min/src/__tests__/min.test.ts similarity index 91% rename from packages/array-min/src/__tests__/min.test.js rename to packages/array-min/src/__tests__/min.test.ts index ca52c48..0b379fc 100644 --- a/packages/array-min/src/__tests__/min.test.js +++ b/packages/array-min/src/__tests__/min.test.ts @@ -1,7 +1,9 @@ -import min from '..'; +import { describe, expect, it } from 'vitest'; + +import min from '../index.ts'; describe('array-min', () => { - let typedArray = new Uint16Array(3); + const typedArray = new Uint16Array(3); typedArray[0] = 1; typedArray[1] = 2; typedArray[2] = 3; @@ -23,7 +25,9 @@ describe('array-min', () => { expect(min(typedArray, { fromIndex: 0, toIndex: 2 })).toBe(1); expect(min(typedArray, { fromIndex: 0, toIndex: 3 })).toBe(1); }); + it('should throw on invalid value', () => { + // @ts-expect-error ensure implementation catch missing input expect(() => min()).toThrow(/input must be an array/); expect(() => min([])).toThrow(/input must not be empty/); diff --git a/packages/array-min/src/index.js b/packages/array-min/src/index.ts similarity index 66% rename from packages/array-min/src/index.js rename to packages/array-min/src/index.ts index 59a8b1b..d73d547 100644 --- a/packages/array-min/src/index.js +++ b/packages/array-min/src/index.ts @@ -1,6 +1,23 @@ import { isAnyArray } from 'is-any-array'; -export default function min(input, options = {}) { +export interface ArrayMinOptions { + /** + * Start index (inclusive) for the slice within which we look for the minimum. + */ + fromIndex?: number; + /** + * End index (exclusive) for the slice within which we look for the minimum + */ + toIndex?: number; +} + +/** + * Computes the minimum of the given values. + */ +export default function min( + input: ArrayLike, + options: ArrayMinOptions = {}, +): number { if (!isAnyArray(input)) { throw new TypeError('input must be an array'); } diff --git a/packages/array-min/tsconfig.build.json b/packages/array-min/tsconfig.build.json new file mode 100644 index 0000000..c63438b --- /dev/null +++ b/packages/array-min/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-min/tsconfig.json b/packages/array-min/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-min/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-min/tsconfig.test.json b/packages/array-min/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-min/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-min/types.d.ts b/packages/array-min/types.d.ts deleted file mode 100644 index a902a77..0000000 --- a/packages/array-min/types.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -declare namespace mlArrayMin { - export interface ArrayMinOptions { - /** - * Start index (inclusive) for the slice within which we look for the minimum. - */ - fromIndex?: number; - /** - * End index (exclusive) for the slice within which we look for the minimum - */ - toIndex?: number; - } -} - -/** - * Computes the minimum of the given values. - */ -declare function mlArrayMin( - array: ArrayLike, - options?: mlArrayMin.ArrayMinOptions, -): number; - -export = mlArrayMin; diff --git a/packages/array-mode/README.md b/packages/array-mode/README.md index 16f9397..b05da58 100644 --- a/packages/array-mode/README.md +++ b/packages/array-mode/README.md @@ -1,7 +1,7 @@ # array-mode - [![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 most repeated value in an array. @@ -20,7 +20,7 @@ const result = mode([1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4]); ## License - [MIT](./LICENSE) +[MIT](./LICENSE) [npm-image]: https://img.shields.io/npm/v/ml-array-mode.svg?style=flat-square [npm-url]: https://npmjs.org/package/ml-array-mode diff --git a/packages/array-mode/package.json b/packages/array-mode/package.json index 99f710b..f425a5b 100644 --- a/packages/array-mode/package.json +++ b/packages/array-mode/package.json @@ -2,14 +2,16 @@ "name": "ml-array-mode", "version": "1.1.5", "description": "Get the most repeated 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", @@ -23,6 +25,6 @@ }, "homepage": "https://github.com/mljs/array/tree/master/packages/array-mode#readme", "dependencies": { - "is-any-array": "^2.0.0" + "is-any-array": "^3.0.0" } } diff --git a/packages/array-mode/src/__tests__/mode.test.js b/packages/array-mode/src/__tests__/mode.test.ts similarity index 76% rename from packages/array-mode/src/__tests__/mode.test.js rename to packages/array-mode/src/__tests__/mode.test.ts index d2e40e0..0d2bac5 100644 --- a/packages/array-mode/src/__tests__/mode.test.js +++ b/packages/array-mode/src/__tests__/mode.test.ts @@ -1,7 +1,9 @@ -import mode from '..'; +import { describe, expect, it } from 'vitest'; + +import mode from '../index.ts'; describe('array-mode', () => { - let typedArray = new Uint16Array(3); + const typedArray = new Uint16Array(3); typedArray[0] = 2; typedArray[1] = 3; typedArray[2] = 1; @@ -17,6 +19,7 @@ describe('array-mode', () => { }); it('should throw on invalid value', () => { + // @ts-expect-error ensure implementation catch missing input expect(() => mode()).toThrow(/input must be an array/); expect(() => mode([])).toThrow(/input must not be empty/); }); diff --git a/packages/array-mode/src/index.js b/packages/array-mode/src/index.ts similarity index 63% rename from packages/array-mode/src/index.js rename to packages/array-mode/src/index.ts index b4edb76..7645b1c 100644 --- a/packages/array-mode/src/index.js +++ b/packages/array-mode/src/index.ts @@ -1,6 +1,9 @@ import { isAnyArray } from 'is-any-array'; -export default function mode(input) { +/** + * Computes the mode of the given values. + */ +export default function mode(input: ArrayLike): number { if (!isAnyArray(input)) { throw new TypeError('input must be an array'); } @@ -11,21 +14,21 @@ export default function mode(input) { let maxValue = 0; let maxCount = 0; let count = 0; - let counts = {}; + const counts: Record = {}; - for (let i = 0; i < input.length; ++i) { - let element = input[i]; + for (const element of input) { count = counts[element]; if (count) { counts[element]++; count++; } else { - counts[element] = count = 1; + count = 1; + counts[element] = count; } if (count > maxCount) { maxCount = count; - maxValue = input[i]; + maxValue = element; } } diff --git a/packages/array-mode/tsconfig.build.json b/packages/array-mode/tsconfig.build.json new file mode 100644 index 0000000..c63438b --- /dev/null +++ b/packages/array-mode/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-mode/tsconfig.json b/packages/array-mode/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-mode/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-mode/tsconfig.test.json b/packages/array-mode/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-mode/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-mode/types.d.ts b/packages/array-mode/types.d.ts deleted file mode 100644 index 96e26b7..0000000 --- a/packages/array-mode/types.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module 'ml-array-mode' { - /** - * Computes the mode of the given values. - */ - function arrayMode(array: ArrayLike): number; - export = arrayMode; -} diff --git a/packages/array-normed/History.md b/packages/array-normed/History.md deleted file mode 100644 index 88c6de8..0000000 --- a/packages/array-normed/History.md +++ /dev/null @@ -1,19 +0,0 @@ -# 1.1.0 (2020-03-02) - - -### Bug Fixes - -* add is-any-array dependency ([451f438](https://github.com/mljs/array/commit/451f43807d3d290aefb6f813408438a1121ce2f7)) -* allow any array in array-normed and array-sequential-fill ([2772ea3](https://github.com/mljs/array/commit/2772ea352c3948b657eb7ae537b04d3e2c287d3d)) -* documentation ([dd9899e](https://github.com/mljs/array/commit/dd9899e13be8747a90ea90ceaa2ee1746be90092)) - - -### Features - -* add standard deviation and variance ([#3](https://github.com/mljs/array/issues/3)) ([b6baef9](https://github.com/mljs/array/commit/b6baef93a5905a36993426a39d15f3b872c19103)) -* **rescale:** autoMinMax option for keeping the current max or min ([#2](https://github.com/mljs/array/issues/2)) ([6f0ebe3](https://github.com/mljs/array/commit/6f0ebe365fc0c1ba10d5c9fff024f5392f710815)) -* add array-rescale package ([ceb02b6](https://github.com/mljs/array/commit/ceb02b640da42af99dd22b97ab6930752eca6e61)) -* add mode, mean and median packages ([dc6a813](https://github.com/mljs/array/commit/dc6a813a2cec1e3f13f1e990defc0b34ca80d3d0)) - - - diff --git a/packages/array-normed/README.md b/packages/array-normed/README.md index 26c80df..a95735d 100644 --- a/packages/array-normed/README.md +++ b/packages/array-normed/README.md @@ -21,14 +21,14 @@ const result = normed([1, 2, 3, 4]); ```js import normed from 'ml-array-normed'; -const result = normed([1, 2, 3, 4], {algorithm:'max'}); +const result = normed([1, 2, 3, 4], { algorithm: 'max' }); // [0.25, 0.5, 0.75, 1] ``` ```js import normed from 'ml-array-normed'; -const result = normed([1, 2, 3, 4], {algorithm:'max', maxValue: 100}); +const result = normed([1, 2, 3, 4], { algorithm: 'max', maxValue: 100 }); // [25, 50, 75, 100] ``` diff --git a/packages/array-normed/docs/assets/anchor.js b/packages/array-normed/docs/assets/anchor.js deleted file mode 100644 index ca95514..0000000 --- a/packages/array-normed/docs/assets/anchor.js +++ /dev/null @@ -1,348 +0,0 @@ -/*! - * AnchorJS - v4.0.0 - 2017-06-02 - * https://github.com/bryanbraun/anchorjs - * Copyright (c) 2017 Bryan Braun; Licensed MIT - */ -/* eslint-env amd, node */ - -// https://github.com/umdjs/umd/blob/master/templates/returnExports.js -(function (root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define([], factory); - } else if (typeof module === 'object' && module.exports) { - // Node. Does not work with strict CommonJS, but - // only CommonJS-like environments that support module.exports, - // like Node. - module.exports = factory(); - } else { - // Browser globals (root is window) - root.AnchorJS = factory(); - root.anchors = new root.AnchorJS(); - } -})(this, function () { - function AnchorJS(options) { - this.options = options || {}; - this.elements = []; - - /** - * Assigns options to the internal options object, and provides defaults. - * @param {Object} opts - Options object - */ - function _applyRemainingDefaultOptions(opts) { - opts.icon = opts.hasOwnProperty('icon') ? opts.icon : '\ue9cb'; // Accepts characters (and also URLs?), like '#', '¶', '❡', or '§'. - opts.visible = opts.hasOwnProperty('visible') ? opts.visible : 'hover'; // Also accepts 'always' & 'touch' - opts.placement = opts.hasOwnProperty('placement') - ? opts.placement - : 'right'; // Also accepts 'left' - opts.class = opts.hasOwnProperty('class') ? opts.class : ''; // Accepts any class name. - // Using Math.floor here will ensure the value is Number-cast and an integer. - opts.truncate = opts.hasOwnProperty('truncate') - ? Math.floor(opts.truncate) - : 64; // Accepts any value that can be typecast to a number. - } - - _applyRemainingDefaultOptions(this.options); - - /** - * Checks to see if this device supports touch. Uses criteria pulled from Modernizr: - * https://github.com/Modernizr/Modernizr/blob/da22eb27631fc4957f67607fe6042e85c0a84656/feature-detects/touchevents.js#L40 - * @returns {Boolean} - true if the current device supports touch. - */ - this.isTouchDevice = function () { - return !!( - 'ontouchstart' in window || - (window.DocumentTouch && document instanceof DocumentTouch) - ); - }; - - /** - * Add anchor links to page elements. - * @param {String|Array|Nodelist} selector - A CSS selector for targeting the elements you wish to add anchor links - * to. Also accepts an array or nodeList containing the relavant elements. - * @returns {this} - The AnchorJS object - */ - this.add = function (selector) { - let elements; - let elsWithIds; - let idList; - let elementID; - let i; - let index; - let count; - let tidyText; - let newTidyText; - let readableID; - let anchor; - let visibleOptionToUse; - let indexesToDrop = []; - - // We reapply options here because somebody may have overwritten the default options object when setting options. - // For example, this overwrites all options but visible: - // - // anchors.options = { visible: 'always'; } - _applyRemainingDefaultOptions(this.options); - - visibleOptionToUse = this.options.visible; - if (visibleOptionToUse === 'touch') { - visibleOptionToUse = this.isTouchDevice() ? 'always' : 'hover'; - } - - // Provide a sensible default selector, if none is given. - if (!selector) { - selector = 'h2, h3, h4, h5, h6'; - } - - elements = _getElements(selector); - - if (elements.length === 0) { - return this; - } - - _addBaselineStyles(); - - // We produce a list of existing IDs so we don't generate a duplicate. - elsWithIds = document.querySelectorAll('[id]'); - idList = [].map.call(elsWithIds, function assign(el) { - return el.id; - }); - - for (i = 0; i < elements.length; i++) { - if (this.hasAnchorJSLink(elements[i])) { - indexesToDrop.push(i); - continue; - } - - if (elements[i].hasAttribute('id')) { - elementID = elements[i].getAttribute('id'); - } else if (elements[i].hasAttribute('data-anchor-id')) { - elementID = elements[i].getAttribute('data-anchor-id'); - } else { - tidyText = this.urlify(elements[i].textContent); - - // Compare our generated ID to existing IDs (and increment it if needed) - // before we add it to the page. - newTidyText = tidyText; - count = 0; - do { - if (index !== undefined) { - newTidyText = `${tidyText}-${count}`; - } - - index = idList.indexOf(newTidyText); - count += 1; - } while (index !== -1); - index = undefined; - idList.push(newTidyText); - - elements[i].setAttribute('id', newTidyText); - elementID = newTidyText; - } - - readableID = elementID.replace(/-/g, ' '); - - // The following code builds the following DOM structure in a more effiecient (albeit opaque) way. - // ''; - anchor = document.createElement('a'); - anchor.className = `anchorjs-link ${this.options.class}`; - anchor.href = `#${elementID}`; - anchor.setAttribute('aria-label', `Anchor link for: ${readableID}`); - anchor.setAttribute('data-anchorjs-icon', this.options.icon); - - if (visibleOptionToUse === 'always') { - anchor.style.opacity = '1'; - } - - if (this.options.icon === '\ue9cb') { - anchor.style.font = '1em/1 anchorjs-icons'; - - // We set lineHeight = 1 here because the `anchorjs-icons` font family could otherwise affect the - // height of the heading. This isn't the case for icons with `placement: left`, so we restore - // line-height: inherit in that case, ensuring they remain positioned correctly. For more info, - // see https://github.com/bryanbraun/anchorjs/issues/39. - if (this.options.placement === 'left') { - anchor.style.lineHeight = 'inherit'; - } - } - - if (this.options.placement === 'left') { - anchor.style.position = 'absolute'; - anchor.style.marginLeft = '-1em'; - anchor.style.paddingRight = '0.5em'; - elements[i].insertBefore(anchor, elements[i].firstChild); - } else { - // if the option provided is `right` (or anything else). - anchor.style.paddingLeft = '0.375em'; - elements[i].appendChild(anchor); - } - } - - for (i = 0; i < indexesToDrop.length; i++) { - elements.splice(indexesToDrop[i] - i, 1); - } - this.elements = this.elements.concat(elements); - - return this; - }; - - /** - * Removes all anchorjs-links from elements targed by the selector. - * @param {String|Array|Nodelist} selector - A CSS selector string targeting elements with anchor links, - * OR a nodeList / array containing the DOM elements. - * @returns {this} - The AnchorJS object - */ - this.remove = function (selector) { - let index; - let domAnchor; - let elements = _getElements(selector); - - for (let i = 0; i < elements.length; i++) { - domAnchor = elements[i].querySelector('.anchorjs-link'); - if (domAnchor) { - // Drop the element from our main list, if it's in there. - index = this.elements.indexOf(elements[i]); - if (index !== -1) { - this.elements.splice(index, 1); - } - // Remove the anchor from the DOM. - elements[i].removeChild(domAnchor); - } - } - return this; - }; - - /** - * Removes all anchorjs links. Mostly used for tests. - */ - this.removeAll = function () { - this.remove(this.elements); - }; - - /** - * Urlify - Refine text so it makes a good ID. - * - * To do this, we remove apostrophes, replace nonsafe characters with hyphens, - * remove extra hyphens, truncate, trim hyphens, and make lowercase. - * - * @param {String} text - Any text. Usually pulled from the webpage element we are linking to. - * @returns {String} - hyphen-delimited text for use in IDs and URLs. - */ - this.urlify = function (text) { - // Regex for finding the nonsafe URL characters (many need escaping): & +$,:;=?@"#{}|^~[`%!'<>]./()*\ - let nonsafeChars = /[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\]/g; - let urlText; - - // The reason we include this _applyRemainingDefaultOptions is so urlify can be called independently, - // even after setting options. This can be useful for tests or other applications. - if (!this.options.truncate) { - _applyRemainingDefaultOptions(this.options); - } - - // Note: we trim hyphens after truncating because truncating can cause dangling hyphens. - // Example string: // " ⚡⚡ Don't forget: URL fragments should be i18n-friendly, hyphenated, short, and clean." - urlText = text - .trim() // "⚡⚡ Don't forget: URL fragments should be i18n-friendly, hyphenated, short, and clean." - .replace(/\'/gi, '') // "⚡⚡ Dont forget: URL fragments should be i18n-friendly, hyphenated, short, and clean." - .replace(nonsafeChars, '-') // "⚡⚡-Dont-forget--URL-fragments-should-be-i18n-friendly--hyphenated--short--and-clean-" - .replace(/-{2,}/g, '-') // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated-short-and-clean-" - .substring(0, this.options.truncate) // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated-" - .replace(/^-+|-+$/gm, '') // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated" - .toLowerCase(); // "⚡⚡-dont-forget-url-fragments-should-be-i18n-friendly-hyphenated" - - return urlText; - }; - - /** - * Determines if this element already has an AnchorJS link on it. - * Uses this technique: http://stackoverflow.com/a/5898748/1154642 - * @param {HTMLElemnt} el - a DOM node - * @returns {Boolean} true/false - */ - this.hasAnchorJSLink = function (el) { - let hasLeftAnchor = - el.firstChild && - ` ${el.firstChild.className} `.indexOf(' anchorjs-link ') > -1; - let hasRightAnchor = - el.lastChild && - ` ${el.lastChild.className} `.indexOf(' anchorjs-link ') > -1; - - return hasLeftAnchor || hasRightAnchor || false; - }; - - /** - * Turns a selector, nodeList, or array of elements into an array of elements (so we can use array methods). - * It also throws errors on any other inputs. Used to handle inputs to .add and .remove. - * @param {String|Array|Nodelist} input - A CSS selector string targeting elements with anchor links, - * OR a nodeList / array containing the DOM elements. - * @returns {Array} - An array containing the elements we want. - */ - function _getElements(input) { - let elements; - if (typeof input === 'string' || input instanceof String) { - // See https://davidwalsh.name/nodelist-array for the technique transforming nodeList -> Array. - elements = [].slice.call(document.querySelectorAll(input)); - // I checked the 'input instanceof NodeList' test in IE9 and modern browsers and it worked for me. - } else if (Array.isArray(input) || input instanceof NodeList) { - elements = [].slice.call(input); - } else { - throw new Error('The selector provided to AnchorJS was invalid.'); - } - return elements; - } - - /** - * _addBaselineStyles - * Adds baseline styles to the page, used by all AnchorJS links irregardless of configuration. - */ - function _addBaselineStyles() { - // We don't want to add global baseline styles if they've been added before. - if (document.head.querySelector('style.anchorjs') !== null) { - return; - } - - let style = document.createElement('style'); - let linkRule = - ' .anchorjs-link {' + - ' opacity: 0;' + - ' text-decoration: none;' + - ' -webkit-font-smoothing: antialiased;' + - ' -moz-osx-font-smoothing: grayscale;' + - ' }'; - let hoverRule = - ' *:hover > .anchorjs-link,' + - ' .anchorjs-link:focus {' + - ' opacity: 1;' + - ' }'; - let anchorjsLinkFontFace = - ' @font-face {' + - ' font-family: "anchorjs-icons";' + // Icon from icomoon; 10px wide & 10px tall; 2 empty below & 4 above - ' src: url(data:n/a;base64,AAEAAAALAIAAAwAwT1MvMg8yG2cAAAE4AAAAYGNtYXDp3gC3AAABpAAAAExnYXNwAAAAEAAAA9wAAAAIZ2x5ZlQCcfwAAAH4AAABCGhlYWQHFvHyAAAAvAAAADZoaGVhBnACFwAAAPQAAAAkaG10eASAADEAAAGYAAAADGxvY2EACACEAAAB8AAAAAhtYXhwAAYAVwAAARgAAAAgbmFtZQGOH9cAAAMAAAAAunBvc3QAAwAAAAADvAAAACAAAQAAAAEAAHzE2p9fDzz1AAkEAAAAAADRecUWAAAAANQA6R8AAAAAAoACwAAAAAgAAgAAAAAAAAABAAADwP/AAAACgAAA/9MCrQABAAAAAAAAAAAAAAAAAAAAAwABAAAAAwBVAAIAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAMCQAGQAAUAAAKZAswAAACPApkCzAAAAesAMwEJAAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAQAAg//0DwP/AAEADwABAAAAAAQAAAAAAAAAAAAAAIAAAAAAAAAIAAAACgAAxAAAAAwAAAAMAAAAcAAEAAwAAABwAAwABAAAAHAAEADAAAAAIAAgAAgAAACDpy//9//8AAAAg6cv//f///+EWNwADAAEAAAAAAAAAAAAAAAAACACEAAEAAAAAAAAAAAAAAAAxAAACAAQARAKAAsAAKwBUAAABIiYnJjQ3NzY2MzIWFxYUBwcGIicmNDc3NjQnJiYjIgYHBwYUFxYUBwYGIwciJicmNDc3NjIXFhQHBwYUFxYWMzI2Nzc2NCcmNDc2MhcWFAcHBgYjARQGDAUtLXoWOR8fORYtLTgKGwoKCjgaGg0gEhIgDXoaGgkJBQwHdR85Fi0tOAobCgoKOBoaDSASEiANehoaCQkKGwotLXoWOR8BMwUFLYEuehYXFxYugC44CQkKGwo4GkoaDQ0NDXoaShoKGwoFBe8XFi6ALjgJCQobCjgaShoNDQ0NehpKGgobCgoKLYEuehYXAAAADACWAAEAAAAAAAEACAAAAAEAAAAAAAIAAwAIAAEAAAAAAAMACAAAAAEAAAAAAAQACAAAAAEAAAAAAAUAAQALAAEAAAAAAAYACAAAAAMAAQQJAAEAEAAMAAMAAQQJAAIABgAcAAMAAQQJAAMAEAAMAAMAAQQJAAQAEAAMAAMAAQQJAAUAAgAiAAMAAQQJAAYAEAAMYW5jaG9yanM0MDBAAGEAbgBjAGgAbwByAGoAcwA0ADAAMABAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAH//wAP) format("truetype");' + - ' }'; - let pseudoElContent = - ' [data-anchorjs-icon]::after {' + - ' content: attr(data-anchorjs-icon);' + - ' }'; - let firstStyleEl; - - style.className = 'anchorjs'; - style.appendChild(document.createTextNode('')); // Necessary for Webkit. - - // We place it in the head with the other style tags, if possible, so as to - // not look out of place. We insert before the others so these styles can be - // overridden if necessary. - firstStyleEl = document.head.querySelector('[rel="stylesheet"], style'); - if (firstStyleEl === undefined) { - document.head.appendChild(style); - } else { - document.head.insertBefore(style, firstStyleEl); - } - - style.sheet.insertRule(linkRule, style.sheet.cssRules.length); - style.sheet.insertRule(hoverRule, style.sheet.cssRules.length); - style.sheet.insertRule(pseudoElContent, style.sheet.cssRules.length); - style.sheet.insertRule(anchorjsLinkFontFace, style.sheet.cssRules.length); - } - } - - return AnchorJS; -}); diff --git a/packages/array-normed/docs/assets/bass-addons.css b/packages/array-normed/docs/assets/bass-addons.css deleted file mode 100644 index c27e96d..0000000 --- a/packages/array-normed/docs/assets/bass-addons.css +++ /dev/null @@ -1,12 +0,0 @@ -.input { - font-family: inherit; - display: block; - width: 100%; - height: 2rem; - padding: .5rem; - margin-bottom: 1rem; - border: 1px solid #ccc; - font-size: .875rem; - border-radius: 3px; - box-sizing: border-box; -} diff --git a/packages/array-normed/docs/assets/bass.css b/packages/array-normed/docs/assets/bass.css deleted file mode 100644 index 2d860c5..0000000 --- a/packages/array-normed/docs/assets/bass.css +++ /dev/null @@ -1,544 +0,0 @@ -/*! Basscss | http://basscss.com | MIT License */ - -.h1{ font-size: 2rem } -.h2{ font-size: 1.5rem } -.h3{ font-size: 1.25rem } -.h4{ font-size: 1rem } -.h5{ font-size: .875rem } -.h6{ font-size: .75rem } - -.font-family-inherit{ font-family:inherit } -.font-size-inherit{ font-size:inherit } -.text-decoration-none{ text-decoration:none } - -.bold{ font-weight: bold; font-weight: bold } -.regular{ font-weight:normal } -.italic{ font-style:italic } -.caps{ text-transform:uppercase; letter-spacing: .2em; } - -.left-align{ text-align:left } -.center{ text-align:center } -.right-align{ text-align:right } -.justify{ text-align:justify } - -.nowrap{ white-space:nowrap } -.break-word{ word-wrap:break-word } - -.line-height-1{ line-height: 1 } -.line-height-2{ line-height: 1.125 } -.line-height-3{ line-height: 1.25 } -.line-height-4{ line-height: 1.5 } - -.list-style-none{ list-style:none } -.underline{ text-decoration:underline } - -.truncate{ - max-width:100%; - overflow:hidden; - text-overflow:ellipsis; - white-space:nowrap; -} - -.list-reset{ - list-style:none; - padding-left:0; -} - -.inline{ display:inline } -.block{ display:block } -.inline-block{ display:inline-block } -.table{ display:table } -.table-cell{ display:table-cell } - -.overflow-hidden{ overflow:hidden } -.overflow-scroll{ overflow:scroll } -.overflow-auto{ overflow:auto } - -.clearfix:before, -.clearfix:after{ - content:" "; - display:table -} -.clearfix:after{ clear:both } - -.left{ float:left } -.right{ float:right } - -.fit{ max-width:100% } - -.max-width-1{ max-width: 24rem } -.max-width-2{ max-width: 32rem } -.max-width-3{ max-width: 48rem } -.max-width-4{ max-width: 64rem } - -.border-box{ box-sizing:border-box } - -.align-baseline{ vertical-align:baseline } -.align-top{ vertical-align:top } -.align-middle{ vertical-align:middle } -.align-bottom{ vertical-align:bottom } - -.m0{ margin:0 } -.mt0{ margin-top:0 } -.mr0{ margin-right:0 } -.mb0{ margin-bottom:0 } -.ml0{ margin-left:0 } -.mx0{ margin-left:0; margin-right:0 } -.my0{ margin-top:0; margin-bottom:0 } - -.m1{ margin: .5rem } -.mt1{ margin-top: .5rem } -.mr1{ margin-right: .5rem } -.mb1{ margin-bottom: .5rem } -.ml1{ margin-left: .5rem } -.mx1{ margin-left: .5rem; margin-right: .5rem } -.my1{ margin-top: .5rem; margin-bottom: .5rem } - -.m2{ margin: 1rem } -.mt2{ margin-top: 1rem } -.mr2{ margin-right: 1rem } -.mb2{ margin-bottom: 1rem } -.ml2{ margin-left: 1rem } -.mx2{ margin-left: 1rem; margin-right: 1rem } -.my2{ margin-top: 1rem; margin-bottom: 1rem } - -.m3{ margin: 2rem } -.mt3{ margin-top: 2rem } -.mr3{ margin-right: 2rem } -.mb3{ margin-bottom: 2rem } -.ml3{ margin-left: 2rem } -.mx3{ margin-left: 2rem; margin-right: 2rem } -.my3{ margin-top: 2rem; margin-bottom: 2rem } - -.m4{ margin: 4rem } -.mt4{ margin-top: 4rem } -.mr4{ margin-right: 4rem } -.mb4{ margin-bottom: 4rem } -.ml4{ margin-left: 4rem } -.mx4{ margin-left: 4rem; margin-right: 4rem } -.my4{ margin-top: 4rem; margin-bottom: 4rem } - -.mxn1{ margin-left: -.5rem; margin-right: -.5rem; } -.mxn2{ margin-left: -1rem; margin-right: -1rem; } -.mxn3{ margin-left: -2rem; margin-right: -2rem; } -.mxn4{ margin-left: -4rem; margin-right: -4rem; } - -.ml-auto{ margin-left:auto } -.mr-auto{ margin-right:auto } -.mx-auto{ margin-left:auto; margin-right:auto; } - -.p0{ padding:0 } -.pt0{ padding-top:0 } -.pr0{ padding-right:0 } -.pb0{ padding-bottom:0 } -.pl0{ padding-left:0 } -.px0{ padding-left:0; padding-right:0 } -.py0{ padding-top:0; padding-bottom:0 } - -.p1{ padding: .5rem } -.pt1{ padding-top: .5rem } -.pr1{ padding-right: .5rem } -.pb1{ padding-bottom: .5rem } -.pl1{ padding-left: .5rem } -.py1{ padding-top: .5rem; padding-bottom: .5rem } -.px1{ padding-left: .5rem; padding-right: .5rem } - -.p2{ padding: 1rem } -.pt2{ padding-top: 1rem } -.pr2{ padding-right: 1rem } -.pb2{ padding-bottom: 1rem } -.pl2{ padding-left: 1rem } -.py2{ padding-top: 1rem; padding-bottom: 1rem } -.px2{ padding-left: 1rem; padding-right: 1rem } - -.p3{ padding: 2rem } -.pt3{ padding-top: 2rem } -.pr3{ padding-right: 2rem } -.pb3{ padding-bottom: 2rem } -.pl3{ padding-left: 2rem } -.py3{ padding-top: 2rem; padding-bottom: 2rem } -.px3{ padding-left: 2rem; padding-right: 2rem } - -.p4{ padding: 4rem } -.pt4{ padding-top: 4rem } -.pr4{ padding-right: 4rem } -.pb4{ padding-bottom: 4rem } -.pl4{ padding-left: 4rem } -.py4{ padding-top: 4rem; padding-bottom: 4rem } -.px4{ padding-left: 4rem; padding-right: 4rem } - -.col{ - float:left; - box-sizing:border-box; -} - -.col-right{ - float:right; - box-sizing:border-box; -} - -.col-1{ - width:8.33333%; -} - -.col-2{ - width:16.66667%; -} - -.col-3{ - width:25%; -} - -.col-4{ - width:33.33333%; -} - -.col-5{ - width:41.66667%; -} - -.col-6{ - width:50%; -} - -.col-7{ - width:58.33333%; -} - -.col-8{ - width:66.66667%; -} - -.col-9{ - width:75%; -} - -.col-10{ - width:83.33333%; -} - -.col-11{ - width:91.66667%; -} - -.col-12{ - width:100%; -} -@media (min-width: 40em){ - - .sm-col{ - float:left; - box-sizing:border-box; - } - - .sm-col-right{ - float:right; - box-sizing:border-box; - } - - .sm-col-1{ - width:8.33333%; - } - - .sm-col-2{ - width:16.66667%; - } - - .sm-col-3{ - width:25%; - } - - .sm-col-4{ - width:33.33333%; - } - - .sm-col-5{ - width:41.66667%; - } - - .sm-col-6{ - width:50%; - } - - .sm-col-7{ - width:58.33333%; - } - - .sm-col-8{ - width:66.66667%; - } - - .sm-col-9{ - width:75%; - } - - .sm-col-10{ - width:83.33333%; - } - - .sm-col-11{ - width:91.66667%; - } - - .sm-col-12{ - width:100%; - } - -} -@media (min-width: 52em){ - - .md-col{ - float:left; - box-sizing:border-box; - } - - .md-col-right{ - float:right; - box-sizing:border-box; - } - - .md-col-1{ - width:8.33333%; - } - - .md-col-2{ - width:16.66667%; - } - - .md-col-3{ - width:25%; - } - - .md-col-4{ - width:33.33333%; - } - - .md-col-5{ - width:41.66667%; - } - - .md-col-6{ - width:50%; - } - - .md-col-7{ - width:58.33333%; - } - - .md-col-8{ - width:66.66667%; - } - - .md-col-9{ - width:75%; - } - - .md-col-10{ - width:83.33333%; - } - - .md-col-11{ - width:91.66667%; - } - - .md-col-12{ - width:100%; - } - -} -@media (min-width: 64em){ - - .lg-col{ - float:left; - box-sizing:border-box; - } - - .lg-col-right{ - float:right; - box-sizing:border-box; - } - - .lg-col-1{ - width:8.33333%; - } - - .lg-col-2{ - width:16.66667%; - } - - .lg-col-3{ - width:25%; - } - - .lg-col-4{ - width:33.33333%; - } - - .lg-col-5{ - width:41.66667%; - } - - .lg-col-6{ - width:50%; - } - - .lg-col-7{ - width:58.33333%; - } - - .lg-col-8{ - width:66.66667%; - } - - .lg-col-9{ - width:75%; - } - - .lg-col-10{ - width:83.33333%; - } - - .lg-col-11{ - width:91.66667%; - } - - .lg-col-12{ - width:100%; - } - -} -.flex{ display:-webkit-box; display:-webkit-flex; display:-ms-flexbox; display:flex } - -@media (min-width: 40em){ - .sm-flex{ display:-webkit-box; display:-webkit-flex; display:-ms-flexbox; display:flex } -} - -@media (min-width: 52em){ - .md-flex{ display:-webkit-box; display:-webkit-flex; display:-ms-flexbox; display:flex } -} - -@media (min-width: 64em){ - .lg-flex{ display:-webkit-box; display:-webkit-flex; display:-ms-flexbox; display:flex } -} - -.flex-column{ -webkit-box-orient:vertical; -webkit-box-direction:normal; -webkit-flex-direction:column; -ms-flex-direction:column; flex-direction:column } -.flex-wrap{ -webkit-flex-wrap:wrap; -ms-flex-wrap:wrap; flex-wrap:wrap } - -.items-start{ -webkit-box-align:start; -webkit-align-items:flex-start; -ms-flex-align:start; -ms-grid-row-align:flex-start; align-items:flex-start } -.items-end{ -webkit-box-align:end; -webkit-align-items:flex-end; -ms-flex-align:end; -ms-grid-row-align:flex-end; align-items:flex-end } -.items-center{ -webkit-box-align:center; -webkit-align-items:center; -ms-flex-align:center; -ms-grid-row-align:center; align-items:center } -.items-baseline{ -webkit-box-align:baseline; -webkit-align-items:baseline; -ms-flex-align:baseline; -ms-grid-row-align:baseline; align-items:baseline } -.items-stretch{ -webkit-box-align:stretch; -webkit-align-items:stretch; -ms-flex-align:stretch; -ms-grid-row-align:stretch; align-items:stretch } - -.self-start{ -webkit-align-self:flex-start; -ms-flex-item-align:start; align-self:flex-start } -.self-end{ -webkit-align-self:flex-end; -ms-flex-item-align:end; align-self:flex-end } -.self-center{ -webkit-align-self:center; -ms-flex-item-align:center; align-self:center } -.self-baseline{ -webkit-align-self:baseline; -ms-flex-item-align:baseline; align-self:baseline } -.self-stretch{ -webkit-align-self:stretch; -ms-flex-item-align:stretch; align-self:stretch } - -.justify-start{ -webkit-box-pack:start; -webkit-justify-content:flex-start; -ms-flex-pack:start; justify-content:flex-start } -.justify-end{ -webkit-box-pack:end; -webkit-justify-content:flex-end; -ms-flex-pack:end; justify-content:flex-end } -.justify-center{ -webkit-box-pack:center; -webkit-justify-content:center; -ms-flex-pack:center; justify-content:center } -.justify-between{ -webkit-box-pack:justify; -webkit-justify-content:space-between; -ms-flex-pack:justify; justify-content:space-between } -.justify-around{ -webkit-justify-content:space-around; -ms-flex-pack:distribute; justify-content:space-around } - -.content-start{ -webkit-align-content:flex-start; -ms-flex-line-pack:start; align-content:flex-start } -.content-end{ -webkit-align-content:flex-end; -ms-flex-line-pack:end; align-content:flex-end } -.content-center{ -webkit-align-content:center; -ms-flex-line-pack:center; align-content:center } -.content-between{ -webkit-align-content:space-between; -ms-flex-line-pack:justify; align-content:space-between } -.content-around{ -webkit-align-content:space-around; -ms-flex-line-pack:distribute; align-content:space-around } -.content-stretch{ -webkit-align-content:stretch; -ms-flex-line-pack:stretch; align-content:stretch } -.flex-auto{ - -webkit-box-flex:1; - -webkit-flex:1 1 auto; - -ms-flex:1 1 auto; - flex:1 1 auto; - min-width:0; - min-height:0; -} -.flex-none{ -webkit-box-flex:0; -webkit-flex:none; -ms-flex:none; flex:none } -.fs0{ flex-shrink: 0 } - -.order-0{ -webkit-box-ordinal-group:1; -webkit-order:0; -ms-flex-order:0; order:0 } -.order-1{ -webkit-box-ordinal-group:2; -webkit-order:1; -ms-flex-order:1; order:1 } -.order-2{ -webkit-box-ordinal-group:3; -webkit-order:2; -ms-flex-order:2; order:2 } -.order-3{ -webkit-box-ordinal-group:4; -webkit-order:3; -ms-flex-order:3; order:3 } -.order-last{ -webkit-box-ordinal-group:100000; -webkit-order:99999; -ms-flex-order:99999; order:99999 } - -.relative{ position:relative } -.absolute{ position:absolute } -.fixed{ position:fixed } - -.top-0{ top:0 } -.right-0{ right:0 } -.bottom-0{ bottom:0 } -.left-0{ left:0 } - -.z1{ z-index: 1 } -.z2{ z-index: 2 } -.z3{ z-index: 3 } -.z4{ z-index: 4 } - -.border{ - border-style:solid; - border-width: 1px; -} - -.border-top{ - border-top-style:solid; - border-top-width: 1px; -} - -.border-right{ - border-right-style:solid; - border-right-width: 1px; -} - -.border-bottom{ - border-bottom-style:solid; - border-bottom-width: 1px; -} - -.border-left{ - border-left-style:solid; - border-left-width: 1px; -} - -.border-none{ border:0 } - -.rounded{ border-radius: 3px } -.circle{ border-radius:50% } - -.rounded-top{ border-radius: 3px 3px 0 0 } -.rounded-right{ border-radius: 0 3px 3px 0 } -.rounded-bottom{ border-radius: 0 0 3px 3px } -.rounded-left{ border-radius: 3px 0 0 3px } - -.not-rounded{ border-radius:0 } - -.hide{ - position:absolute !important; - height:1px; - width:1px; - overflow:hidden; - clip:rect(1px, 1px, 1px, 1px); -} - -@media (max-width: 40em){ - .xs-hide{ display:none !important } -} - -@media (min-width: 40em) and (max-width: 52em){ - .sm-hide{ display:none !important } -} - -@media (min-width: 52em) and (max-width: 64em){ - .md-hide{ display:none !important } -} - -@media (min-width: 64em){ - .lg-hide{ display:none !important } -} - -.display-none{ display:none !important } - diff --git a/packages/array-normed/docs/assets/fonts/EOT/SourceCodePro-Bold.eot b/packages/array-normed/docs/assets/fonts/EOT/SourceCodePro-Bold.eot deleted file mode 100755 index d24cc39..0000000 Binary files a/packages/array-normed/docs/assets/fonts/EOT/SourceCodePro-Bold.eot and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/EOT/SourceCodePro-Regular.eot b/packages/array-normed/docs/assets/fonts/EOT/SourceCodePro-Regular.eot deleted file mode 100755 index 09e9473..0000000 Binary files a/packages/array-normed/docs/assets/fonts/EOT/SourceCodePro-Regular.eot and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/LICENSE.txt b/packages/array-normed/docs/assets/fonts/LICENSE.txt deleted file mode 100755 index d154618..0000000 --- a/packages/array-normed/docs/assets/fonts/LICENSE.txt +++ /dev/null @@ -1,93 +0,0 @@ -Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. - -This Font Software is licensed under the SIL Open Font License, Version 1.1. - -This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/packages/array-normed/docs/assets/fonts/OTF/SourceCodePro-Bold.otf b/packages/array-normed/docs/assets/fonts/OTF/SourceCodePro-Bold.otf deleted file mode 100755 index f4e576c..0000000 Binary files a/packages/array-normed/docs/assets/fonts/OTF/SourceCodePro-Bold.otf and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/OTF/SourceCodePro-Regular.otf b/packages/array-normed/docs/assets/fonts/OTF/SourceCodePro-Regular.otf deleted file mode 100755 index 4e3b9d0..0000000 Binary files a/packages/array-normed/docs/assets/fonts/OTF/SourceCodePro-Regular.otf and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf b/packages/array-normed/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf deleted file mode 100755 index e0c576f..0000000 Binary files a/packages/array-normed/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf b/packages/array-normed/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf deleted file mode 100755 index 437f472..0000000 Binary files a/packages/array-normed/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff b/packages/array-normed/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff deleted file mode 100755 index cf96099..0000000 Binary files a/packages/array-normed/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff b/packages/array-normed/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff deleted file mode 100755 index 395436e..0000000 Binary files a/packages/array-normed/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff b/packages/array-normed/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff deleted file mode 100755 index c65ba84..0000000 Binary files a/packages/array-normed/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff b/packages/array-normed/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff deleted file mode 100755 index 0af792a..0000000 Binary files a/packages/array-normed/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 b/packages/array-normed/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 deleted file mode 100755 index cbe3835..0000000 Binary files a/packages/array-normed/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 b/packages/array-normed/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 deleted file mode 100755 index 65cd591..0000000 Binary files a/packages/array-normed/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 b/packages/array-normed/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 deleted file mode 100755 index b78d523..0000000 Binary files a/packages/array-normed/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 b/packages/array-normed/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 deleted file mode 100755 index 18d2199..0000000 Binary files a/packages/array-normed/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 and /dev/null differ diff --git a/packages/array-normed/docs/assets/fonts/source-code-pro.css b/packages/array-normed/docs/assets/fonts/source-code-pro.css deleted file mode 100755 index 3abb4f0..0000000 --- a/packages/array-normed/docs/assets/fonts/source-code-pro.css +++ /dev/null @@ -1,23 +0,0 @@ -@font-face{ - font-family: 'Source Code Pro'; - font-weight: 400; - font-style: normal; - font-stretch: normal; - src: url('EOT/SourceCodePro-Regular.eot') format('embedded-opentype'), - url('WOFF2/TTF/SourceCodePro-Regular.ttf.woff2') format('woff2'), - url('WOFF/OTF/SourceCodePro-Regular.otf.woff') format('woff'), - url('OTF/SourceCodePro-Regular.otf') format('opentype'), - url('TTF/SourceCodePro-Regular.ttf') format('truetype'); -} - -@font-face{ - font-family: 'Source Code Pro'; - font-weight: 700; - font-style: normal; - font-stretch: normal; - src: url('EOT/SourceCodePro-Bold.eot') format('embedded-opentype'), - url('WOFF2/TTF/SourceCodePro-Bold.ttf.woff2') format('woff2'), - url('WOFF/OTF/SourceCodePro-Bold.otf.woff') format('woff'), - url('OTF/SourceCodePro-Bold.otf') format('opentype'), - url('TTF/SourceCodePro-Bold.ttf') format('truetype'); -} diff --git a/packages/array-normed/docs/assets/github.css b/packages/array-normed/docs/assets/github.css deleted file mode 100644 index 8852abb..0000000 --- a/packages/array-normed/docs/assets/github.css +++ /dev/null @@ -1,123 +0,0 @@ -/* - -github.com style (c) Vasily Polovnyov - -*/ - -.hljs { - display: block; - overflow-x: auto; - padding: 0.5em; - color: #333; - background: #f8f8f8; - -webkit-text-size-adjust: none; -} - -.hljs-comment, -.diff .hljs-header, -.hljs-javadoc { - color: #998; - font-style: italic; -} - -.hljs-keyword, -.css .rule .hljs-keyword, -.hljs-winutils, -.nginx .hljs-title, -.hljs-subst, -.hljs-request, -.hljs-status { - color: #1184CE; -} - -.hljs-number, -.hljs-hexcolor, -.ruby .hljs-constant { - color: #ed225d; -} - -.hljs-string, -.hljs-tag .hljs-value, -.hljs-phpdoc, -.hljs-dartdoc, -.tex .hljs-formula { - color: #ed225d; -} - -.hljs-title, -.hljs-id, -.scss .hljs-preprocessor { - color: #900; - font-weight: bold; -} - -.hljs-list .hljs-keyword, -.hljs-subst { - font-weight: normal; -} - -.hljs-class .hljs-title, -.hljs-type, -.vhdl .hljs-literal, -.tex .hljs-command { - color: #458; - font-weight: bold; -} - -.hljs-tag, -.hljs-tag .hljs-title, -.hljs-rules .hljs-property, -.django .hljs-tag .hljs-keyword { - color: #000080; - font-weight: normal; -} - -.hljs-attribute, -.hljs-variable, -.lisp .hljs-body { - color: #008080; -} - -.hljs-regexp { - color: #009926; -} - -.hljs-symbol, -.ruby .hljs-symbol .hljs-string, -.lisp .hljs-keyword, -.clojure .hljs-keyword, -.scheme .hljs-keyword, -.tex .hljs-special, -.hljs-prompt { - color: #990073; -} - -.hljs-built_in { - color: #0086b3; -} - -.hljs-preprocessor, -.hljs-pragma, -.hljs-pi, -.hljs-doctype, -.hljs-shebang, -.hljs-cdata { - color: #999; - font-weight: bold; -} - -.hljs-deletion { - background: #fdd; -} - -.hljs-addition { - background: #dfd; -} - -.diff .hljs-change { - background: #0086b3; -} - -.hljs-chunk { - color: #aaa; -} diff --git a/packages/array-normed/docs/assets/site.js b/packages/array-normed/docs/assets/site.js deleted file mode 100644 index 28b2a98..0000000 --- a/packages/array-normed/docs/assets/site.js +++ /dev/null @@ -1,168 +0,0 @@ -/* global anchors */ - -// add anchor links to headers -anchors.options.placement = 'left'; -anchors.add('h3'); - -// Filter UI -let tocElements = document.getElementById('toc').getElementsByTagName('li'); - -document.getElementById('filter-input').addEventListener('keyup', function (e) { - let i, element, children; - - // enter key - if (e.keyCode === 13) { - // go to the first displayed item in the toc - for (i = 0; i < tocElements.length; i++) { - element = tocElements[i]; - if (!element.classList.contains('display-none')) { - location.replace(element.firstChild.href); - return e.preventDefault(); - } - } - } - - let match = function () { - return true; - }; - - let value = this.value.toLowerCase(); - - if (!value.match(/^\s*$/)) { - match = function (element) { - let html = element.firstChild.innerHTML; - return html && html.toLowerCase().indexOf(value) !== -1; - }; - } - - for (i = 0; i < tocElements.length; i++) { - element = tocElements[i]; - children = Array.from(element.getElementsByTagName('li')); - if (match(element) || children.some(match)) { - element.classList.remove('display-none'); - } else { - element.classList.add('display-none'); - } - } -}); - -let items = document.getElementsByClassName('toggle-sibling'); -for (let j = 0; j < items.length; j++) { - items[j].addEventListener('click', toggleSibling); -} - -function toggleSibling() { - let stepSibling = this.parentNode.getElementsByClassName('toggle-target')[0]; - let icon = this.getElementsByClassName('icon')[0]; - let klass = 'display-none'; - if (stepSibling.classList.contains(klass)) { - stepSibling.classList.remove(klass); - icon.innerHTML = '▾'; - } else { - stepSibling.classList.add(klass); - icon.innerHTML = '▸'; - } -} - -function showHashTarget(targetId) { - if (targetId) { - let hashTarget = document.getElementById(targetId); - // new target is hidden - if ( - hashTarget && - hashTarget.offsetHeight === 0 && - hashTarget.parentNode.parentNode.classList.contains('display-none') - ) { - hashTarget.parentNode.parentNode.classList.remove('display-none'); - } - } -} - -function scrollIntoView(targetId) { - // Only scroll to element if we don't have a stored scroll position. - if (targetId && !history.state) { - let hashTarget = document.getElementById(targetId); - if (hashTarget) { - hashTarget.scrollIntoView(); - } - } -} - -function gotoCurrentTarget() { - showHashTarget(location.hash.substring(1)); - scrollIntoView(location.hash.substring(1)); -} - -window.addEventListener('hashchange', gotoCurrentTarget); -gotoCurrentTarget(); - -let toclinks = document.getElementsByClassName('pre-open'); -for (let k = 0; k < toclinks.length; k++) { - toclinks[k].addEventListener('mousedown', preOpen, false); -} - -function preOpen() { - showHashTarget(this.hash.substring(1)); -} - -let split_left = document.querySelector('#split-left'); -let split_right = document.querySelector('#split-right'); -let split_parent = split_left.parentNode; -let cw_with_sb = split_left.clientWidth; -split_left.style.overflow = 'hidden'; -let cw_without_sb = split_left.clientWidth; -split_left.style.overflow = ''; - -Split(['#split-left', '#split-right'], { - elementStyle: function (dimension, size, gutterSize) { - return { - 'flex-basis': `calc(${size}% - ${gutterSize}px)`, - }; - }, - gutterStyle: function (dimension, gutterSize) { - return { - 'flex-basis': `${gutterSize}px`, - }; - }, - gutterSize: 20, - sizes: [33, 67], -}); - -// Chrome doesn't remember scroll position properly so do it ourselves. -// Also works on Firefox and Edge. - -function updateState() { - history.replaceState( - { - left_top: split_left.scrollTop, - right_top: split_right.scrollTop, - }, - document.title, - ); -} - -function loadState(ev) { - if (ev) { - // Edge doesn't replace change history.state on popstate. - history.replaceState(ev.state, document.title); - } - if (history.state) { - split_left.scrollTop = history.state.left_top; - split_right.scrollTop = history.state.right_top; - } -} - -window.addEventListener('load', function () { - // Restore after Firefox scrolls to hash. - setTimeout(function () { - loadState(); - // Update with initial scroll position. - updateState(); - // Update scroll positions only after we've loaded because Firefox - // emits an initial scroll event with 0. - split_left.addEventListener('scroll', updateState); - split_right.addEventListener('scroll', updateState); - }, 1); -}); - -window.addEventListener('popstate', loadState); diff --git a/packages/array-normed/docs/assets/split.css b/packages/array-normed/docs/assets/split.css deleted file mode 100644 index 2d7779e..0000000 --- a/packages/array-normed/docs/assets/split.css +++ /dev/null @@ -1,15 +0,0 @@ -.gutter { - background-color: #f5f5f5; - background-repeat: no-repeat; - background-position: 50%; -} - -.gutter.gutter-vertical { - background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAFAQMAAABo7865AAAABlBMVEVHcEzMzMzyAv2sAAAAAXRSTlMAQObYZgAAABBJREFUeF5jOAMEEAIEEFwAn3kMwcB6I2AAAAAASUVORK5CYII='); - cursor: ns-resize; -} - -.gutter.gutter-horizontal { - background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAeCAYAAADkftS9AAAAIklEQVQoU2M4c+bMfxAGAgYYmwGrIIiDjrELjpo5aiZeMwF+yNnOs5KSvgAAAABJRU5ErkJggg=='); - cursor: ew-resize; -} diff --git a/packages/array-normed/docs/assets/split.js b/packages/array-normed/docs/assets/split.js deleted file mode 100644 index 6ff1ea7..0000000 --- a/packages/array-normed/docs/assets/split.js +++ /dev/null @@ -1,798 +0,0 @@ -/*! Split.js - v1.5.11 */ - -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' - ? (module.exports = factory()) - : typeof define === 'function' && define.amd - ? define(factory) - : (global.Split = factory()); -})(this, function () { - // The programming goals of Split.js are to deliver readable, understandable and - // maintainable code, while at the same time manually optimizing for tiny minified file size, - // browser compatibility without additional requirements, graceful fallback (IE8 is supported) - // and very few assumptions about the user's page layout. - let global = window; - let document = global.document; - - // Save a couple long function names that are used frequently. - // This optimization saves around 400 bytes. - let addEventListener = 'addEventListener'; - let removeEventListener = 'removeEventListener'; - let getBoundingClientRect = 'getBoundingClientRect'; - let gutterStartDragging = '_a'; - let aGutterSize = '_b'; - let bGutterSize = '_c'; - let HORIZONTAL = 'horizontal'; - let NOOP = function () { - return false; - }; - - // Figure out if we're in IE8 or not. IE8 will still render correctly, - // but will be static instead of draggable. - let isIE8 = global.attachEvent && !global[addEventListener]; - - // Helper function determines which prefixes of CSS calc we need. - // We only need to do this once on startup, when this anonymous function is called. - // - // Tests -webkit, -moz and -o prefixes. Modified from StackOverflow: - // http://stackoverflow.com/questions/16625140/js-feature-detection-to-detect-the-usage-of-webkit-calc-over-calc/16625167#16625167 - let calc = `${['', '-webkit-', '-moz-', '-o-'] - .filter(function (prefix) { - let el = document.createElement('div'); - el.style.cssText = `width:${prefix}calc(9px)`; - - return !!el.style.length; - }) - .shift()}calc`; - - // Helper function checks if its argument is a string-like type - let isString = function (v) { - return typeof v === 'string' || v instanceof String; - }; - - // Helper function allows elements and string selectors to be used - // interchangeably. In either case an element is returned. This allows us to - // do `Split([elem1, elem2])` as well as `Split(['#id1', '#id2'])`. - let elementOrSelector = function (el) { - if (isString(el)) { - let ele = document.querySelector(el); - if (!ele) { - throw new Error(`Selector ${el} did not match a DOM element`); - } - return ele; - } - - return el; - }; - - // Helper function gets a property from the properties object, with a default fallback - let getOption = function (options, propName, def) { - let value = options[propName]; - if (value !== undefined) { - return value; - } - return def; - }; - - let getGutterSize = function (gutterSize, isFirst, isLast, gutterAlign) { - if (isFirst) { - if (gutterAlign === 'end') { - return 0; - } - if (gutterAlign === 'center') { - return gutterSize / 2; - } - } else if (isLast) { - if (gutterAlign === 'start') { - return 0; - } - if (gutterAlign === 'center') { - return gutterSize / 2; - } - } - - return gutterSize; - }; - - // Default options - let defaultGutterFn = function (i, gutterDirection) { - let gut = document.createElement('div'); - gut.className = `gutter gutter-${gutterDirection}`; - return gut; - }; - - let defaultElementStyleFn = function (dim, size, gutSize) { - let style = {}; - - if (!isString(size)) { - if (!isIE8) { - style[dim] = `${calc}(${size}% - ${gutSize}px)`; - } else { - style[dim] = `${size}%`; - } - } else { - style[dim] = size; - } - - return style; - }; - - let defaultGutterStyleFn = function (dim, gutSize) { - let obj; - - return (obj = {}), (obj[dim] = `${gutSize}px`), obj; - }; - - // The main function to initialize a split. Split.js thinks about each pair - // of elements as an independant pair. Dragging the gutter between two elements - // only changes the dimensions of elements in that pair. This is key to understanding - // how the following functions operate, since each function is bound to a pair. - // - // A pair object is shaped like this: - // - // { - // a: DOM element, - // b: DOM element, - // aMin: Number, - // bMin: Number, - // dragging: Boolean, - // parent: DOM element, - // direction: 'horizontal' | 'vertical' - // } - // - // The basic sequence: - // - // 1. Set defaults to something sane. `options` doesn't have to be passed at all. - // 2. Initialize a bunch of strings based on the direction we're splitting. - // A lot of the behavior in the rest of the library is paramatized down to - // rely on CSS strings and classes. - // 3. Define the dragging helper functions, and a few helpers to go with them. - // 4. Loop through the elements while pairing them off. Every pair gets an - // `pair` object and a gutter. - // 5. Actually size the pair elements, insert gutters and attach event listeners. - let Split = function (idsOption, options) { - if (options === void 0) options = {}; - - let ids = idsOption; - let dimension; - let clientAxis; - let position; - let positionEnd; - let clientSize; - let elements; - - // Allow HTMLCollection to be used as an argument when supported - if (Array.from) { - ids = Array.from(ids); - } - - // All DOM elements in the split should have a common parent. We can grab - // the first elements parent and hope users read the docs because the - // behavior will be whacky otherwise. - let firstElement = elementOrSelector(ids[0]); - let parent = firstElement.parentNode; - let parentStyle = getComputedStyle ? getComputedStyle(parent) : null; - let parentFlexDirection = parentStyle ? parentStyle.flexDirection : null; - - // Set default options.sizes to equal percentages of the parent element. - let sizes = - getOption(options, 'sizes') || - ids.map(function () { - return 100 / ids.length; - }); - - // Standardize minSize to an array if it isn't already. This allows minSize - // to be passed as a number. - let minSize = getOption(options, 'minSize', 100); - let minSizes = Array.isArray(minSize) - ? minSize - : ids.map(function () { - return minSize; - }); - - // Get other options - let expandToMin = getOption(options, 'expandToMin', false); - let gutterSize = getOption(options, 'gutterSize', 10); - let gutterAlign = getOption(options, 'gutterAlign', 'center'); - let snapOffset = getOption(options, 'snapOffset', 30); - let dragInterval = getOption(options, 'dragInterval', 1); - let direction = getOption(options, 'direction', HORIZONTAL); - let cursor = getOption( - options, - 'cursor', - direction === HORIZONTAL ? 'col-resize' : 'row-resize', - ); - let gutter = getOption(options, 'gutter', defaultGutterFn); - let elementStyle = getOption( - options, - 'elementStyle', - defaultElementStyleFn, - ); - let gutterStyle = getOption(options, 'gutterStyle', defaultGutterStyleFn); - - // 2. Initialize a bunch of strings based on the direction we're splitting. - // A lot of the behavior in the rest of the library is paramatized down to - // rely on CSS strings and classes. - if (direction === HORIZONTAL) { - dimension = 'width'; - clientAxis = 'clientX'; - position = 'left'; - positionEnd = 'right'; - clientSize = 'clientWidth'; - } else if (direction === 'vertical') { - dimension = 'height'; - clientAxis = 'clientY'; - position = 'top'; - positionEnd = 'bottom'; - clientSize = 'clientHeight'; - } - - // 3. Define the dragging helper functions, and a few helpers to go with them. - // Each helper is bound to a pair object that contains its metadata. This - // also makes it easy to store references to listeners that that will be - // added and removed. - // - // Even though there are no other functions contained in them, aliasing - // this to self saves 50 bytes or so since it's used so frequently. - // - // The pair object saves metadata like dragging state, position and - // event listener references. - - function setElementSize(el, size, gutSize, i) { - // Split.js allows setting sizes via numbers (ideally), or if you must, - // by string, like '300px'. This is less than ideal, because it breaks - // the fluid layout that `calc(% - px)` provides. You're on your own if you do that, - // make sure you calculate the gutter size by hand. - let style = elementStyle(dimension, size, gutSize, i); - - Object.keys(style).forEach(function (prop) { - // eslint-disable-next-line no-param-reassign - el.style[prop] = style[prop]; - }); - } - - function setGutterSize(gutterElement, gutSize, i) { - let style = gutterStyle(dimension, gutSize, i); - - Object.keys(style).forEach(function (prop) { - // eslint-disable-next-line no-param-reassign - gutterElement.style[prop] = style[prop]; - }); - } - - function getSizes() { - return elements.map(function (element) { - return element.size; - }); - } - - // Supports touch events, but not multitouch, so only the first - // finger `touches[0]` is counted. - function getMousePosition(e) { - if ('touches' in e) { - return e.touches[0][clientAxis]; - } - return e[clientAxis]; - } - - // Actually adjust the size of elements `a` and `b` to `offset` while dragging. - // calc is used to allow calc(percentage + gutterpx) on the whole split instance, - // which allows the viewport to be resized without additional logic. - // Element a's size is the same as offset. b's size is total size - a size. - // Both sizes are calculated from the initial parent percentage, - // then the gutter size is subtracted. - function adjust(offset) { - let a = elements[this.a]; - let b = elements[this.b]; - let percentage = a.size + b.size; - - a.size = (offset / this.size) * percentage; - b.size = percentage - (offset / this.size) * percentage; - - setElementSize(a.element, a.size, this[aGutterSize], a.i); - setElementSize(b.element, b.size, this[bGutterSize], b.i); - } - - // drag, where all the magic happens. The logic is really quite simple: - // - // 1. Ignore if the pair is not dragging. - // 2. Get the offset of the event. - // 3. Snap offset to min if within snappable range (within min + snapOffset). - // 4. Actually adjust each element in the pair to offset. - // - // --------------------------------------------------------------------- - // | | <- a.minSize || b.minSize -> | | - // | | | <- this.snapOffset || this.snapOffset -> | | | - // | | | || | | | - // | | | || | | | - // --------------------------------------------------------------------- - // | <- this.start this.size -> | - function drag(e) { - let offset; - let a = elements[this.a]; - let b = elements[this.b]; - - if (!this.dragging) { - return; - } - - // Get the offset of the event from the first side of the - // pair `this.start`. Then offset by the initial position of the - // mouse compared to the gutter size. - offset = - getMousePosition(e) - - this.start + - (this[aGutterSize] - this.dragOffset); - - if (dragInterval > 1) { - offset = Math.round(offset / dragInterval) * dragInterval; - } - - // If within snapOffset of min or max, set offset to min or max. - // snapOffset buffers a.minSize and b.minSize, so logic is opposite for both. - // Include the appropriate gutter sizes to prevent overflows. - if (offset <= a.minSize + snapOffset + this[aGutterSize]) { - offset = a.minSize + this[aGutterSize]; - } else if ( - offset >= - this.size - (b.minSize + snapOffset + this[bGutterSize]) - ) { - offset = this.size - (b.minSize + this[bGutterSize]); - } - - // Actually adjust the size. - adjust.call(this, offset); - - // Call the drag callback continously. Don't do anything too intensive - // in this callback. - getOption(options, 'onDrag', NOOP)(); - } - - // Cache some important sizes when drag starts, so we don't have to do that - // continously: - // - // `size`: The total size of the pair. First + second + first gutter + second gutter. - // `start`: The leading side of the first element. - // - // ------------------------------------------------ - // | aGutterSize -> ||| | - // | ||| | - // | ||| | - // | ||| <- bGutterSize | - // ------------------------------------------------ - // | <- start size -> | - function calculateSizes() { - // Figure out the parent size minus padding. - let a = elements[this.a].element; - let b = elements[this.b].element; - - let aBounds = a[getBoundingClientRect](); - let bBounds = b[getBoundingClientRect](); - - this.size = - aBounds[dimension] + - bBounds[dimension] + - this[aGutterSize] + - this[bGutterSize]; - this.start = aBounds[position]; - this.end = aBounds[positionEnd]; - } - - function innerSize(element) { - // Return nothing if getComputedStyle is not supported (< IE9) - // Or if parent element has no layout yet - if (!getComputedStyle) { - return null; - } - - let computedStyle = getComputedStyle(element); - - if (!computedStyle) { - return null; - } - - let size = element[clientSize]; - - if (size === 0) { - return null; - } - - if (direction === HORIZONTAL) { - size -= - parseFloat(computedStyle.paddingLeft) + - parseFloat(computedStyle.paddingRight); - } else { - size -= - parseFloat(computedStyle.paddingTop) + - parseFloat(computedStyle.paddingBottom); - } - - return size; - } - - // When specifying percentage sizes that are less than the computed - // size of the element minus the gutter, the lesser percentages must be increased - // (and decreased from the other elements) to make space for the pixels - // subtracted by the gutters. - function trimToMin(sizesToTrim) { - // Try to get inner size of parent element. - // If it's no supported, return original sizes. - let parentSize = innerSize(parent); - if (parentSize === null) { - return sizesToTrim; - } - - if ( - minSizes.reduce(function (a, b) { - return a + b; - }, 0) > parentSize - ) { - return sizesToTrim; - } - - // Keep track of the excess pixels, the amount of pixels over the desired percentage - // Also keep track of the elements with pixels to spare, to decrease after if needed - let excessPixels = 0; - let toSpare = []; - - let pixelSizes = sizesToTrim.map(function (size, i) { - // Convert requested percentages to pixel sizes - let pixelSize = (parentSize * size) / 100; - let elementGutterSize = getGutterSize( - gutterSize, - i === 0, - i === sizesToTrim.length - 1, - gutterAlign, - ); - let elementMinSize = minSizes[i] + elementGutterSize; - - // If element is too smal, increase excess pixels by the difference - // and mark that it has no pixels to spare - if (pixelSize < elementMinSize) { - excessPixels += elementMinSize - pixelSize; - toSpare.push(0); - return elementMinSize; - } - - // Otherwise, mark the pixels it has to spare and return it's original size - toSpare.push(pixelSize - elementMinSize); - return pixelSize; - }); - - // If nothing was adjusted, return the original sizes - if (excessPixels === 0) { - return sizesToTrim; - } - - return pixelSizes.map(function (pixelSize, i) { - let newPixelSize = pixelSize; - - // While there's still pixels to take, and there's enough pixels to spare, - // take as many as possible up to the total excess pixels - if (excessPixels > 0 && toSpare[i] - excessPixels > 0) { - let takenPixels = Math.min(excessPixels, toSpare[i] - excessPixels); - - // Subtract the amount taken for the next iteration - excessPixels -= takenPixels; - newPixelSize = pixelSize - takenPixels; - } - - // Return the pixel size adjusted as a percentage - return (newPixelSize / parentSize) * 100; - }); - } - - // stopDragging is very similar to startDragging in reverse. - function stopDragging() { - let self = this; - let a = elements[self.a].element; - let b = elements[self.b].element; - - if (self.dragging) { - getOption(options, 'onDragEnd', NOOP)(getSizes()); - } - - self.dragging = false; - - // Remove the stored event listeners. This is why we store them. - global[removeEventListener]('mouseup', self.stop); - global[removeEventListener]('touchend', self.stop); - global[removeEventListener]('touchcancel', self.stop); - global[removeEventListener]('mousemove', self.move); - global[removeEventListener]('touchmove', self.move); - - // Clear bound function references - self.stop = null; - self.move = null; - - a[removeEventListener]('selectstart', NOOP); - a[removeEventListener]('dragstart', NOOP); - b[removeEventListener]('selectstart', NOOP); - b[removeEventListener]('dragstart', NOOP); - - a.style.userSelect = ''; - a.style.webkitUserSelect = ''; - a.style.MozUserSelect = ''; - a.style.pointerEvents = ''; - - b.style.userSelect = ''; - b.style.webkitUserSelect = ''; - b.style.MozUserSelect = ''; - b.style.pointerEvents = ''; - - self.gutter.style.cursor = ''; - self.parent.style.cursor = ''; - document.body.style.cursor = ''; - } - - // startDragging calls `calculateSizes` to store the inital size in the pair object. - // It also adds event listeners for mouse/touch events, - // and prevents selection while dragging so avoid the selecting text. - function startDragging(e) { - // Right-clicking can't start dragging. - if ('button' in e && e.button !== 0) { - return; - } - - // Alias frequently used variables to save space. 200 bytes. - let self = this; - let a = elements[self.a].element; - let b = elements[self.b].element; - - // Call the onDragStart callback. - if (!self.dragging) { - getOption(options, 'onDragStart', NOOP)(getSizes()); - } - - // Don't actually drag the element. We emulate that in the drag function. - e.preventDefault(); - - // Set the dragging property of the pair object. - self.dragging = true; - - // Create two event listeners bound to the same pair object and store - // them in the pair object. - self.move = drag.bind(self); - self.stop = stopDragging.bind(self); - - // All the binding. `window` gets the stop events in case we drag out of the elements. - global[addEventListener]('mouseup', self.stop); - global[addEventListener]('touchend', self.stop); - global[addEventListener]('touchcancel', self.stop); - global[addEventListener]('mousemove', self.move); - global[addEventListener]('touchmove', self.move); - - // Disable selection. Disable! - a[addEventListener]('selectstart', NOOP); - a[addEventListener]('dragstart', NOOP); - b[addEventListener]('selectstart', NOOP); - b[addEventListener]('dragstart', NOOP); - - a.style.userSelect = 'none'; - a.style.webkitUserSelect = 'none'; - a.style.MozUserSelect = 'none'; - a.style.pointerEvents = 'none'; - - b.style.userSelect = 'none'; - b.style.webkitUserSelect = 'none'; - b.style.MozUserSelect = 'none'; - b.style.pointerEvents = 'none'; - - // Set the cursor at multiple levels - self.gutter.style.cursor = cursor; - self.parent.style.cursor = cursor; - document.body.style.cursor = cursor; - - // Cache the initial sizes of the pair. - calculateSizes.call(self); - - // Determine the position of the mouse compared to the gutter - self.dragOffset = getMousePosition(e) - self.end; - } - - // adjust sizes to ensure percentage is within min size and gutter. - sizes = trimToMin(sizes); - - // 5. Create pair and element objects. Each pair has an index reference to - // elements `a` and `b` of the pair (first and second elements). - // Loop through the elements while pairing them off. Every pair gets a - // `pair` object and a gutter. - // - // Basic logic: - // - // - Starting with the second element `i > 0`, create `pair` objects with - // `a = i - 1` and `b = i` - // - Set gutter sizes based on the _pair_ being first/last. The first and last - // pair have gutterSize / 2, since they only have one half gutter, and not two. - // - Create gutter elements and add event listeners. - // - Set the size of the elements, minus the gutter sizes. - // - // ----------------------------------------------------------------------- - // | i=0 | i=1 | i=2 | i=3 | - // | | | | | - // | pair 0 pair 1 pair 2 | - // | | | | | - // ----------------------------------------------------------------------- - let pairs = []; - elements = ids.map(function (id, i) { - // Create the element object. - let element = { - element: elementOrSelector(id), - size: sizes[i], - minSize: minSizes[i], - i: i, - }; - - let pair; - - if (i > 0) { - // Create the pair object with its metadata. - pair = { - a: i - 1, - b: i, - dragging: false, - direction: direction, - parent: parent, - }; - - pair[aGutterSize] = getGutterSize( - gutterSize, - i - 1 === 0, - false, - gutterAlign, - ); - pair[bGutterSize] = getGutterSize( - gutterSize, - false, - i === ids.length - 1, - gutterAlign, - ); - - // if the parent has a reverse flex-direction, switch the pair elements. - if ( - parentFlexDirection === 'row-reverse' || - parentFlexDirection === 'column-reverse' - ) { - let temp = pair.a; - pair.a = pair.b; - pair.b = temp; - } - } - - // Determine the size of the current element. IE8 is supported by - // staticly assigning sizes without draggable gutters. Assigns a string - // to `size`. - // - // IE9 and above - if (!isIE8) { - // Create gutter elements for each pair. - if (i > 0) { - let gutterElement = gutter(i, direction, element.element); - setGutterSize(gutterElement, gutterSize, i); - - // Save bound event listener for removal later - pair[gutterStartDragging] = startDragging.bind(pair); - - // Attach bound event listener - gutterElement[addEventListener]( - 'mousedown', - pair[gutterStartDragging], - ); - gutterElement[addEventListener]( - 'touchstart', - pair[gutterStartDragging], - ); - - parent.insertBefore(gutterElement, element.element); - - pair.gutter = gutterElement; - } - } - - setElementSize( - element.element, - element.size, - getGutterSize(gutterSize, i === 0, i === ids.length - 1, gutterAlign), - i, - ); - - // After the first iteration, and we have a pair object, append it to the - // list of pairs. - if (i > 0) { - pairs.push(pair); - } - - return element; - }); - - function adjustToMin(element) { - let isLast = element.i === pairs.length; - let pair = isLast ? pairs[element.i - 1] : pairs[element.i]; - - calculateSizes.call(pair); - - let size = isLast - ? pair.size - element.minSize - pair[bGutterSize] - : element.minSize + pair[aGutterSize]; - - adjust.call(pair, size); - } - - elements.forEach(function (element) { - let computedSize = element.element[getBoundingClientRect]()[dimension]; - - if (computedSize < element.minSize) { - if (expandToMin) { - adjustToMin(element); - } else { - // eslint-disable-next-line no-param-reassign - element.minSize = computedSize; - } - } - }); - - function setSizes(newSizes) { - let trimmed = trimToMin(newSizes); - trimmed.forEach(function (newSize, i) { - if (i > 0) { - let pair = pairs[i - 1]; - - let a = elements[pair.a]; - let b = elements[pair.b]; - - a.size = trimmed[i - 1]; - b.size = newSize; - - setElementSize(a.element, a.size, pair[aGutterSize], a.i); - setElementSize(b.element, b.size, pair[bGutterSize], b.i); - } - }); - } - - function destroy(preserveStyles, preserveGutter) { - pairs.forEach(function (pair) { - if (preserveGutter !== true) { - pair.parent.removeChild(pair.gutter); - } else { - pair.gutter[removeEventListener]( - 'mousedown', - pair[gutterStartDragging], - ); - pair.gutter[removeEventListener]( - 'touchstart', - pair[gutterStartDragging], - ); - } - - if (preserveStyles !== true) { - let style = elementStyle(dimension, pair.a.size, pair[aGutterSize]); - - Object.keys(style).forEach(function (prop) { - elements[pair.a].element.style[prop] = ''; - elements[pair.b].element.style[prop] = ''; - }); - } - }); - } - - if (isIE8) { - return { - setSizes: setSizes, - destroy: destroy, - }; - } - - return { - setSizes: setSizes, - getSizes: getSizes, - collapse: function collapse(i) { - adjustToMin(elements[i]); - }, - destroy: destroy, - parent: parent, - pairs: pairs, - }; - }; - - return Split; -}); diff --git a/packages/array-normed/docs/assets/style.css b/packages/array-normed/docs/assets/style.css deleted file mode 100644 index 0618f43..0000000 --- a/packages/array-normed/docs/assets/style.css +++ /dev/null @@ -1,147 +0,0 @@ -.documentation { - font-family: Helvetica, sans-serif; - color: #666; - line-height: 1.5; - background: #f5f5f5; -} - -.black { - color: #666; -} - -.bg-white { - background-color: #fff; -} - -h4 { - margin: 20px 0 10px 0; -} - -.documentation h3 { - color: #000; -} - -.border-bottom { - border-color: #ddd; -} - -a { - color: #1184ce; - text-decoration: none; -} - -.documentation a[href]:hover { - text-decoration: underline; -} - -a:hover { - cursor: pointer; -} - -.py1-ul li { - padding: 5px 0; -} - -.max-height-100 { - max-height: 100%; -} - -.height-viewport-100 { - height: 100vh; -} - -section:target h3 { - font-weight: 700; -} - -.documentation td, -.documentation th { - padding: 0.25rem 0.25rem; -} - -h1:hover .anchorjs-link, -h2:hover .anchorjs-link, -h3:hover .anchorjs-link, -h4:hover .anchorjs-link { - opacity: 1; -} - -.fix-3 { - width: 25%; - max-width: 244px; -} - -.fix-3 { - width: 25%; - max-width: 244px; -} - -@media (min-width: 52em) { - .fix-margin-3 { - margin-left: 25%; - } -} - -.pre, -pre, -code, -.code { - font-family: Source Code Pro, Menlo, Consolas, Liberation Mono, monospace; - font-size: 14px; -} - -.fill-light { - background: #f9f9f9; -} - -.width2 { - width: 1rem; -} - -.input { - font-family: inherit; - display: block; - width: 100%; - height: 2rem; - padding: 0.5rem; - margin-bottom: 1rem; - border: 1px solid #ccc; - font-size: 0.875rem; - border-radius: 3px; - box-sizing: border-box; -} - -table { - border-collapse: collapse; -} - -.prose table th, -.prose table td { - text-align: left; - padding: 8px; - border: 1px solid #ddd; -} - -.prose table th:nth-child(1) { - border-right: none; -} -.prose table th:nth-child(2) { - border-left: none; -} - -.prose table { - border: 1px solid #ddd; -} - -.prose-big { - font-size: 18px; - line-height: 30px; -} - -.quiet { - opacity: 0.7; -} - -.minishadow { - box-shadow: 2px 2px 10px #f3f3f3; -} diff --git a/packages/array-normed/docs/index.html b/packages/array-normed/docs/index.html deleted file mode 100644 index 607f96f..0000000 --- a/packages/array-normed/docs/index.html +++ /dev/null @@ -1,161 +0,0 @@ - - - - - ml-array-normed 1.1.0 | Documentation - - - - - - - - -
-
-
-

ml-array-normed

-
1.1.0
- -
- -
- -
-
-
- - -
- - - - - -

Computes the norm of the given values

- -
norm(input: Array<number>, options: object): number
- - - - - - - - - - - -
Parameters
-
- -
-
- input (Array<number>) - -
- -
- -
-
- options (object - = {}) - -
- - - - - - - - - - - - - - - - - - - - - - -
NameDescription
options.algorithm string - - (default 'absolute') - absolute, sum or max -
- -
- -
- - - - - - -
Returns
- number: - - - - - - - - - - - - - - - - - -
- - - -
-
- - - - - diff --git a/packages/array-normed/package.json b/packages/array-normed/package.json index ac51443..2f93649 100644 --- a/packages/array-normed/package.json +++ b/packages/array-normed/package.json @@ -2,14 +2,16 @@ "name": "ml-array-normed", "version": "1.3.7", "description": "Normalize the values of a given 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", @@ -23,7 +25,7 @@ }, "homepage": "https://github.com/mljs/array/tree/master/packages/array-mean#readme", "dependencies": { - "is-any-array": "^2.0.0", + "is-any-array": "^3.0.0", "ml-array-max": "^1.2.4", "ml-array-sum": "^1.1.6" } diff --git a/packages/array-normed/src/__tests__/normed.test.js b/packages/array-normed/src/__tests__/normed.test.ts similarity index 79% rename from packages/array-normed/src/__tests__/normed.test.js rename to packages/array-normed/src/__tests__/normed.test.ts index 203e29e..de83c34 100644 --- a/packages/array-normed/src/__tests__/normed.test.js +++ b/packages/array-normed/src/__tests__/normed.test.ts @@ -1,4 +1,6 @@ -import norm from '..'; +import { describe, expect, it } from 'vitest'; + +import norm from '../index.ts'; describe('array-norm', () => { it('should return the norm', () => { @@ -9,10 +11,10 @@ describe('array-norm', () => { }); it('should return the norm algorithm=absolute', () => { - expect(norm([0], { meethod: 'absolute' })).toStrictEqual([0]); - expect(norm([0, 0], { meethod: 'absolute' })).toStrictEqual([0, 0]); - expect(norm([-1, 1], { meethod: 'absolute' })).toStrictEqual([-0.5, 0.5]); - expect(norm([1, 3], { meethod: 'absolute' })).toStrictEqual([0.25, 0.75]); + expect(norm([0], { algorithm: 'absolute' })).toStrictEqual([0]); + expect(norm([0, 0], { algorithm: 'absolute' })).toStrictEqual([0, 0]); + expect(norm([-1, 1], { algorithm: 'absolute' })).toStrictEqual([-0.5, 0.5]); + expect(norm([1, 3], { algorithm: 'absolute' })).toStrictEqual([0.25, 0.75]); }); it('should return the norm algorithm=max', () => { @@ -25,16 +27,13 @@ describe('array-norm', () => { it('should return the norm algorithm=max and max to 100', () => { expect(norm([0], { algorithm: 'max', maxValue: 100 })).toStrictEqual([0]); expect(norm([0, 0], { algorithm: 'max', maxValue: 100 })).toStrictEqual([ - 0, - 0, + 0, 0, ]); expect(norm([-1, 1], { algorithm: 'max', maxValue: 100 })).toStrictEqual([ - -100, - 100, + -100, 100, ]); expect(norm([1, 4], { algorithm: 'max', maxValue: 100 })).toStrictEqual([ - 25, - 100, + 25, 100, ]); }); @@ -49,24 +48,21 @@ describe('array-norm', () => { it('should return the norm algorithm=sum sumValue=5', () => { expect(norm([0], { algorithm: 'sum', sumValue: 5 })).toStrictEqual([0]); expect(norm([0, 0], { algorithm: 'sum', sumValue: 5 })).toStrictEqual([ - 0, - 0, + 0, 0, ]); expect(norm([-1, 1], { algorithm: 'sum', sumValue: 5 })).toStrictEqual([ - -1, - 1, + -1, 1, ]); expect(norm([-1, 3], { algorithm: 'sum', sumValue: 5 })).toStrictEqual([ - -2.5, - 7.5, + -2.5, 7.5, ]); expect(norm([1, 3], { algorithm: 'sum', sumValue: 5 })).toStrictEqual([ - 1.25, - 3.75, + 1.25, 3.75, ]); }); it('should throw on invalid value', () => { + // @ts-expect-error ensure implementation catch missing input expect(() => norm()).toThrow(/input must be an array/); expect(() => norm([])).toThrow(/input must not be empty/); }); diff --git a/packages/array-normed/src/index.js b/packages/array-normed/src/index.js deleted file mode 100644 index d81fcc0..0000000 --- a/packages/array-normed/src/index.js +++ /dev/null @@ -1,62 +0,0 @@ -import { isAnyArray } from 'is-any-array'; -import max from 'ml-array-max'; -import sum from 'ml-array-sum'; - -export default function norm(input, options = {}) { - const { algorithm = 'absolute', sumValue = 1, maxValue = 1 } = options; - if (!isAnyArray(input)) { - throw new Error('input must be an array'); - } - - let output; - if (options.output !== undefined) { - if (!isAnyArray(options.output)) { - throw new TypeError('output option must be an array if specified'); - } - output = options.output; - } else { - output = new Array(input.length); - } - - if (input.length === 0) { - throw new Error('input must not be empty'); - } - - switch (algorithm.toLowerCase()) { - case 'absolute': { - let absoluteSumValue = absoluteSum(input) / sumValue; - if (absoluteSumValue === 0) return input.slice(0); - for (let i = 0; i < input.length; i++) { - output[i] = input[i] / absoluteSumValue; - } - return output; - } - case 'max': { - let currentMaxValue = max(input); - if (currentMaxValue === 0) return input.slice(0); - const factor = maxValue / currentMaxValue; - for (let i = 0; i < input.length; i++) { - output[i] = input[i] * factor; - } - return output; - } - case 'sum': { - let sumFactor = sum(input) / sumValue; - if (sumFactor === 0) return input.slice(0); - for (let i = 0; i < input.length; i++) { - output[i] = input[i] / sumFactor; - } - return output; - } - default: - throw new Error(`norm: unknown algorithm: ${algorithm}`); - } -} - -function absoluteSum(input) { - let sumValue = 0; - for (let i = 0; i < input.length; i++) { - sumValue += Math.abs(input[i]); - } - return sumValue; -} diff --git a/packages/array-normed/src/index.ts b/packages/array-normed/src/index.ts new file mode 100644 index 0000000..04b7283 --- /dev/null +++ b/packages/array-normed/src/index.ts @@ -0,0 +1,95 @@ +import type { AnyArray } from 'is-any-array'; +import { isAnyArray } from 'is-any-array'; +import max from 'ml-array-max'; +import sum from 'ml-array-sum'; + +export interface ArrayNormedOptions> { + /** + * @default 'absolute' + */ + algorithm?: 'absolute' | 'max' | 'sum'; + /** + * New max value for algo 'max'. + * @default 1 + */ + maxValue?: number; + /** + * New max value for algo 'absolute' and 'sum'. + * @default 1 + */ + sumValue?: number; + /** + * Specify the output array. Can be the input array for in place modification. + */ + output?: T; +} + +/** + * Normalize the values of the given array. + */ +export default function norm>( + input: T, + options: ArrayNormedOptions = {}, +): T | number[] { + const { algorithm = 'absolute', sumValue = 1, maxValue = 1 } = options; + if (!isAnyArray(input)) { + throw new Error('input must be an array'); + } + + let output: T | number[]; + if (options.output !== undefined) { + if (!isAnyArray(options.output)) { + throw new TypeError('output option must be an array if specified'); + } + output = options.output; + } else { + output = new Array(input.length); + } + + if (input.length === 0) { + throw new Error('input must not be empty'); + } + + switch (algorithm.toLowerCase()) { + case 'absolute': { + const absoluteSumValue = absoluteSum(input) / sumValue; + if (absoluteSumValue === 0) return input.slice(0) as unknown as T; + for (let i = 0; i < input.length; i++) { + // @ts-expect-error In this context, T should not be readonly so it's OK. + output[i] = input[i] / absoluteSumValue; + } + return output; + } + case 'max': { + const currentMaxValue = max(input); + if (currentMaxValue === 0) return input.slice(0) as unknown as T; + const factor = maxValue / currentMaxValue; + for (let i = 0; i < input.length; i++) { + // @ts-expect-error In this context, T should not be readonly so it's OK. + output[i] = input[i] * factor; + } + return output; + } + case 'sum': { + const sumFactor = sum(input) / sumValue; + if (sumFactor === 0) return input.slice(0) as unknown as T; + for (let i = 0; i < input.length; i++) { + // @ts-expect-error In this context, T should not be readonly so it's OK. + output[i] = input[i] / sumFactor; + } + return output; + } + default: + throw new Error(`norm: unknown algorithm: ${algorithm}`); + } +} + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +type NumberArray = Exclude | number[]; +function absoluteSum(input: NumberArray) { + let sumValue = 0; + for (const value of input) { + sumValue += Math.abs(value); + } + return sumValue; +} diff --git a/packages/array-normed/tsconfig.build.json b/packages/array-normed/tsconfig.build.json new file mode 100644 index 0000000..aa20233 --- /dev/null +++ b/packages/array-normed/tsconfig.build.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "../array-max/tsconfig.json" }, + { "path": "../array-sum/tsconfig.json" } + ], + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-normed/tsconfig.json b/packages/array-normed/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-normed/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-normed/tsconfig.test.json b/packages/array-normed/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-normed/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-normed/types.d.ts b/packages/array-normed/types.d.ts deleted file mode 100644 index 851f817..0000000 --- a/packages/array-normed/types.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -declare namespace mlArrayNormed { - export interface ArrayNormedOptions> { - /** - * @default 'absolute' - */ - algorithm?: 'absolute' | 'max' | 'sum'; - /** - * New max value for algo 'max'. - * @default 1 - */ - maxValue?: number; - /** - * New max value for algo 'absolute' and 'sum'. - * @default 1 - */ - sumValue?: number; - /** - * Specify the output array. Can be the input array for in place modification. - */ - output?: T; - } -} - -/** - * Normalize the values of the given array. - */ -declare function mlArrayNormed>( - array: T, - options?: mlArrayNormed.ArrayNormedOptions, -): number[]; - -export = mlArrayNormed; diff --git a/packages/array-rescale/README.md b/packages/array-rescale/README.md index ba905ab..0e3342b 100644 --- a/packages/array-rescale/README.md +++ b/packages/array-rescale/README.md @@ -1,7 +1,7 @@ # array-rescale - [![NPM version][npm-image]][npm-url] - [![npm download][download-image]][download-url] +[![NPM version][npm-image]][npm-url] +[![npm download][download-image]][download-url] Rescale an array into a range. @@ -15,11 +15,11 @@ Rescale an array into a range. Rescales the values in the `input` so they fit between two new values. -__Options:__ +**Options:** -* `min`: the new minimum value (default: 0) -* `max`: the new maximum value (default: 1) -* `output`: an array to use for output. You can pass `input` here to get an in-place modification. +- `min`: the new minimum value (default: 0) +- `max`: the new maximum value (default: 1) +- `output`: an array to use for output. You can pass `input` here to get an in-place modification. ```js import rescale from 'ml-array-rescale'; @@ -30,7 +30,7 @@ const result = rescale([0, 1, 2, 3, 4]); ## License - [MIT](./LICENSE) +[MIT](./LICENSE) [npm-image]: https://img.shields.io/npm/v/ml-array-rescale.svg?style=flat-square [npm-url]: https://npmjs.org/package/ml-array-rescale diff --git a/packages/array-rescale/package.json b/packages/array-rescale/package.json index d50233c..7c98536 100644 --- a/packages/array-rescale/package.json +++ b/packages/array-rescale/package.json @@ -2,14 +2,16 @@ "name": "ml-array-rescale", "version": "1.3.7", "description": "Rescale an array into a range", - "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", @@ -23,7 +25,7 @@ }, "homepage": "https://github.com/mljs/array/tree/master/packages/array-rescale#readme", "dependencies": { - "is-any-array": "^2.0.0", + "is-any-array": "^3.0.0", "ml-array-max": "^1.2.4", "ml-array-min": "^1.2.3" } diff --git a/packages/array-rescale/src/__tests__/rescale.test.js b/packages/array-rescale/src/__tests__/rescale.test.ts similarity index 88% rename from packages/array-rescale/src/__tests__/rescale.test.js rename to packages/array-rescale/src/__tests__/rescale.test.ts index 2fe3ec6..0df992d 100644 --- a/packages/array-rescale/src/__tests__/rescale.test.js +++ b/packages/array-rescale/src/__tests__/rescale.test.ts @@ -1,7 +1,9 @@ -import rescale from '../index'; +import { describe, expect, it } from 'vitest'; + +import rescale from '../index.ts'; describe('rescale', () => { - let typedArray = new Uint16Array(3); + const typedArray = new Uint16Array(3); typedArray[0] = 1; typedArray[1] = 2; typedArray[2] = 3; @@ -23,6 +25,7 @@ describe('rescale', () => { const array = [0, 1, 2, 3, 4]; const output = new Array(5); rescale(array, { output }); + expect(output).toStrictEqual([0, 0.25, 0.5, 0.75, 1]); expect(array).toStrictEqual([0, 1, 2, 3, 4]); }); @@ -30,6 +33,7 @@ describe('rescale', () => { it('should work in-place', () => { const array = [0, 1, 2, 3, 4]; rescale(array, { output: array }); + expect(array).toStrictEqual([0, 0.25, 0.5, 0.75, 1]); }); @@ -39,21 +43,17 @@ describe('rescale', () => { expect(rescale([0, 1, 2], { min: 0.5 })).toStrictEqual([0.5, 0.75, 1]); expect(rescale([0, 1, 2], { max: 0.5 })).toStrictEqual([0, 0.25, 0.5]); expect(rescale([0, 1, 2], { min: 50, max: 100 })).toStrictEqual([ - 50, - 75, - 100, + 50, 75, 100, ]); expect(rescale([-25, 0, 25, 50, 75], { min: -50, max: 0 })).toStrictEqual([ - -50, - -37.5, - -25, - -12.5, - 0, + -50, -37.5, -25, -12.5, 0, ]); }); it('should throw on bad inputs', () => { + // @ts-expect-error ensure implementation catch missing input expect(() => rescale()).toThrow(/input must be an array/); + // @ts-expect-error ensure implementation catch wrong output option expect(() => rescale([0, 1, 2], { output: false })).toThrow( /output option must be an array if specified/, ); @@ -76,14 +76,10 @@ describe('rescale', () => { it('should work with current min/max', () => { expect(rescale([0, 1, 2], { min: 1, autoMinMax: true })).toStrictEqual([ - 1, - 1.5, - 2, + 1, 1.5, 2, ]); expect(rescale([0, 1, 2], { max: 3, autoMinMax: true })).toStrictEqual([ - 0, - 1.5, - 3, + 0, 1.5, 3, ]); }); }); diff --git a/packages/array-rescale/src/index.js b/packages/array-rescale/src/index.ts similarity index 67% rename from packages/array-rescale/src/index.js rename to packages/array-rescale/src/index.ts index 2c93645..609972e 100644 --- a/packages/array-rescale/src/index.js +++ b/packages/array-rescale/src/index.ts @@ -2,7 +2,33 @@ import { isAnyArray } from 'is-any-array'; import max from 'ml-array-max'; import min from 'ml-array-min'; -export default function rescale(input, options = {}) { +export interface ArrayRescaleOptions> { + /** + * @default 0 + */ + min?: number; + /** + * @default 1 + */ + max?: number; + /** + * If `true` and min or max is undefined take the min or max from input array. + * @default false + */ + autoMinMax?: boolean; + /** + * Specify the output array. Can be the input array for in place modification. + */ + output?: T; +} + +/** + * Rescale an array into a range. + */ +export default function rescale>( + input: T, + options: ArrayRescaleOptions = {}, +): T | number[] { if (!isAnyArray(input)) { throw new TypeError('input must be an array'); } else if (input.length === 0) { diff --git a/packages/array-rescale/tsconfig.build.json b/packages/array-rescale/tsconfig.build.json new file mode 100644 index 0000000..d386d0a --- /dev/null +++ b/packages/array-rescale/tsconfig.build.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "../array-max/tsconfig.json" }, + { "path": "../array-min/tsconfig.json" } + ], + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-rescale/tsconfig.json b/packages/array-rescale/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-rescale/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-rescale/tsconfig.test.json b/packages/array-rescale/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-rescale/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-rescale/types.d.ts b/packages/array-rescale/types.d.ts deleted file mode 100644 index 9d31702..0000000 --- a/packages/array-rescale/types.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -declare namespace mlArrayRescale { - export interface ArrayRescaleOptions> { - /** - * @default 0 - */ - min?: number; - /** - * @default 1 - */ - max?: number; - /** - * If `true` and min or max is undefined take the min or max from input array. - * @default false - */ - autoMinMax?: boolean; - /** - * Specify the output array. Can be the input array for in place modification. - */ - output?: T; - } -} - -/** - * Rescale an array into a range. - */ -declare function mlArrayRescale>( - array: T, - options?: mlArrayRescale.ArrayRescaleOptions, -): number[]; - -export = mlArrayRescale; diff --git a/packages/array-sequential-fill/README.md b/packages/array-sequential-fill/README.md index 28c9b9e..18f9f4e 100644 --- a/packages/array-sequential-fill/README.md +++ b/packages/array-sequential-fill/README.md @@ -1,7 +1,7 @@ # ml-array-sequential-fill - [![NPM version][npm-image]][npm-url] - [![npm download][download-image]][download-url] +[![NPM version][npm-image]][npm-url] +[![npm download][download-image]][download-url] Fill an array with sequential numbers or create a new array containing sequential numbers. @@ -14,25 +14,23 @@ Fill an array with sequential numbers or create a new array containing sequentia ```js import sequentialFill from 'ml-array-sequential-fill'; -var array = sequentialFill({from:0, to:10, size: 6}); +var array = sequentialFill({ from: 0, to: 10, size: 6 }); // array = [0,2,4,6,8,10] // The following alternatives gives the same result -var array = sequentialFill(undefined, {from:0, to:10, size: 6}); -var array = sequentialFill([], {from:0, to:10, size: 6}); -var array = sequentialFill([1,2,3], {from:0, to:10, size: 6}); -var array = sequentialFill({from:0, to:10, step: 2}); +var array = sequentialFill(undefined, { from: 0, to: 10, size: 6 }); +var array = sequentialFill([], { from: 0, to: 10, size: 6 }); +var array = sequentialFill([1, 2, 3], { from: 0, to: 10, size: 6 }); +var array = sequentialFill({ from: 0, to: 10, step: 2 }); ``` -If you provide an array the array will be modified ! If you would like a +If you provide an array the array will be modified ! If you would like a new array you may provide as value 'undefined' or just skip this value. - - ## License - [MIT](./LICENSE) +[MIT](./LICENSE) [npm-image]: https://img.shields.io/npm/v/ml-array-variance.svg?style=flat-square [npm-url]: https://npmjs.org/package/ml-array-variance diff --git a/packages/array-sequential-fill/package.json b/packages/array-sequential-fill/package.json index 30576dd..b526253 100644 --- a/packages/array-sequential-fill/package.json +++ b/packages/array-sequential-fill/package.json @@ -2,14 +2,16 @@ "name": "ml-array-sequential-fill", "version": "1.1.8", "description": "Create an array with sequential numbers", - "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", @@ -23,6 +25,6 @@ }, "homepage": "https://github.com/mljs/array/tree/master/packages/array-variance#readme", "dependencies": { - "is-any-array": "^2.0.0" + "is-any-array": "^3.0.0" } } diff --git a/packages/array-sequential-fill/src/__tests__/sequentialFill.test.js b/packages/array-sequential-fill/src/__tests__/sequentialFill.test.ts similarity index 70% rename from packages/array-sequential-fill/src/__tests__/sequentialFill.test.js rename to packages/array-sequential-fill/src/__tests__/sequentialFill.test.ts index c61eeac..b7445f2 100644 --- a/packages/array-sequential-fill/src/__tests__/sequentialFill.test.js +++ b/packages/array-sequential-fill/src/__tests__/sequentialFill.test.ts @@ -1,81 +1,42 @@ -import sequentialFill from '..'; +import { describe, expect, it } from 'vitest'; + +import sequentialFill from '../index.ts'; describe('array-sequential fill', () => { it('default value', () => { expect(sequentialFill()).toStrictEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); expect(sequentialFill([])).toStrictEqual([ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ]); }); + it('check options', () => { expect(sequentialFill([], { from: 0, to: 10, step: 2 })).toStrictEqual([ - 0, - 2, - 4, - 6, - 8, - 10, + 0, 2, 4, 6, 8, 10, ]); expect(sequentialFill([], { from: 0, to: 10, size: 6 })).toStrictEqual([ - 0, - 2, - 4, - 6, - 8, - 10, + 0, 2, 4, 6, 8, 10, ]); expect( sequentialFill([1, 2, 3, 4, 5, 6], { from: 0, to: 10 }), ).toStrictEqual([0, 2, 4, 6, 8, 10]); expect(sequentialFill([], { from: 0, to: 10, step: 2 })).toStrictEqual([ - 0, - 2, - 4, - 6, - 8, - 10, + 0, 2, 4, 6, 8, 10, ]); expect( sequentialFill(undefined, { from: 0, to: 10, step: 2 }), ).toStrictEqual([0, 2, 4, 6, 8, 10]); expect(sequentialFill({ from: 0, to: 10, step: 2 })).toStrictEqual([ - 0, - 2, - 4, - 6, - 8, - 10, + 0, 2, 4, 6, 8, 10, ]); expect(sequentialFill([], { from: -1, to: 1, size: 5 })).toStrictEqual([ - -1, - -0.5, - 0, - 0.5, - 1, + -1, -0.5, 0, 0.5, 1, ]); expect(sequentialFill([], { from: 0, to: 0, size: 5 })).toStrictEqual([ - 0, - 0, - 0, - 0, - 0, + 0, 0, 0, 0, 0, ]); expect(sequentialFill([], { from: 1, to: -1, size: 5 })).toStrictEqual([ - 1, - 0.5, - 0, - -0.5, - -1, + 1, 0.5, 0, -0.5, -1, ]); expect( Array.from(sequentialFill(new Uint16Array(4), { from: 0, to: 3 })), diff --git a/packages/array-sequential-fill/src/index.js b/packages/array-sequential-fill/src/index.js deleted file mode 100644 index 0014909..0000000 --- a/packages/array-sequential-fill/src/index.js +++ /dev/null @@ -1,59 +0,0 @@ -import { isAnyArray } from 'is-any-array'; - -/** - * Fill an array with sequential numbers - * @param {Array} [input] - optional destination array (if not provided a new array will be created) - * @param {object} [options={}] - * @param {number} [options.from=0] - first value in the array - * @param {number} [options.to=10] - last value in the array - * @param {number} [options.size=input.length] - size of the array (if not provided calculated from step) - * @param {number} [options.step] - if not provided calculated from size - * @return {Array} - */ -export default function sequentialFill(input = [], options = {}) { - if (typeof input === 'object' && !isAnyArray(input)) { - options = input; - input = []; - } - - if (!isAnyArray(input)) { - throw new TypeError('input must be an array'); - } - - let { from = 0, to = 10, size = input.length, step } = options; - - if (size !== 0 && step) { - throw new Error('step is defined by the array size'); - } - - if (!size) { - if (step) { - size = Math.floor((to - from) / step) + 1; - } else { - size = to - from + 1; - } - } - if (!step && size) { - step = (to - from) / (size - 1); - } - if (Array.isArray(input)) { - // only works with normal array - input.length = 0; - for (let i = 0; i < size; i++) { - input.push(from); - from += step; - } - } else { - if (input.length !== size) { - throw new Error( - 'sequentialFill typed array must have the correct length', - ); - } - for (let i = 0; i < size; i++) { - input[i] = from; - from += step; - } - } - - return input; -} diff --git a/packages/array-sequential-fill/src/index.ts b/packages/array-sequential-fill/src/index.ts new file mode 100644 index 0000000..913571a --- /dev/null +++ b/packages/array-sequential-fill/src/index.ts @@ -0,0 +1,98 @@ +import { isAnyArray } from 'is-any-array'; + +export interface ArraySequentialFillOptions { + /** + * First value in the array. + * @default 0 + */ + from?: number; + /** + * Last value in the array. + * @default 10 + */ + to?: number; + /** + * Size of the array. If not provided, calculated from step. + */ + size?: number; + /** + * If not provided, calculated from size. + */ + step?: number; +} + +/** + * Fill an array with sequential numbers. + * + * @param input - The input array to fill + * @param options - The options to drive the filling + */ +function sequentialFill(options?: ArraySequentialFillOptions): number[]; +function sequentialFill>( + input: T, + options?: ArraySequentialFillOptions, +): T; +function sequentialFill( + input: undefined, + options: ArraySequentialFillOptions, +): number[]; +function sequentialFill>( + input?: T, + options: ArraySequentialFillOptions = {}, +): T { + if (!isAnyArray(input)) { + if (typeof input === 'object') { + options = (input as ArraySequentialFillOptions) ?? {}; + } + input = [] as unknown as T; + } + + if (!isAnyArray(input)) { + throw new TypeError('input must be an array'); + } + + let { from = 0, size = input.length, step } = options; + const { to = 10 } = options; + + if (size !== 0 && step) { + throw new Error('step is defined by the array size'); + } + + if (!size) { + if (step) { + size = Math.floor((to - from) / step) + 1; + } else { + size = to - from + 1; + } + } + if (!step && size) { + step = (to - from) / (size - 1); + } + + if (typeof step !== 'number') { + throw new TypeError('No checks initialized the step'); + } + + if (Array.isArray(input)) { + // only works with normal array + input.length = 0; + for (let i = 0; i < size; i++) { + input.push(from); + from += step; + } + } else { + if (input.length !== size) { + throw new Error( + 'sequentialFill typed array must have the correct length', + ); + } + for (let i = 0; i < size; i++) { + input[i] = from; + from += step; + } + } + + return input; +} + +export default sequentialFill; diff --git a/packages/array-sequential-fill/tsconfig.build.json b/packages/array-sequential-fill/tsconfig.build.json new file mode 100644 index 0000000..c63438b --- /dev/null +++ b/packages/array-sequential-fill/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-sequential-fill/tsconfig.json b/packages/array-sequential-fill/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-sequential-fill/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-sequential-fill/tsconfig.test.json b/packages/array-sequential-fill/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-sequential-fill/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-sequential-fill/types.d.ts b/packages/array-sequential-fill/types.d.ts deleted file mode 100644 index 81e0e7c..0000000 --- a/packages/array-sequential-fill/types.d.ts +++ /dev/null @@ -1,35 +0,0 @@ -declare namespace arraySequentialFill { - export interface ArraySequentialFillOptions { - /** - * First value in the array. - * @default 0 - */ - from?: number; - /** - * Last value in the array. - * @default 10 - */ - to?: number; - /** - * Size of the array. If not provided, calculated from step. - */ - size?: number; - /** - * If not provided, calculated from size. - */ - step?: number; - } -} - -/** - * Fill an array with sequential numbers. - */ -declare function arraySequentialFill( - options?: arraySequentialFill.ArraySequentialFillOptions, -): number[]; -declare function arraySequentialFill>( - array: T, - options?: arraySequentialFill.ArraySequentialFillOptions, -): T; - -export = arraySequentialFill; diff --git a/packages/array-standard-deviation/README.md b/packages/array-standard-deviation/README.md index f3fb77c..15f7c6b 100644 --- a/packages/array-standard-deviation/README.md +++ b/packages/array-standard-deviation/README.md @@ -1,7 +1,7 @@ # array-standard-deviation - [![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 standard deviation in an array. @@ -20,7 +20,7 @@ var stdv = standardDeviation(data); ## License - [MIT](./LICENSE) +[MIT](./LICENSE) [npm-image]: https://img.shields.io/npm/v/ml-array-standard-deviation.svg?style=flat-square [npm-url]: https://npmjs.org/package/ml-array-standard-deviation diff --git a/packages/array-standard-deviation/package.json b/packages/array-standard-deviation/package.json index f0f7d92..338cfdf 100644 --- a/packages/array-standard-deviation/package.json +++ b/packages/array-standard-deviation/package.json @@ -2,14 +2,16 @@ "name": "ml-array-standard-deviation", "version": "1.1.8", "description": "Get the standard deviation 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", diff --git a/packages/array-standard-deviation/src/__tests__/standardDeviation.test.js b/packages/array-standard-deviation/src/__tests__/standardDeviation.test.ts similarity index 69% rename from packages/array-standard-deviation/src/__tests__/standardDeviation.test.js rename to packages/array-standard-deviation/src/__tests__/standardDeviation.test.ts index c4b3621..734d2f0 100644 --- a/packages/array-standard-deviation/src/__tests__/standardDeviation.test.js +++ b/packages/array-standard-deviation/src/__tests__/standardDeviation.test.ts @@ -1,22 +1,26 @@ -import standardDeviation from '..'; +import { expect, test } from 'vitest'; -let data = [15, 13, 17, 7]; +import standardDeviation from '../index.ts'; -let typedArray = new Uint16Array(4); +const data = [15, 13, 17, 7]; + +const typedArray = new Uint16Array(4); typedArray[0] = 15; typedArray[1] = 13; typedArray[2] = 17; typedArray[3] = 7; test('standard deviation', () => { - let s = standardDeviation(data); + const s = standardDeviation(data); + expect(s).toBeCloseTo(Math.sqrt(18.667), 3); expect(standardDeviation(data, { unbiased: true })).toBe(s); expect(standardDeviation(data, { unbiased: false })).toBe(Math.sqrt(14)); }); test('standard deviation of typed array', () => { - let s = standardDeviation(typedArray); + const s = standardDeviation(typedArray); + expect(s).toBeCloseTo(Math.sqrt(18.667), 3); expect(standardDeviation(data, { unbiased: true })).toBe(s); expect(standardDeviation(data, { unbiased: false })).toBe(Math.sqrt(14)); diff --git a/packages/array-standard-deviation/src/index.js b/packages/array-standard-deviation/src/index.js deleted file mode 100644 index 042152b..0000000 --- a/packages/array-standard-deviation/src/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import variance from 'ml-array-variance'; - -export default function standardDeviation(values, options = {}) { - return Math.sqrt(variance(values, options)); -} diff --git a/packages/array-standard-deviation/src/index.ts b/packages/array-standard-deviation/src/index.ts new file mode 100644 index 0000000..7512d50 --- /dev/null +++ b/packages/array-standard-deviation/src/index.ts @@ -0,0 +1,23 @@ +import variance from 'ml-array-variance'; + +export interface ArrayStandardDeviationOptions { + /** + * If true, divide by (n-1). If false, divide by n. + * @default true + */ + unbiased?: boolean; + /** + * Precalculated mean. + */ + mean?: number; +} + +/** + * Computes the standard deviation of the given values. + */ +export default function standardDeviation( + array: ArrayLike, + options: ArrayStandardDeviationOptions = {}, +) { + return Math.sqrt(variance(array, options)); +} diff --git a/packages/array-standard-deviation/tsconfig.build.json b/packages/array-standard-deviation/tsconfig.build.json new file mode 100644 index 0000000..c63438b --- /dev/null +++ b/packages/array-standard-deviation/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-standard-deviation/tsconfig.json b/packages/array-standard-deviation/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-standard-deviation/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-standard-deviation/tsconfig.test.json b/packages/array-standard-deviation/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-standard-deviation/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-standard-deviation/types.d.ts b/packages/array-standard-deviation/types.d.ts deleted file mode 100644 index 3aafbed..0000000 --- a/packages/array-standard-deviation/types.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -declare namespace arrayStandardDeviation { - export interface ArrayStandardDeviationOptions { - /** - * If true, divide by (n-1). If false, divide by n. - * @default true - */ - unbiased?: boolean; - /** - * Precalculated mean. - */ - mean?: number; - } -} - -/** - * Computes the standard deviation of the given values. - */ -declare function arrayStandardDeviation( - array: ArrayLike, - options?: arrayStandardDeviation.ArrayStandardDeviationOptions, -): number; - -export = arrayStandardDeviation; diff --git a/packages/array-sum/README.md b/packages/array-sum/README.md index 7ce98aa..f2d3686 100644 --- a/packages/array-sum/README.md +++ b/packages/array-sum/README.md @@ -1,7 +1,7 @@ # array-sum - [![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 sum of the values in an array. @@ -20,7 +20,7 @@ const result = sum([1, 5, 3, 2, 4]); ## License - [MIT](./LICENSE) +[MIT](./LICENSE) [npm-image]: https://img.shields.io/npm/v/ml-array-sum.svg?style=flat-square [npm-url]: https://npmjs.org/package/ml-array-sum diff --git a/packages/array-sum/package.json b/packages/array-sum/package.json index b7309bd..2062ddf 100644 --- a/packages/array-sum/package.json +++ b/packages/array-sum/package.json @@ -2,14 +2,16 @@ "name": "ml-array-sum", "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", @@ -23,6 +25,6 @@ }, "homepage": "https://github.com/mljs/array/tree/master/packages/array-sum#readme", "dependencies": { - "is-any-array": "^2.0.0" + "is-any-array": "^3.0.0" } } diff --git a/packages/array-sum/src/__tests__/sum.test.js b/packages/array-sum/src/__tests__/sum.test.ts similarity index 73% rename from packages/array-sum/src/__tests__/sum.test.js rename to packages/array-sum/src/__tests__/sum.test.ts index 55df41c..c32e589 100644 --- a/packages/array-sum/src/__tests__/sum.test.js +++ b/packages/array-sum/src/__tests__/sum.test.ts @@ -1,7 +1,9 @@ -import sum from '..'; +import { describe, expect, it } from 'vitest'; + +import sum from '../index.ts'; describe('array-sum', () => { - let typedArray = new Uint16Array(3); + const typedArray = new Uint16Array(3); typedArray[0] = 1; typedArray[1] = 2; typedArray[2] = 3; @@ -16,6 +18,7 @@ describe('array-sum', () => { }); it('should throw on invalid value', () => { + // @ts-expect-error ensure implementation catch missing input expect(() => sum()).toThrow(/input must be an array/); expect(() => sum([])).toThrow(/input must not be empty/); }); diff --git a/packages/array-sum/src/index.js b/packages/array-sum/src/index.ts similarity index 61% rename from packages/array-sum/src/index.js rename to packages/array-sum/src/index.ts index 6042607..e1fa2a8 100644 --- a/packages/array-sum/src/index.js +++ b/packages/array-sum/src/index.ts @@ -1,6 +1,9 @@ import { isAnyArray } from 'is-any-array'; -export default function sum(input) { +/** + * Computes the sum of the given values. + */ +export default function sum(input: ArrayLike) { if (!isAnyArray(input)) { throw new TypeError('input must be an array'); } @@ -10,8 +13,8 @@ export default function sum(input) { } let sumValue = 0; - for (let i = 0; i < input.length; i++) { - sumValue += input[i]; + for (const value of input) { + sumValue += value; } return sumValue; } diff --git a/packages/array-sum/tsconfig.build.json b/packages/array-sum/tsconfig.build.json new file mode 100644 index 0000000..c63438b --- /dev/null +++ b/packages/array-sum/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-sum/tsconfig.json b/packages/array-sum/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-sum/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-sum/tsconfig.test.json b/packages/array-sum/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-sum/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-sum/types.d.ts b/packages/array-sum/types.d.ts deleted file mode 100644 index f94379d..0000000 --- a/packages/array-sum/types.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module 'ml-array-sum' { - /** - * Computes the sum of the given values. - */ - function arraySum(array: ArrayLike): number; - export = arraySum; -} diff --git a/packages/array-variance/README.md b/packages/array-variance/README.md index 22a6889..edf862b 100644 --- a/packages/array-variance/README.md +++ b/packages/array-variance/README.md @@ -1,7 +1,7 @@ # array-variance - [![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 variance in an array. @@ -20,7 +20,7 @@ var dataVariance = variance(data); ## License - [MIT](./LICENSE) +[MIT](./LICENSE) [npm-image]: https://img.shields.io/npm/v/ml-array-variance.svg?style=flat-square [npm-url]: https://npmjs.org/package/ml-array-variance diff --git a/packages/array-variance/package.json b/packages/array-variance/package.json index 0dc24a8..138f8b1 100644 --- a/packages/array-variance/package.json +++ b/packages/array-variance/package.json @@ -2,14 +2,16 @@ "name": "ml-array-variance", "version": "1.1.8", "description": "Get the variance 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", @@ -23,7 +25,7 @@ }, "homepage": "https://github.com/mljs/array/tree/master/packages/array-variance#readme", "dependencies": { - "is-any-array": "^2.0.0", + "is-any-array": "^3.0.0", "ml-array-mean": "^1.1.6" } } diff --git a/packages/array-variance/src/__tests__/variance.test.js b/packages/array-variance/src/__tests__/variance.test.ts similarity index 68% rename from packages/array-variance/src/__tests__/variance.test.js rename to packages/array-variance/src/__tests__/variance.test.ts index 2899466..74c10f3 100644 --- a/packages/array-variance/src/__tests__/variance.test.js +++ b/packages/array-variance/src/__tests__/variance.test.ts @@ -1,22 +1,26 @@ -import variance from '..'; +import { describe, expect, it } from 'vitest'; + +import variance from '../index.ts'; describe('variance', () => { it('array', () => { - let data = [15, 13, 17, 7]; - let v = variance(data); + const data = [15, 13, 17, 7]; + const v = variance(data); + expect(v).toBeCloseTo(18.667, 3); expect(variance(data, { unbiased: true })).toBe(v); expect(variance(data, { unbiased: false })).toBe(14); }); it('typed array', () => { - let typedArray = new Uint16Array(4); + const typedArray = new Uint16Array(4); typedArray[0] = 15; typedArray[1] = 13; typedArray[2] = 17; typedArray[3] = 7; - let v = variance(typedArray); + const v = variance(typedArray); + expect(v).toBeCloseTo(18.667, 3); expect(variance(typedArray, { unbiased: true })).toBe(v); expect(variance(typedArray, { unbiased: false })).toBe(14); diff --git a/packages/array-variance/src/index.js b/packages/array-variance/src/index.ts similarity index 51% rename from packages/array-variance/src/index.js rename to packages/array-variance/src/index.ts index 5671b78..6360e87 100644 --- a/packages/array-variance/src/index.js +++ b/packages/array-variance/src/index.ts @@ -1,7 +1,22 @@ import { isAnyArray } from 'is-any-array'; import arrayMean from 'ml-array-mean'; -export default function variance(values, options = {}) { +export interface ArrayVarianceOptions { + /** + * If true, divide by (n-1). If false, divide by n. + * @default true + */ + unbiased?: boolean; + /** + * Precalculated mean. + */ + mean?: number; +} + +export default function variance( + values: ArrayLike, + options: ArrayVarianceOptions = {}, +) { if (!isAnyArray(values)) { throw new TypeError('input must be an array'); } @@ -9,8 +24,8 @@ export default function variance(values, options = {}) { const { unbiased = true, mean = arrayMean(values) } = options; let sqrError = 0; - for (let i = 0; i < values.length; i++) { - let x = values[i] - mean; + for (const value of values) { + const x = value - mean; sqrError += x * x; } diff --git a/packages/array-variance/tsconfig.build.json b/packages/array-variance/tsconfig.build.json new file mode 100644 index 0000000..b5dd8f4 --- /dev/null +++ b/packages/array-variance/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "references": [{ "path": "../array-mean/tsconfig.json" }], + "include": ["src"], + "exclude": ["**/*.test.*"] +} diff --git a/packages/array-variance/tsconfig.json b/packages/array-variance/tsconfig.json new file mode 100644 index 0000000..9048c58 --- /dev/null +++ b/packages/array-variance/tsconfig.json @@ -0,0 +1,10 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./tsconfig.build.json" }, + { "path": "./tsconfig.test.json" } + ] +} diff --git a/packages/array-variance/tsconfig.test.json b/packages/array-variance/tsconfig.test.json new file mode 100644 index 0000000..6d824f2 --- /dev/null +++ b/packages/array-variance/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.json", + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/packages/array-variance/types.d.ts b/packages/array-variance/types.d.ts deleted file mode 100644 index 5e343de..0000000 --- a/packages/array-variance/types.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -declare namespace arrayVariance { - export interface ArrayVarianceOptions { - /** - * If true, divide by (n-1). If false, divide by n. - * @default true - */ - unbiased?: boolean; - /** - * Precalculated mean. - */ - mean?: number; - } -} - -/** - * Computes the variance of the given values. - */ -declare function arrayVariance( - array: ArrayLike, - options?: arrayVariance.ArrayVarianceOptions, -): number; - -export = arrayVariance; diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index 843f7d4..0000000 --- a/rollup.config.js +++ /dev/null @@ -1,32 +0,0 @@ -import babel from '@rollup/plugin-babel'; - -const formats = [ - { format: 'cjs', file: 'lib/index.js', exports: 'auto' }, - { format: 'esm', file: 'lib-es6/index.js' }, -]; - -const config = (opts) => ({ - input: 'src/index.js', - output: opts, - external: [ - 'is-any-array', - 'median-quickselect', - 'ml-array-max', - 'ml-array-min', - 'ml-array-sum', - 'ml-array-mean', - 'ml-array-variance', - ], - plugins: - opts.format === 'esm' - ? [ - babel({ - babelHelpers: 'bundled', - exclude: 'node_modules/**', - presets: ['@babel/env'], - }), - ] - : [], -}); - -export default formats.map(config); diff --git a/src/index.js b/src/index.js index 9160010..9f4adac 100644 --- a/src/index.js +++ b/src/index.js @@ -1,25 +1,11 @@ -import max from '../packages/array-max/src'; -import mean from '../packages/array-mean/src'; -import median from '../packages/array-median/src'; -import min from '../packages/array-min/src'; -import mode from '../packages/array-mode/src'; -import normed from '../packages/array-normed'; -import rescale from '../packages/array-rescale/src'; -import sequentialFill from '../packages/array-sequential-fill/src'; -import sd from '../packages/array-standard-deviation/src'; -import sum from '../packages/array-sum/src'; -import variance from '../packages/array-variance/src'; - -export { - min, - max, - median, - mean, - mode, - normed, - rescale, - sd, - sequentialFill, - sum, - variance, -}; +export { default as max } from '../packages/array-max/src'; +export { default as mean } from '../packages/array-mean/src'; +export { default as median } from '../packages/array-median/src'; +export { default as min } from '../packages/array-min/src'; +export { default as mode } from '../packages/array-mode/src'; +export { default as normed } from '../packages/array-normed'; +export { default as rescale } from '../packages/array-rescale/src'; +export { default as sequentialFill } from '../packages/array-sequential-fill/src'; +export { default as sd } from '../packages/array-standard-deviation/src'; +export { default as sum } from '../packages/array-sum/src'; +export { default as variance } from '../packages/array-variance/src'; diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..f0e9ee4 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,10 @@ +{ + "extends": "@zakodium/tsconfig", + "compilerOptions": { + "rootDir": "${configDir}/src", + "noUncheckedIndexedAccess": false, + "customConditions": ["ml-array-internal"], + "outDir": "${configDir}/lib", + "types": ["node"] + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..599eec0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "files": [], + "references": [ + { "path": "packages/array-max/tsconfig.json" }, + { "path": "packages/array-mean/tsconfig.json" }, + { "path": "packages/array-median/tsconfig.json" }, + { "path": "packages/array-min/tsconfig.json" }, + { "path": "packages/array-mode/tsconfig.json" }, + { "path": "packages/array-normed/tsconfig.json" }, + { "path": "packages/array-rescale/tsconfig.json" }, + { "path": "packages/array-sequential-fill/tsconfig.json" }, + { "path": "packages/array-standard-deviation/tsconfig.json" }, + { "path": "packages/array-sum/tsconfig.json" }, + { "path": "packages/array-variance/tsconfig.json" } + ] +} diff --git a/vitest.config.js b/vitest.config.js new file mode 100644 index 0000000..97be447 --- /dev/null +++ b/vitest.config.js @@ -0,0 +1,15 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + ssr: { + resolve: { + conditions: ['ml-array-internal'], + }, + }, + test: { + coverage: { + include: ['**/src'], + exclude: ['**/lib', '**/docs', '/src'], + }, + }, +});