Catalog npm
Back to packageRELEASE DETAILS

1.0.1

npm

@0x26e/utils

A TypeScript Utility Collection Similar to Laravel Helpers

helperstypescriptutils
Published30 Aug 2024
Direct dependencies6
Transitive dependenciesNot calculated

README

Current package documentation

@0x26e/utils

A TypeScript Utility Collection Similar to Laravel Helpers.

Instalation

npm install @0x26e/utils

Available Methods

Arrays & Objects

crossJoin

Miscellaneous

Arrays & Objects

crossJoin()

Returns the Cartesian product of the given arrays. The Cartesian product of multiple sets is a set of all possible combinations where each combination contains one element from each input array.

const result = crossJoin([1, 2], ['a', 'b']);
console.log(result);
// Output: [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]

toCssClasses()

The toCssClasses function conditionally compiles a CSS class string. The method accepts an object of classes where the object key contains the class or classes you wish to add, while the value is a boolean expression. If the object key has a numeric key, it will always be included in the rendered class list:

const isActive = false;
const hasError = true;
const classes = toCssClasses([
  'p-4',
  { 'font-bold': isActive, 'bg-red': hasError },
]);
console.log(classes);
// Output: 'p-4 bg-red'

Miscellaneous

blank()

The blank function determines whether the given value is "blank":

blank('');
blank('   ');
blank(null);
blank(collect());

// true

blank(0);
blank(true);
blank(false);

// false

sleep()

Pauses the execution for a specified number of seconds

await sleep(2); // Pauses execution for 2 seconds.

usleep()

Pauses the execution for a specified number of milliseconds.

await usleep(500); // Pauses execution for 500 milliseconds.

tap()

Invokes an interceptor function with a provided value and returns the result.

const tappedValue = tap(5, (n) => n * 2); // tappedValue = 10

until()

Continuously attempts a function until a condition is met.

const result = await until(
  () => isConditionTrue(),
  () => fetchData(),
  2,
);

clamp()

Returns a value clamped to the inclusive range of min and max. This function ensures that the value falls within the specified range. If the value is less than min, it returns min. If the value is greater than max, it returns max. Otherwise, it returns the value itself.

const clamped1 = clamp(5, 1, 10);
console.log(clamped1); // 5

const clamped2 = clamp(15, 1, 10);
console.log(clamped2); // 10 (since 15 is greater than max 10)
const clamped3 = clamp(-5, 1, 10);
console.log(clamped3); // 1 (since -5 is less than min 1)

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 6

Native requirements
6 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
tsup
Environment
{
  "local_name": "tsup",
  "alias": false,
  "peer_metadata": null
}
^8.2.4development
vitest
Environment
{
  "local_name": "vitest",
  "alias": false,
  "peer_metadata": null
}
^2.0.5development
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
^3.3.3development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^5.5.4development
@changesets/cli
Environment
{
  "local_name": "@changesets/cli",
  "alias": false,
  "peer_metadata": null
}
^2.27.7development
@arethetypeswrong/cli
Environment
{
  "local_name": "@arethetypeswrong/cli",
  "alias": false,
  "peer_metadata": null
}
^0.15.4development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "52341abaf8f4a1b0fcd81a05eff7d7817bf19377",
  "tarball": "https://registry.npmjs.org/@0x26e/utils/-/utils-1.0.1.tgz",
  "fileCount": 7,
  "integrity": "sha512-fXX6UapqOI7fm2lFN9qNsMoW2ivvjrX7ValogO74K0t/dDKU4K4gmsGWqq1unTXetbIngSK+3qmAU0qc/2wG9Q==",
  "signatures": [
    {
      "sig": "MEQCIA7xcLL47TG64O3sHSoKK104UQM3i8GRKsuGXEI9CJ0vAiB2fCDX3QldeB30Mpf/SAuSu+wo1C8lkGiYExOi5FX49A==",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 5939
}

Repository

PENDING
foysal50x/js-utils

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:34 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:2a9bacd95df15b287c4728f48c4cd11f339c28093471ef128de82400a0b73c87

Other collected versions

1.0.59 Sept1.0.430 Aug1.0.330 Aug1.0.230 AugView all collected versions →