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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ series [How to Contribute to an Open Source Project on GitHub][egghead]
> pull requests from branches on your fork. To do this, run:
>
> ```
> git remote add upstream https://github.com/@feedzai/js-utilities
> git remote add upstream https://github.com/feedzai/js-utilities
> git fetch upstream
> git branch --set-upstream-to=upstream/master master
> git branch --set-upstream-to=upstream/main main
> ```
>
> This will add the original repository as a "remote" called "upstream," Then
> fetch the git information from that remote, then set your local `main`
> branch to use the upstream master branch whenever you run `git pull`. Then you
> branch to use the upstream main branch whenever you run `git pull`. Then you
> can make all of your pull request branches based on this `main` branch.
> Whenever you want to update your version of `main`, do a regular `git pull`.

Expand All @@ -40,5 +40,5 @@ requests! Thanks!

<!-- prettier-ignore-start -->
[egghead]: https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github
[issues]: https://github.com/@feedzai/js-utilities/issues
[issues]: https://github.com/feedzai/js-utilities/issues
<!-- prettier-ignore-end -->
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ It also comes with comprehensive documentation, making it a breeze to navigate a

The package is available in both CommonJS and ES Modules formats so, whether you're working in a traditional environment or embracing the latest ES Modules, we have you covered.

For JavaScript and TypeScript developers seeking a lightweight but robust toolkit that balances simplicity with utility, `@feedzai/js-utilities` might jus be the answer!
For JavaScript and TypeScript developers seeking a lightweight but robust toolkit that balances simplicity with utility, `@feedzai/js-utilities` might just be the answer!

## Table of Contents

Expand Down Expand Up @@ -168,6 +168,7 @@ import * as JS_UTILS from "@feedzai/js-utilities";

| Name | Source |
| ------------------ | ------------------------------------------------------------------------------------------------------- |
| formatDate | [source](https://github.com/feedzai/js-utilities/blob/main/src/functions/dates/format-date.ts) |
| getBrowserTimezone | [source](https://github.com/feedzai/js-utilities/blob/main/src/functions/dates/get-browser-timezone.ts) |

### Events
Expand Down Expand Up @@ -252,6 +253,7 @@ import * as JS_UTILS from "@feedzai/js-utilities";
| ------------------ | -------------------------------------------------------------------------------------------------------- |
| callIfExists | [source](https://github.com/feedzai/js-utilities/blob/main/src/functions/utilities/call-if-exists.ts) |
| emptyFunction | [source](https://github.com/feedzai/js-utilities/blob/main/src/functions/utilities/empty-function.ts) |
| generateUUID | [source](https://github.com/feedzai/js-utilities/blob/main/src/functions/utilities/generate-uuid.ts) |
| makeCancelable | [source](https://github.com/feedzai/js-utilities/blob/main/src/functions/utilities/make-cancelable.ts) |
| throwError | [source](https://github.com/feedzai/js-utilities/blob/main/src/functions/utilities/throw-error.ts) |
| HTTP StatusCodes | [source](https://github.com/feedzai/js-utilities/blob/main/src/functions/constants/http-status-codes.ts) |
Expand All @@ -271,6 +273,8 @@ import * as JS_UTILS from "@feedzai/js-utilities";
| useConstant | [source](https://github.com/feedzai/js-utilities/tree/main/src/hooks/use-constant.ts) |
| useCopyToClipboard | [source](https://github.com/feedzai/js-utilities/tree/main/src/hooks/use-copy-to-clipboard.ts) |
| useEffectOnce | [source](https://github.com/feedzai/js-utilities/tree/main/src/hooks/use-effect-once.ts) |
| useEnsuredForwardedRef | [source](https://github.com/feedzai/js-utilities/tree/main/src/hooks/use-ensured-forwarded-ref.ts) |
| useIntersection | [source](https://github.com/feedzai/js-utilities/tree/main/src/hooks/use-intersection.ts) |
| useLifecycle | [source](https://github.com/feedzai/js-utilities/tree/main/src/hooks/use-lifecycle.ts) |
| useLiveRef | [source](https://github.com/feedzai/js-utilities/tree/main/src/hooks/use-live-ref.ts) |
| useMergeRefs | [source](https://github.com/feedzai/js-utilities/tree/main/src/hooks/use-merge-refs.ts) |
Expand All @@ -288,13 +292,13 @@ To run tests locally:

```
# using npm
npm run test:open
npm run test:unit

# using npm (headless)
npm run test

# using yarn
yarn test:open
yarn test:unit

# using yarn (headless)
yarn test
Expand Down
6 changes: 6 additions & 0 deletions cypress/test/functions/array.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ describe("flatten", () => {
const result = _.flatten(array);
expect(result).to.deep.equal([]);
});

it("should fully flatten when level exceeds the nesting depth", () => {
const array = [1, [2, [3, [4]], 5]];
const result = _.flatten(array, 5);
expect(result).to.deep.equal([1, 2, 3, 4, 5]);
});
});

describe("find", () => {
Expand Down
8 changes: 8 additions & 0 deletions cypress/test/functions/typed.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ describe("isObject", () => {
it("should return false for a new String('')", () => {
expect(_.isObject(new String(""))).to.be.false;
});

it("should return false for an array", () => {
expect(_.isObject([1, 2, 3])).to.be.false;
});

it("should return false for an arrow function", () => {
expect(_.isObject(() => {})).to.be.false;
});
});

describe("isPlainObject", () => {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/functions/arbitrarily/draw.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This helper can also be useful for using inside tests where - given a list of po
## API

```typescript
function random(lower?: number, upper?: number | boolean, floating?: boolean): number;
function draw<T>(array: readonly T[]): T | null;
```

### Usage
Expand Down
9 changes: 4 additions & 5 deletions docs/docs/functions/arrays/flatten.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ const array = [1, [2, [3, [4]], 5]]
flatten(array, true)
// => [1, 2, 3, 4, 5]

flattenDepth(array, 1)
flatten(array, 1)
// => [1, 2, [3, [4]], 5]

flattenDepth(array, 2)
flatten(array, 2)
// => [1, 2, 3, [4], 5]

flatten(array, 5]])
// => [1, 2, [3, [4]], 5]

flatten(array, 5)
// => [1, 2, 3, 4, 5]
```
4 changes: 2 additions & 2 deletions docs/docs/functions/arrays/remove-index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const DATA = [
"Maggie"
];

const SORTED = removeIndex(1);
const RESULT = removeIndex(DATA, 1);

console.log(SORTED) // ["Homer","Lisa","Bart","Maggie"];
console.log(RESULT) // ["Homer","Lisa","Bart","Maggie"];
```
4 changes: 2 additions & 2 deletions docs/docs/functions/arrays/remove-item.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const DATA = [
"Maggie"
];

const SORTED = removeItem("Marge");
const RESULT = removeItem(DATA, "Marge");

console.log(SORTED) // ["Homer","Lisa","Bart","Maggie"];
console.log(RESULT) // ["Homer","Lisa","Bart","Maggie"];
```
2 changes: 1 addition & 1 deletion docs/docs/functions/objects/get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ get(complexObject, 'a[0].bar.c')
// => 3

get(complexObject, ['a', '0', 'bar', 'c'])
// => 2
// => 3

get(simpleObject, 'a.bar.c', 'default')
// => 'default'
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/functions/objects/is-equal.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function isEqual<TType>(x: TType, y: TType): boolean;
### Usage

```typescript
import { has } from '@feedzai/js-utilities';
import { isEqual } from '@feedzai/js-utilities';

isEqual(null, null)
// => true
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/functions/string/kebab-case.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function kebabCase(str: string): string;
### Usage

```typescript
import { random } from '@feedzai/js-utilities';
import { kebabCase } from '@feedzai/js-utilities';

kebabCase('Foo Bar')
// => 'foo-bar'
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/functions/string/readable-string-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ readableStringList(SIMPSONS, "fr", "and");
// 'Homer, Marge, Lisa, Bart et Maggie'

readableStringList(SIMPSONS, "fr", "or");
// 'Homer, Marge, Lisa, Bart our Maggie'
// 'Homer, Marge, Lisa, Bart ou Maggie'

readableStringList(SIMPSONS, "pt", "and");
// 'Homer, Marge, Lisa, Bart e Maggie'
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/functions/string/strip-unit.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: stripUnit
---
Shortens a given number to its shortest form so it can occupy little space as possible.
Removes CSS units from a string-based value, returning the numeric value and the unit separately.

## API

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/functions/string/template.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function template(str: string, data: Record<string, any>, regex?: RegExp): strin
### Usage

```typescript
import { titleCase } from '@feedzai/js-utilities';
import { template } from '@feedzai/js-utilities';

template('Hello, {{name}}', { name: 'ray' })
//-> Hello, ray
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/functions/typed/is-date.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ function isDate(value: any): value is Date;
```typescript
import { isDate } from '@feedzai/js-utilities';

isDate(new Date()))
isDate(new Date())
//-> true

isDate("2024-02-18")
//-> false

isDate(123))
isDate(123)
//-> false

isDate([2024, 2, 18])
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/functions/typed/is-element.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function isElement(value: any): value is Element;
### Usage

```typescript
import { isUndefined } from '@feedzai/js-utilities';
import { isElement } from '@feedzai/js-utilities';

isElement(document.body)
// true
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/functions/typed/is-function.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: isFunction
---
Checks if `value` is classified as a String primitive or object.
Checks if `value` is classified as a Function object.

## API

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/functions/typed/is-object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ isObject({})
// true

isObject([1, 2, 3])
// true
// false

isObject(() => {})
// true
// false

isObject(null)
// false
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/hooks/use-click-outside.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function App(props) {
const DROPDOWN_REF = useRef();

useClickOutside(
DROPDROWN_REF,
DROPDOWN_REF,
() => props.closeDropdown(),
props.shouldClose,
);
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It also comes with comprehensive documentation, making it a breeze to navigate a

The package is available in both CommonJS and ES Modules formats so, whether you're working in a traditional environment or embracing the latest ES Modules, we have you covered.

For JavaScript and TypeScript developers seeking a lightweight but robust toolkit that balances simplicity with utility, `@feedzai/js-utilities` might jus be the answer!
For JavaScript and TypeScript developers seeking a lightweight but robust toolkit that balances simplicity with utility, `@feedzai/js-utilities` might just be the answer!

## Installation

Expand Down
2 changes: 1 addition & 1 deletion src/functions/DOM/toggle-data-attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/**
* Adds a data attribute to a DOM element, without its state bein rendered as a value
* Adds a data attribute to a DOM element, without its state being rendered as a value
*
* @example
*
Expand Down
8 changes: 4 additions & 4 deletions src/functions/array/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
*
* const array = [1, [2, [3, [4]], 5]]
*
* flatten(array, 5]])
* // => [1, 2, [3, [4]], 5]
* flatten(array, 5)
* // => [1, 2, 3, 4, 5]
*
* flatten(array, true)
* // => [1, 2, 3, 4, 5]
*
* flattenDepth(array, 1)
* flatten(array, 1)
* // => [1, 2, [3, [4]], 5]
*
* flattenDepth(array, 2)
* flatten(array, 2)
* // => [1, 2, 3, [4], 5]
*/
export function flatten<T>(arr: T[], level?: number | boolean) {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/object/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { isNil } from "..";
* // => 3
*
* get(complexObject, ['a', '0', 'bar', 'c'])
* // => 2
* // => 3
*
* get(simpleObject, 'a.bar.c', 'default')
* // => 'default'
Expand Down
4 changes: 2 additions & 2 deletions src/functions/typed/is-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* // true
*
* isObject([1, 2, 3])
* // true
* // false
*
* isObject(() => {})
* // true
* // false
*
* isObject(null)
* // false
Expand Down
2 changes: 1 addition & 1 deletion src/functions/utilities/generate-uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function generateFallbackUUID() {
*
* @example
* ```ts
* import { generateUUID } from "@feedzai/react-utilities";
* import { generateUUID } from "@feedzai/js-utilities";
*
* const uuid = generateUUID(); // "123e4567-e89b-12d3-a456-426614174000"
* ```
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/use-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const cachedScripts: string[] = [];
*
* @example
* ```tsx
* import { useSafeLayoutEffect } from '@feedzai/js-utilities/hooks';
* import { useScript } from '@feedzai/js-utilities/hooks';
* ...
* const [loaded, error] = useScript("")
* const [loaded, error] = useScript('')
* ```
*/
export function useScript(
Expand Down
Loading