Skip to content

Commit

Permalink
Refactor using TypeScript, support TypeScript and ES Module (ESM)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoneTone committed Jun 16, 2024
1 parent bcb5ab1 commit f9e3432
Show file tree
Hide file tree
Showing 21 changed files with 5,010 additions and 10,498 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,json,yml}]
charset = utf-8
indent_style = space
indent_size = 2
16 changes: 0 additions & 16 deletions .eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
1 change: 0 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username

custom: ['https://donate.reh.tw/', 'https://paypal.me/GoneTone']
14 changes: 9 additions & 5 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,33 @@ on:
types: [ published ]

jobs:
test:
npm-publish:
runs-on: ${{ matrix.operating-system }}
environment: cd

strategy:
fail-fast: false

matrix:
operating-system: [ ubuntu-latest ]
node-version: [ 16.x ]
node-version: [ 20.x ]

name: NPM Publish
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
run: npm install
run: yarn install

- name: TypeScript Compiler
run: yarn build

- name: Publish
run: npm publish --access public
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
name: CI

on: [push, pull_request]
on:
push:
pull_request:

jobs:
test:
runs-on: ${{ matrix.operating-system }}
environment: ci

strategy:
fail-fast: false

matrix:
operating-system: [ ubuntu-latest ]
node-version: [ 12.x, 14.x, 15.x, 16.x ]
node-version: [ 16.x, 18.x, 20.x ]

name: Node.js ${{ matrix.node-version }} Test on ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: npm ci

- name: Run ESLint
run: npm run lint
run: yarn install --immutable --inline-builds

- name: Jest Tests
run: npm test
run: yarn test
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
/node_modules/
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Swap the comments on the following lines if you wish to use zero-installs
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
# Documentation here: https://yarnpkg.com/features/caching#zero-installs

#!.yarn/cache
.pnp.*

/.idea/
/node_modules/
/dist/
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
node_modules/
.yarn/
19 changes: 19 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"endOfLine": "lf",
"printWidth": 150,
"quoteProps": "as-needed",
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "none",
"useTabs": true,
"overrides": [
{
"files": "*.yml",
"options": {
"tabWidth": 2,
"useTabs": false
}
}
]
}
3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enableGlobalCache: true

nodeLinker: node-modules
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (C) 2021 by GoneTone
Copyright (C) 2024 by GoneTone

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Get YouTube ID By Url (Node.js Library)
# Get YouTube ID By Url (npm Package)

Get YouTube channel or video id by url!

Expand All @@ -10,24 +10,40 @@ Please report any bugs you discover at <https://github.com/GoneToneStudio/node-g

Node.js 12.0.0 or newer is required.

### With NPM
### npm

```sh-session
npm install @gonetone/get-youtube-id-by-url
```

## Examples
### Yarn

```javascript
const { channelId, videoId } = require('@gonetone/get-youtube-id-by-url')
```sh-session
yarn add @gonetone/get-youtube-id-by-url
```

## Usage

### Import package

ES Module (ESM)

```js
import { channelId, videoId } from '@gonetone/get-youtube-id-by-url';
```

CommonJS (CJS)

```js
const { channelId, videoId } = require('@gonetone/get-youtube-id-by-url');
```

### Get YouTube Channel ID By Url

```javascript
```js
channelId('YouTube Channel Url').then((id) => {
console.log(id)
})
console.log(id);
});
```

Support URL format:
Expand All @@ -38,10 +54,10 @@ Support URL format:

### Get YouTube Video ID By Url

```javascript
```js
videoId('YouTube Video Url').then((id) => {
console.log(id)
})
console.log(id);
});
```

Support URL format:
Expand Down
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
Loading

0 comments on commit f9e3432

Please sign in to comment.