Skip to content

Commit

Permalink
feat(utilities): add possibility to import single functions by append…
Browse files Browse the repository at this point in the history
…ing them to the import path. (#454)

Co-authored-by: Jeroen Claassens <support@favware.tech>
  • Loading branch information
imranbarbhuiya and favna committed Oct 2, 2022
1 parent b67192f commit 374c145
Show file tree
Hide file tree
Showing 52 changed files with 446 additions and 87 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -2,3 +2,4 @@ node_modules/
**/dist/
**/docs/
**/*.d.ts
**/coverage/
17 changes: 17 additions & 0 deletions .github/workflows/continuous-integration.yml
Expand Up @@ -113,3 +113,20 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
directory: coverage/
fail_ci_if_error: true

Check_SubPath:
name: Check SubPath
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
- name: Use Node.js v16
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
with:
node-version: 16
cache: yarn
registry-url: https://registry.yarnpkg.org/
- name: Install Dependencies
run: yarn --immutable
- name: Run Script
run: yarn check-subpath -- --check
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -14,7 +14,8 @@
"docs": "turbo run docs",
"update": "yarn upgrade-interactive",
"postinstall": "husky install .github/husky",
"check-update": "turbo run check-update"
"check-update": "turbo run check-update",
"check-subpath": "turbo run check-subpath"
},
"devDependencies": {
"@actions/core": "^1.10.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/cron/src/lib/Cron.ts
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/restrict-plus-operands */
import { range } from '@sapphire/utilities';
import { allowedNum, cronTokens, partRegex, predefined, Time, tokensRegex, wildcardRegex } from './constants';

Expand Down Expand Up @@ -105,7 +104,6 @@ export class Cron {
return [...new Set(res)].sort((a, b) => a - b);
}

// eslint-disable-next-line prefer-const
const [, wild, minStr, maxStr, step] = partRegex.exec(cronPart)!;
let [min, max] = [parseInt(minStr, 10), parseInt(maxStr, 10)];

Expand Down
1 change: 0 additions & 1 deletion packages/decorators/src/utils.ts
Expand Up @@ -89,7 +89,6 @@ export function createFunctionPrecondition(precondition: FunctionPrecondition, f
* @param handler The handler function to modify the constructor behavior for the target
* @hidden
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T {
return new Proxy(target, {
...handler,
Expand Down
@@ -1,4 +1,4 @@
import { Awaitable, isNullish } from '@sapphire/utilities';
import { isNullish, type Awaitable } from '@sapphire/utilities';
import type { CollectorFilter, CollectorOptions, EmojiIdentifierResolvable, Message, MessageReaction, User } from 'discord.js';
import { isTextBasedChannel } from '../../type-guards';
import type { MessagePrompterChannelTypes, MessagePrompterMessage } from '../constants';
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js-utilities/src/lib/type-guards.ts
@@ -1,4 +1,4 @@
import { isNullish, Nullish } from '@sapphire/utilities';
import { isNullish, type Nullish } from '@sapphire/utilities';
import type { APIGuildMember, APIInteractionDataResolvedGuildMember, APIInteractionGuildMember, APIMessage } from 'discord-api-types/v9';
import {
GuildMember,
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js-utilities/src/lib/utilities.ts
@@ -1,4 +1,4 @@
import { isNullish, Nullish } from '@sapphire/utilities';
import { isNullish, type Nullish } from '@sapphire/utilities';
import { Permissions, type VoiceBasedChannel } from 'discord.js';
import { isDMChannel, isGuildBasedChannel, isVoiceBasedChannel } from './type-guards';
import type { ChannelTypes } from './utility-types';
Expand Down
1 change: 0 additions & 1 deletion packages/duration/src/lib/Duration.ts
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/restrict-plus-operands */
const tokens = new Map([
['nanosecond', 1 / 1e6],
['nanoseconds', 1 / 1e6],
Expand Down
1 change: 0 additions & 1 deletion packages/duration/src/lib/DurationFormatter.ts
Expand Up @@ -66,7 +66,6 @@ export interface DurationFormatSeparators {
}

export interface DurationFormatAssetsUnit extends Record<number, string> {
// eslint-disable-next-line @typescript-eslint/naming-convention
DEFAULT: string;
}

Expand Down
1 change: 0 additions & 1 deletion packages/duration/tests/lib/DurationFormatter.test.ts
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/restrict-plus-operands, @typescript-eslint/naming-convention */
import { DurationFormatter } from '../../src';

enum Time {
Expand Down
1 change: 0 additions & 1 deletion packages/event-iterator/tests/index.test.ts
Expand Up @@ -80,7 +80,6 @@ describe('EventIterator', () => {

const iter = emitter.createPeopleIterator({ idle: 500 });

// eslint-disable-next-line @typescript-eslint/no-unused-vars
for await (const {} of iter) {
// Give always false expectation to make this always throw
expect(false).toBe(true);
Expand Down
2 changes: 0 additions & 2 deletions packages/event-iterator/tests/lib/MockEmitter.ts
Expand Up @@ -20,11 +20,9 @@ export class PeopleEmitter extends EventEmitter {
if (this.#emitted === this.#people.length) {
clearInterval(this.#timeout!);
this.#timeout = null;
// eslint-disable-next-line no-unused-expressions
this.#iterator?.end();
this.#iterator = null;
} else {
// eslint-disable-next-line no-unused-expressions
this.emit('testEvent', this.#people[this.#emitted++]);
}
}, 1000);
Expand Down
2 changes: 1 addition & 1 deletion packages/snowflake/src/lib/Snowflake.ts
Expand Up @@ -30,7 +30,7 @@ export class Snowflake {
/**
* Alias for {@link deconstruct}
*/
// eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-invalid-this
// eslint-disable-next-line @typescript-eslint/unbound-method
public decode = this.deconstruct;

/**
Expand Down
1 change: 0 additions & 1 deletion packages/ts-config/.gitignore

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion packages/ts-config/tests/tsconfig.test.ts
@@ -1,4 +1,4 @@
import { testBuild } from '.';
import { testBuild } from './fixture';

describe('TSConfig Test Build', () => {
test('should return param if instanceof string', () => {
Expand Down
14 changes: 14 additions & 0 deletions packages/utilities/README.md
Expand Up @@ -34,6 +34,20 @@ npm install @sapphire/utilities

---

## Usage

You can import individual utility function from subpath like: @sapphire/utility/isFunction or the entire library.

```ts
import { isFunction } from '@sapphire/utilities/isFunction';
// or
import { isFunction } from '@sapphire/utilities';
```

**Note:** For typescript users, subpath import are only supported in `--moduleResolution node16` and `--moduleResolution nodenext`. More information can be found [in this issue on the microsoft/TypeScript repository](https://github.com/microsoft/TypeScript/issues/50794).

---

## Buy us some doughnuts

Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
Expand Down

0 comments on commit 374c145

Please sign in to comment.