Skip to content

Commit

Permalink
Setup, @datakit/eslint@0.1.0, @datakit/tx@0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mindrones committed Aug 28, 2024
0 parents commit 8ea4f74
Show file tree
Hide file tree
Showing 28 changed files with 2,492 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_/
**/*.idea.js
**/*.todo.js
coverage/
node_modules/
6 changes: 6 additions & 0 deletions .gitignore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {readFileSync} from 'node:fs';

export const gitIgnoredPatterns =
readFileSync('.gitignore', 'utf8')
.split('\n')
.filter(line => line && !line.startsWith('#'));
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
publish-branch = dev
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Luca Bonavita

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# DataKit

- `@datakit/eslint`: config objects for eslint
- `@datakit/tx`: utilities for data transformation
12 changes: 12 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {jsConfig, jsdocConfig, styleConfig} from '@datakit/eslint';

import {gitIgnoredPatterns} from './.gitignore.js';

export default [
{
ignores: gitIgnoredPatterns,
},
...jsConfig,
...jsdocConfig,
...styleConfig,
];
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"bugs": {
"url": "https://github.com/mindrones/datakit/issues"
},
"description": "A collection of utilities for data transformation and visualisation",
"devDependencies": {
"@datakit/eslint": "workspace:",
"@vitest/coverage-v8": "^2.0.5",
"vitest": "^2.0.5"
},
"homepage": "https://github.com/mindrones/datakit",
"license": "MIT",
"name": "datakit-monorepo",
"private": true,
"scripts": {
"coverage": "vitest run --coverage",
"lint": "eslint",
"publish": "pnpm publish -r",
"publishDry": "pnpm publish -r --dry-run",
"test": "vitest"
},
"type": "module",
"workspaces": [
"packages/*"
]
}
Binary file added packages/eslint/.DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions packages/eslint/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @datakit/eslint

## v0.1.0

Exports `jsConfig`, `styleConfig`, `jsdocConfig`
21 changes: 21 additions & 0 deletions packages/eslint/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Luca Bonavita

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions packages/eslint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `@datakit/eslint`

Eslint configurations to be shared across `@datakit` packages.

This could be used in apps installing `@datakit` packages to maintain
linting and style consistency with those packages.
37 changes: 37 additions & 0 deletions packages/eslint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"bugs": {
"url": "https://github.com/mindrones/datakit/issues"
},
"dependencies": {
"@eslint/js": "^9.9.1",
"@stylistic/eslint-plugin-js": "^2.6.4",
"eslint": "^9.9.1",
"eslint-plugin-jsdoc": "^50.2.2",
"globals": "^15.9.0"
},
"description": "eslint configurations used by @datakit/* packages.",
"files": [
"src/**/*.js",
"!src/**/*.test.js",
"CHANGELOG.md",
"README.md"
],
"homepage": "https://github.com/mindrones/datakit",
"keywords": [
"configuration",
"eslint"
],
"license": "MIT",
"main": "src/index.js",
"name": "@datakit/eslint",
"publishConfig": {
"access": "public"
},
"repository": {
"directory": "packages/eslint",
"type": "git",
"url": "github:mindrones/datakit"
},
"type": "module",
"version": "0.1.0"
}
47 changes: 47 additions & 0 deletions packages/eslint/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pluginJs from '@eslint/js';
import pluginJsStyle from '@stylistic/eslint-plugin-js';
import pluginJsDoc from 'eslint-plugin-jsdoc';
import globals from 'globals';

export const jsConfig = [
{
languageOptions: {
// https://github.com/sindresorhus/globals
// A value of `false` indicates that the variable should be considered read-only.
globals: {
...globals.browser,
...globals.node
}
},
linterOptions: {
reportUnusedDisableDirectives: 'warn'
}
},
pluginJs.configs.recommended, // {rules}
];

export const styleConfig = [
{
plugins: {
'@stylistic/js': pluginJsStyle
},
rules: {
'@stylistic/js/indent': ['warn', 'tab', {
MemberExpression: 'off',
SwitchCase: 1,
}],
'@stylistic/js/quotes': ['warn', 'single', {avoidEscape: true}]
}
},
];

export const jsdocConfig = [
pluginJsDoc.configs['flat/recommended'], // {plugins, rules}
{
rules: {
'jsdoc/require-param-description': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/tag-lines': 'off',
}
},
];
7 changes: 7 additions & 0 deletions packages/tx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @datakit/tx

## v0.1.0

- Re-exports all functions from `@svizzle/utils@0.21.0`
- Re-exports `compare` from `just-compare@2.3.0` as `areEquals`
- add: `getRandomItemOf`, `getRandomIndexOf`, `joinWithNewline`
21 changes: 21 additions & 0 deletions packages/tx/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Luca Bonavita

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions packages/tx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `@datakit/tx`

Utilities for data transformation.

This library re-exports all functions from `@svizzle/utils@0.21.0` and
provides new ones.
36 changes: 36 additions & 0 deletions packages/tx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"bugs": {
"url": "https://github.com/mindrones/datakit/issues"
},
"dependencies": {
"@svizzle/utils": "catalog:",
"just-compare": "catalog:",
"lamb": "catalog:"
},
"description": "Utilities for data transformation.",
"files": [
"src/**/*.js",
"!src/**/*.test.js",
"CHANGELOG.md",
"README.md"
],
"homepage": "https://github.com/mindrones/datakit",
"keywords": [
"@svizzle/utils",
"data transformation",
"functional programming"
],
"license": "MIT",
"main": "src/index.js",
"name": "@datakit/tx",
"publishConfig": {
"access": "public"
},
"repository": {
"directory": "packages/tx",
"type": "git",
"url": "github:mindrones/datakit"
},
"type": "module",
"version": "0.1.0"
}
28 changes: 28 additions & 0 deletions packages/tx/src/array-any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {getRandomIndexOf} from './array-number.js';

/**
* Return a random item of the passed array
*
* @function
* @param {Array} array
* @returns {any}
*
* @example
> getRandomItem = getRandomItemOf([0, 1, 2, 3])
> getRandomItem()
2
> getRandomItem()
1
> getRandomItem = getRandomItemOf([{a: 0}, {a: 1}, {a: 2}, {a: 3}])
> getRandomItem()
{a: 3}
> getRandomItem()
{a: 0}
*
* @since 0.1.0
*/
export const getRandomItemOf = array => {
const index = getRandomIndexOf(array);

return array[index];
}
21 changes: 21 additions & 0 deletions packages/tx/src/array-any.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {makeIsIncluded} from '@svizzle/utils';
import {describe, it, expect} from 'vitest';

import {getRandomItemOf} from './array-any.js';

describe('getRandomItemOf', () => {
it('get a random number in the array', () => {
const nums = [0, 1, 2, 3];
const isIncluded = makeIsIncluded(nums);

const number = getRandomItemOf(nums);
expect(number).toSatisfy(isIncluded);
});
it('get a random object in the array', () => {
const objs = [{a: 0}, {a: 1}, {a: 2}, {a: 3}];
const isIncluded = makeIsIncluded(objs);

const obj = getRandomItemOf(objs);
expect(obj).toSatisfy(isIncluded);
});
});
23 changes: 23 additions & 0 deletions packages/tx/src/array-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as _ from 'lamb';

/**
* Return the index of a random item of the passed array
*
* @function
* @param {Array} array
* @returns {number}
*
* @example
> getRandomIndex = getRandomIndexOf([0, 1, 2, 3])
> getRandomIndex()
2
> getRandomItem()
1
*
* @since 0.1.0
*/
export const getRandomIndexOf = array => {
const index = _.randomInt(0, array.length - 1);

return index;
}
11 changes: 11 additions & 0 deletions packages/tx/src/array-number.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {describe, it, expect} from 'vitest';

import {getRandomIndexOf} from './array-number.js';

describe('getRandomIndexOf', () => {
it('get a random index in the array', () => {
const index = getRandomIndexOf([0, 1, 2, 3]);
expect(index).toBeLessThanOrEqual(3);
expect(index).toBeGreaterThanOrEqual(0);
});
});
19 changes: 19 additions & 0 deletions packages/tx/src/array-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as _ from 'lamb';

/**
* Return a string joining the provided array items with a return
* @see {@link https://ascartabelli.github.io/lamb/module-lamb.html#joinWith|joinWith}
*
* @function
* @param {Array} array
* @returns {string}
*
* @example
> joinWithNewline([1, 2, 3])
'1\n2\n3'
> joinWithNewline(['a', 'b', 'c'])
'a\nb\nc'
*
* @since 0.1.0
*/
export const joinWithNewline = _.joinWith('\n');
Loading

0 comments on commit 8ea4f74

Please sign in to comment.