@phutran98/open-ai-helpers
TypeScript icon, indicating that this package has built-in type declarations

0.2.6 • Public • Published

NX

GitHub - nrwl/nx-examples: Example repo for Nx workspace

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

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

Package Sidebar

Install

npm i @phutran98/open-ai-helpers

Weekly Downloads

0

Version

0.2.6

License

MIT

Unpacked Size

76.2 kB

Total Files

110

Last publish

Collaborators

  • phutran98