npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@phutran98/open-ai-helpers

v0.2.6

Published

Helpers function for javascript

Downloads

2

Readme

NX

Create a New Workspace

  • Start by creating a new workspace. We can use the following command that will help us set it up.

npx create-nx-workspace@latest myorg --preset=ts

This command

  • myorg is name of workspace (can you rename for you application)

Create a Package

With nx can you help with scaffolding applications

npx nx generate @nrwl/js:library is-even --publishable --importPath @myorg/is-even

This command 2

  • Uses the @nrwl/js plugin's library generator to scaffold a new library named is-even.
  • The --publishable flag makes sure we also get a package.json generated and a publish target we can invoke to publish to NPM.
  • The --importPath allows us to define the name of the NPM package.

The file structure should look like this

├── dist
├── packages/
├── tools/
├── nx.json
├── package.json
├── README.md
└── tsconfig.base.json

Push your package to NPM

  • npm run build is-even

  • cd /Users/phutran/Documents/package/myorg/dist/packages/is-even

  • update version package => "version": "0.0.3",

  • npm publish

  • npm publish dist/packages/is-odd

  • npm publish dist/packages/is-check-size

Testing

  • npx nx test [is-even] runs the pre-configured Jest tests for the package
  • npx nx test open-ai-helpers

Build

  • npx nx build open-ai-helpers
  • npx nx build [is-odd]
  • npx nx run-many --target=build
  • npx nx affected --target=build RUN NO CACHE

Lint

  • nx run [is-even]:lint

Learn More

  • [DOC README] (https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-text) - Learn about README SYSTAX
  • [DOC NX] (https://nx.dev/) - Learn about nx tool
  • [DOC NPM] (https://docs.npmjs.com/) - Learn about npm

Example & Doc

es5

  const { findLast } = require('@phutran98/open-ai-helpers')

  const input = [1, 2, 3, 4, 5];
  const fn = (elem) => elem > 2;

  console.log('FindLast: ',findLast(input,fn)) // 3

es6

  import { findLast } from '@phutran98/open-ai-helpers'

  const input = [1, 2, 3, 4, 5];
  const fn = (elem) => elem > 2;

  console.log('FindLast: ',findLast(input,fn)) // 3

1.Words

  import { words } from '@phutran98/open-ai-helpers'
  const input = 'Hello world!'

  console.log('Words: ', words(input)) // ['Hello', 'world'];

2.All

  import { all } from '@phutran98/open-ai-helpers'
  const input = [4, 2, 3];

  console.log('All: ', all(input, x => x > 1)) // true

3.allEqual

  import { allEqual } from '@phutran98/open-ai-helpers'
  const input = [4, 2, 3];
  const input2 = [1, 1, 1];

  console.log('allEqual: ',allEqual(input)) // false
  console.log('allEqual: ',allEqual(input2)) // true

4.approximatelyEqual

  import { approximatelyEqual } from '@phutran98/open-ai-helpers'

  console.log('approximatelyEqual: ',approximatelyEqual(Math.PI / 2.0, 1.5708)) // true
  console.log('approximatelyEqual: ',approximatelyEqual(1, 2)) // false

5.arrayToCSV

  import { arrayToCSV } from '@phutran98/open-ai-helpers'

  console.log('arrayToCSV: ',arrayToCSV([['a', 'b'], ['c', 'd']])) // '"a","b"\n"c","d"'
  console.log('arrayToCSVWords: ',arrayToCSV([['a', 'b'], ['c', 'd']], ';')) // '"a";"b"\n"c";"d"'

6.arrayToHtmlList

  import { arrayToHtmlList } from '@phutran98/open-ai-helpers'

  console.log('arrayToHtmlList: ',arrayToHtmlList(['item 1', 'item 2'])) // '<ul><li>item 1</li><li>item 2</li></ul>'

7.average

  import { average } from '@phutran98/open-ai-helpers'

  const input = [1, 2, 3, 4, 5];

  console.log('average: ',average(input)) // 3

8.missingNumber

  import { missingNumber } from '@phutran98/open-ai-helpers'

  const input = [1, 2, 4, 5];

  console.log('missingNumber: ',missingNumber(input)) // 3

9.averageBy

  import { averageBy } from '@phutran98/open-ai-helpers'

  const input = [1, 2, 3, 4];

  console.log('averageBy: ',averageBy(input, val => val)) // 2.5

10.onesAndZeros

  import { onesAndZeros } from '@phutran98/open-ai-helpers'

  const input = '101';

  console.log('result: ', onesAndZeros(input, '1', '0')) // 1

11 validateNumber

  import { validateNumber } from '@phutran98/open-ai-helpers'

  const input1 = 1;
  const input2 = '3.14';
  const input3 = 'abc';

  console.log('result: ', validateNumber(input1)) // true
  console.log('result: ', validateNumber(input2)) // true
  console.log('result: ', validateNumber(input3)) // false

12.toCurrency

  import { toCurrency } from '@phutran98/open-ai-helpers'

  console.log('result: ', toCurrency(1000.5, "USD")) // $1,000.50
  console.log('result: ', toCurrency(-1000.5, "USD")) // -$1,000.50
  console.log('result: ', toCurrency(0, "USD")) // $0.00

13.takeRight

  import { takeRight } from '@phutran98/open-ai-helpers'

  console.log('result: ', takeRight([1, 2, 3, 4, 5], 3)) // [3, 4, 5]
  console.log('result: ', takeRight(["a", "b", "c", "d"], 2)) // ["c", "d"]
  console.log('result: ', takeRight([{ name: "John" }, { name: "Jane" }, { name: "Bob" }])) // [{ name: "Bob" }]
  console.log('result: ', takeRight([1, 2, 3], 0)) // []
  console.log('result: ', takeRight([{ name: "John" }], 2)) // [{ name: "John" }]

14.take

  import { take } from '@phutran98/open-ai-helpers'

  console.log('result: ', take([1, 2, 3], 2)) // [1 , 2]
  console.log('result: ', take(["a", "b", "c", "d"], 3)), // ["a", "b", "c", "d"]
  console.log('result: ', take(["a", "b", "c", "d"])), // ["a"]
  console.log('result: ', take([true, false, true])), // [true]

15.matches

  import { matches } from '@phutran98/open-ai-helpers'

  console.log('result: ', matches([1, 2, 3], 2)) // [1 , 2]
  console.log('result: ', matches(["a", "b", "c", "d"], 3)), // ["a", "b", "c", "d"]
  console.log('result: ', matches(["a", "b", "c", "d"])), // ["a"]
  console.log('result: ', matches([true, false, true])), // [true]

16.isValidJSON

  import { isValidJSON } from '@phutran98/open-ai-helpers'

  console.log('result: ', isValidJSON('{"name":"John","age":30,"city":"New York"}')) // true
  console.log('result: ', isValidJSON('{"name":"John","age":30,"city":"New York"')) // false

17.isSameDate

  import { isSameDate } from '@phutran98/open-ai-helpers'

  const date1 = new Date(2022, 0, 1);
  const date2 = new Date(2022, 0, 1);

  console.log('result: ', isSameDate(date1, date2)) // true

18.isValidDate

  import { isValidDate } from '@phutran98/open-ai-helpers'

  const validDate = new Date("2022-01-01");
  const validDate2 = undefined;

  console.log('result: ', isValidDate(validDate)) // true
  console.log('result: ', isValidDate(validDate2)) // false

19.indexOfAll

  import { indexOfAll } from '@phutran98/open-ai-helpers'

  console.log('result: ', indexOfAll([1, 2, 3, 4, 1], 1)) // [0, 4]
  console.log('result: ', indexOfAll(["a", "b", "a", "c", "d", "a"], "a")) // [0, 2, 5]
  console.log('result: ', indexOfAll([true, false, true, false, true], true)) // [0, 2, 4]

20.groupBy

  import { groupBy } from '@phutran98/open-ai-helpers'
  const arr = [6.1, 4.2, 6.3];

  console.log('result: ', groupBy(arr, Math.floor)) // { '4': [4.2], '6': [6.1, 6.3] }

21.filterNonUnique

  import { filterNonUnique } from '@phutran98/open-ai-helpers'
  const input = [1, 2, 2, 'hello', 'world', 'hello'];

  console.log('result: ', filterNonUnique(input)) // [1, 'world']

22.dropRightWhile

  import { dropRightWhile } from '@phutran98/open-ai-helpers'
  const arr = [1, 2, 3, 4];
  const func = (n: number) => n < 5;
  const func2 = (n: number) => n > 5;

  console.log('result: ', dropRightWhile(arr,func)) // [1, 2, 3, 4]
  console.log('result: ', dropRightWhile(arr,func2)) // []

23.dropRight

  import { dropRight } from '@phutran98/open-ai-helpers'
  const arr = [1, 2, 3, 4];

  console.log('result: ', dropRight(arr)) // [1, 2, 3]
  console.log('result: ', dropRight(arr,2)) // [1, 2]

24.dropRight

  import { dropRight } from '@phutran98/open-ai-helpers'
  const arr = [1, 2, 3, 4];

  console.log('result: ', dropRight(arr)) // [1, 2, 3]
  console.log('result: ', dropRight(arr,2)) // [1, 2]

25.drop

  import { drop } from '@phutran98/open-ai-helpers'
  const arr = [1, 2, 3, 4];

  console.log('result: ', drop(arr)) // [1, 2, 3]
  console.log('result: ', drop(arr,2)) // [3, 4]

26.deepFlatten

  import { deepFlatten } from '@phutran98/open-ai-helpers'
  const arr = [1, 2, [3, [4, 5]], 6];

  console.log('result: ', deepFlatten(arr)) // [1, 2, 3, 4, 5, 6]

27.countOccurrences

  import { countOccurrences } from '@phutran98/open-ai-helpers'
  const arr = [1, 2, 3, 2, 2, 4, 2, 5];
  const val = 2;
  const result = countOccurrences(arr, val); // 4

28.compact

  import { compact } from '@phutran98/open-ai-helpers'
  const input = [0, 1, false, true, '', 'hello', null, undefined, NaN];
  const result = compact(arr, val); // [1, true, 'hello'];

29.checkFalsy

  import { checkFalsy } from '@phutran98/open-ai-helpers'
  const result = checkFalsy(0); // true
  const result = checkFalsy(''); // true
  const result = checkFalsy(1); // false
  const result = checkFalsy('abc'); // false

30.capitalizeEveryWord

  import { capitalizeEveryWord } from '@phutran98/open-ai-helpers'
  const input = 'hello world';
  const result = capitalizeEveryWord(input); // 'Hello World';

  const input2 = 'hello';
  const result2 = capitalizeEveryWord(input2); // Hello

31.camelCase

  import { camelCase } from '@phutran98/open-ai-helpers'
  const input = 'foo bar';
  const result = camelCase(input); // fooBar

  const input2 = '--foo-bar--';
  const result2 = camelCase(input2); // FooBar

32.baseToString

  import { camelCase } from '@phutran98/open-ai-helpers'
  const input = 'foo bar';
  const result = camelCase(input); // fooBar

  const input2 = '--foo-bar--';
  const result2 = camelCase(input2); // FooBar