-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b248c04
Showing
24 changed files
with
6,482 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github: razonyang | ||
custom: | ||
- https://paypal.me/razonyang | ||
- https://afdian.com/a/razonyang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
ci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm ci | ||
- run: npm run lint | ||
- run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
name: release-please | ||
|
||
jobs: | ||
release-please: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: googleapis/release-please-action@v4 | ||
with: | ||
command: manifest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public/ | ||
resources/ | ||
.hugo_build.lock | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pull_request_rules: | ||
- name: Automatic merge for Renovate pull requests | ||
conditions: | ||
- author=renovate[bot] | ||
actions: | ||
merge: | ||
method: rebase | ||
|
||
- name: Automatic merge on approval | ||
conditions: | ||
- '#approved-reviews-by>=1' | ||
actions: | ||
merge: | ||
method: rebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
".": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/*.tmpl.scss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "@hugomods/stylelint-config", | ||
"rules": { | ||
"at-rule-no-unknown": null, | ||
"color-function-notation": null, | ||
"scss/at-rule-no-unknown": true, | ||
"scss/at-extend-no-missing-placeholder": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 HugoMods Authors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Hugo JSend Module | ||
|
||
[![Used By](https://flat.badgen.net/github/dependents-repo/hugomods/jsend?icon=github&label=used+by&color=green)](https://github.com/hugomods/jsend/network/dependents) | ||
![Hugo Requirements](https://img.shields.io/badge/dynamic/json?color=important&label=requirements&query=requirements&logo=hugo&style=flat-square&url=https://api.razonyang.com/v1/hugo/modules/github.com/hugomods/jsend) | ||
[![License](https://flat.badgen.net/github/license/hugomods/jsend)](https://github.com/hugomods/jsend/blob/main/LICENSE) | ||
[![Version](https://flat.badgen.net/github/tag/hugomods/jsend)](https://github.com/hugomods/jsend/tags) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type Data = unknown; | ||
interface JSend { | ||
status: string; | ||
data?: Data; | ||
code?: number; | ||
message?: string; | ||
} | ||
type ErrorFunc = { | ||
(message: string): JSend; | ||
(message: string, code: number): JSend; | ||
(message: string, code: number, data: Data): JSend; | ||
}; | ||
export declare const error: ErrorFunc; | ||
export declare const fail: (data?: Data) => JSend; | ||
export declare const success: (data?: Data) => JSend; | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { expect, test } from '@jest/globals'; | ||
import { error, fail, success } from './index'; | ||
|
||
test('fail without data', () => { | ||
const rst = fail(); | ||
expect(rst.status).toBe('fail'); | ||
expect(rst.data).toBeNull(); | ||
}); | ||
|
||
test('fail with data', () => { | ||
const data = { | ||
fields: { | ||
title: 'The title is required.', | ||
}, | ||
}; | ||
const rst = fail(data); | ||
expect(rst.status).toBe('fail'); | ||
expect(rst.data).toStrictEqual(data); | ||
}); | ||
|
||
test('error with message', () => { | ||
const message = 'ERROR'; | ||
const rst = error(message); | ||
expect(rst.status).toBe('error'); | ||
expect(rst.message).toStrictEqual(message); | ||
}); | ||
|
||
test('error with message and code', () => { | ||
const message = 'ERROR'; | ||
const code = 10000; | ||
const rst = error(message, code); | ||
expect(rst.status).toBe('error'); | ||
expect(rst.message).toStrictEqual(message); | ||
expect(rst.code).toStrictEqual(code); | ||
}); | ||
|
||
test('error with message, code and data', () => { | ||
const message = 'ERROR'; | ||
const code = 10000; | ||
const data = { | ||
debug: [ | ||
{ | ||
error: 'Unable to communicate with database', | ||
file: '/home/foo/bar/app.js', | ||
line: 8, | ||
}, | ||
], | ||
}; | ||
const rst = error(message, code, data); | ||
expect(rst.status).toBe('error'); | ||
expect(rst.message).toStrictEqual(message); | ||
expect(rst.code).toStrictEqual(code); | ||
}); | ||
|
||
test('success without data', () => { | ||
const rst = success(); | ||
expect(rst.status).toBe('success'); | ||
expect(rst.data).toBeNull(); | ||
}); | ||
|
||
test('success with data', () => { | ||
const data = { | ||
items: [ | ||
{ | ||
title: 'Foo', | ||
}, | ||
{ | ||
title: 'Bar', | ||
}, | ||
], | ||
page: 1, | ||
}; | ||
const rst = success(data); | ||
expect(rst.status).toBe('success'); | ||
expect(rst.data).toStrictEqual(data); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
type Data = unknown; | ||
|
||
interface JSend { | ||
status: string; | ||
data?: Data; | ||
code?: number; | ||
message?: string; | ||
} | ||
|
||
type ErrorFunc = { | ||
(message: string): JSend; | ||
(message: string, code: number): JSend; | ||
(message: string, code: number, data: Data): JSend; | ||
}; | ||
|
||
export const error: ErrorFunc = ( | ||
message: string, | ||
code?: number, | ||
data?: Data, | ||
): JSend => { | ||
const body: JSend = { | ||
status: 'error', | ||
message, | ||
}; | ||
|
||
if (code !== undefined) { | ||
body.code = code; | ||
} | ||
if (data !== undefined) { | ||
body.data = data; | ||
} | ||
|
||
return body; | ||
}; | ||
|
||
export const fail = (data?: Data): JSend => { | ||
return { | ||
status: 'fail', | ||
data: data ?? null, | ||
}; | ||
}; | ||
|
||
export const success = (data?: Data): JSend => { | ||
return { | ||
status: 'success', | ||
data: data ?? null, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import config from '@hugomods/eslint-config'; | ||
import tseslint from 'typescript-eslint'; | ||
|
||
export default tseslint.config(config, { | ||
ignores: ['jest.config.js'], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/hugomods/jsend | ||
|
||
go 1.18 |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} **/ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+.tsx?$': ['ts-jest', {}], | ||
}, | ||
}; |
Oops, something went wrong.