@opndev/util 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/lib/asArray.mjs +19 -0
- package/lib/index.mjs +7 -1
- package/lib/uniq.mjs +16 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2020-2024 Wesley Schwengle <wesley@opndev.io>
|
|
3
|
+
|
|
4
|
+
SPDX-License-Identifier: MIT
|
|
5
|
+
-->
|
|
6
|
+
|
|
7
|
+
# Welcome to @opndev/util
|
|
8
|
+
|
|
9
|
+
This is a utility function package that tries to solve issues by keeping things
|
|
10
|
+
DRY. It is an ESM package.
|
|
11
|
+
|
|
12
|
+
[If you want to know more, have a look at our documenation](https://opndev.gitlab.io/javascript/opndev-js-util/)
|
|
13
|
+
|
|
14
|
+
## Development
|
|
15
|
+
|
|
16
|
+
Try to keep functions small and try not to depend on any outside functions. We
|
|
17
|
+
aim to keep the dependency graph as small as possible. The use of `esm` is
|
|
18
|
+
welcomed and writing tests is encouraged.
|
|
19
|
+
|
|
20
|
+
### jsdoc
|
|
21
|
+
|
|
22
|
+
You can build the documentation by running `npm run jsdoc`.
|
|
23
|
+
|
|
24
|
+
### eslint
|
|
25
|
+
|
|
26
|
+
The ES Linting profile is flexible and does not try to enforce much. There is
|
|
27
|
+
more than one way to do it ([TIMTOWTDI](https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it)).
|
|
28
|
+
|
|
29
|
+
Try to stay constistent, but forcing a programming style upon others is bad.
|
|
30
|
+
|
|
31
|
+
### gitignore
|
|
32
|
+
|
|
33
|
+
Please educate yourself and use a global gitignore file. Somes files will
|
|
34
|
+
always be there. I'm looking at you `node_modules`.
|
|
35
|
+
|
|
36
|
+
### The lockfiles
|
|
37
|
+
You'll also see that `package-lock.json` and/or `yarn.lock` are ignored. I
|
|
38
|
+
strongly believe that pinning packages lead to bit rot, as you never update
|
|
39
|
+
packages. When a downstream module breaks its API you should know and update
|
|
40
|
+
your code accordingly. The same goes for possible upstream modules. If you want
|
|
41
|
+
a specific version, pin it to that version, otherwise use the latest and
|
|
42
|
+
greatest when possible.
|
|
43
|
+
|
|
44
|
+
### Code of conduct
|
|
45
|
+
|
|
46
|
+
There is none, stay human, communicate and accept that some people have
|
|
47
|
+
different opinions.
|
|
48
|
+
|
|
49
|
+
### Pull requests
|
|
50
|
+
|
|
51
|
+
I'm happy to accept pull requests, just make sure your change has tests.
|
|
52
|
+
Add a good commit message and commit with a sign-off `git commit -s`.
|
|
53
|
+
|
|
54
|
+
A good commit message isn't just `issue(feat): added foo to bar` but also
|
|
55
|
+
explain the why in the commit.
|
package/lib/asArray.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Wesley Schwengle <wesley@opndev.io>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Return an array if something is a scalar. This array-i-fies everything to an
|
|
7
|
+
* array. Perl ref $a ne 'ARRAY' ? [ $a ] : $a
|
|
8
|
+
*
|
|
9
|
+
* @function uniq
|
|
10
|
+
* @param {Anything} needle Anything
|
|
11
|
+
* @returns {Array} An array
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export default function asArray(v) {
|
|
15
|
+
if (v == null) return [];
|
|
16
|
+
return Array.isArray(v) ? v : [v];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { asArray }
|
package/lib/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT
|
|
4
4
|
|
|
5
|
-
const VERSION = "0.0.
|
|
5
|
+
const VERSION = "0.0.10";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
@@ -13,6 +13,10 @@ const VERSION = "0.0.9";
|
|
|
13
13
|
* @exports defined
|
|
14
14
|
* @exports pow_of_two
|
|
15
15
|
* @exports is_pow_of_two
|
|
16
|
+
* @exports uniq
|
|
17
|
+
* @exports ucFirst
|
|
18
|
+
* @exports lcFirst
|
|
19
|
+
* @exports range
|
|
16
20
|
*
|
|
17
21
|
* Export all the useful functions. Unfortunatly, without webpack's
|
|
18
22
|
* require.context we cannot automaticly load everything. So we just keep
|
|
@@ -26,3 +30,5 @@ export { is_pow_of_two } from './ispowtwo.mjs'
|
|
|
26
30
|
export { range } from './range.mjs'
|
|
27
31
|
export { ucFirst } from './ucFirst.mjs'
|
|
28
32
|
export { lcFirst } from './lcFirst.mjs'
|
|
33
|
+
export { uniq } from './uniq.mjs'
|
|
34
|
+
export { asArray } from './asArray.mjs'
|
package/lib/uniq.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Wesley Schwengle <wesley@opndev.io>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Return an array with uniq values
|
|
7
|
+
*
|
|
8
|
+
* @function uniq
|
|
9
|
+
* @param {Array} needle Anything
|
|
10
|
+
* @returns {Array} An array with unique values
|
|
11
|
+
*/
|
|
12
|
+
export default function uniq(arr) {
|
|
13
|
+
return [...new Set(arr.filter((x) => x != null && x !== ""))];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { uniq }
|
package/package.json
CHANGED