├── .eslintignore
├── .nuxtrc
├── .npmrc
├── renovate.json
├── tsconfig.json
├── .eslintrc
├── .editorconfig
├── playground
├── nuxt.config.ts
└── app.vue
├── .gitignore
├── LICENSE
├── package.json
├── src
└── module.ts
└── README.md
/.eslintignore:
--------------------------------------------------------------------------------
1 | dist
2 | node_modules
3 |
--------------------------------------------------------------------------------
/.nuxtrc:
--------------------------------------------------------------------------------
1 | typescript.includeWorkspace=true
2 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | shamefully-hoist=true
2 | strict-peer-dependencies=false
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "@nuxtjs"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./playground/.nuxt/tsconfig.json"
3 | }
4 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "extends": ["@nuxt/eslint-config"]
4 | }
5 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_size = 2
5 | indent_style = space
6 | end_of_line = lf
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
--------------------------------------------------------------------------------
/playground/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | export default defineNuxtConfig({
2 | modules: ['../src/module'],
3 | radash: {
4 | prefix: '_',
5 | prefixSkip: ['string'],
6 | upperAfterPrefix: true,
7 | alias: [
8 | ['snake', 'stringToSnake'], // => stringToCamelCase
9 | ]
10 | }
11 | })
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Dependencies
2 | node_modules
3 |
4 | # Logs
5 | *.log*
6 |
7 | # Temp directories
8 | .temp
9 | .tmp
10 | .cache
11 |
12 | # Yarn
13 | **/.yarn/cache
14 | **/.yarn/*state*
15 |
16 | # Generated dirs
17 | dist
18 |
19 | # Nuxt
20 | .nuxt
21 | .output
22 | .vercel_build_output
23 | .build-*
24 | .env
25 | .netlify
26 |
27 | # Env
28 | .env
29 |
30 | # Testing
31 | reports
32 | coverage
33 | *.lcov
34 | .nyc_output
35 |
36 | # VSCode
37 | .vscode
38 |
39 | # Intellij idea
40 | *.iml
41 | .idea
42 |
43 | # OSX
44 | .DS_Store
45 | .AppleDouble
46 | .LSOverride
47 | .AppleDB
48 | .AppleDesktop
49 | Network Trash Folder
50 | Temporary Items
51 | .apdisk
52 |
--------------------------------------------------------------------------------
/playground/app.vue:
--------------------------------------------------------------------------------
1 |
30 |
31 |
32 | {{ text }}
33 | {{ min }}
34 | {{ lowerize }}
35 | {{ snake }}
36 |
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Michal Čípa
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nuxt-radash",
3 | "version": "1.0.0",
4 | "description": "radash for Nuxt",
5 | "keywords": [
6 | "nuxt",
7 | "nuxt-module",
8 | "radash"
9 | ],
10 | "repository": {
11 | "type": "git",
12 | "url": "https://github.com/bbg/nuxt-radash"
13 | },
14 | "author": {
15 | "name": "Batuhan Göksu",
16 | "email": "batuhangoksu@gmail.com"
17 | },
18 | "license": "MIT",
19 | "type": "module",
20 | "exports": {
21 | ".": {
22 | "import": "./dist/module.mjs",
23 | "require": "./dist/module.cjs"
24 | }
25 | },
26 | "main": "./dist/module.cjs",
27 | "types": "./dist/types.d.ts",
28 | "files": [
29 | "dist"
30 | ],
31 | "scripts": {
32 | "prepack": "nuxt-module-build --stub && nuxi prepare playground && nuxt-module-build",
33 | "dev": "nuxi dev playground",
34 | "dev:build": "nuxi build playground",
35 | "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground"
36 | },
37 | "dependencies": {
38 | "@nuxt/kit": "^3.6.5",
39 | "radash": "^11.0.0"
40 | },
41 | "devDependencies": {
42 | "@nuxt/devtools": "latest",
43 | "@nuxt/eslint-config": "^0.1.1",
44 | "@nuxt/module-builder": "^0.4.0",
45 | "@nuxt/schema": "^3.6.5",
46 | "@nuxt/test-utils": "^3.6.5",
47 | "@nuxtjs/eslint-config-typescript": "latest",
48 | "@types/node": "^18.17.0",
49 | "eslint": "latest",
50 | "nuxt": "^3.6.0"
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/module.ts:
--------------------------------------------------------------------------------
1 | import { addImports, defineNuxtModule } from "@nuxt/kit";
2 | import * as radash from "radash";
3 |
4 | export interface ModuleOptions {
5 | /**
6 | * Prefix to be added before every radash function
7 | *
8 | * `false` to disable uppercasing
9 | *
10 | * @defaultValue `use`
11 | */
12 | prefix: false | string;
13 | /**
14 | * Functions that starts with this keywords will be skipped by prefix
15 | *
16 | * `false` to disable uppercasing
17 | *
18 | * @defaultValue 'is'
19 | */
20 | prefixSkip: string | string[] | false;
21 | /**
22 | * Iterable of string pairs to alias each function
23 | *
24 | * @defaultValue []
25 | */
26 | alias: Iterable<[string, string]>;
27 | /**
28 | * Upper case first letter after prefix
29 | *
30 | * `false` to disable uppercasing
31 | *
32 | * @defaultValue true
33 | */
34 | upperAfterPrefix: boolean;
35 | }
36 |
37 | export default defineNuxtModule({
38 | meta: {
39 | name: "nuxt-radash",
40 | configKey: "radash",
41 | compatibility: {
42 | nuxt: "^3.0.0",
43 | },
44 | },
45 | defaults: {
46 | prefix: "use",
47 | prefixSkip: "is",
48 | alias: [],
49 | upperAfterPrefix: true,
50 | },
51 | setup(options, nuxt) {
52 | const aliasMap = new Map(options.alias);
53 | const prefixSkip = options.prefixSkip
54 | ? radash.isArray(options.prefixSkip)
55 | ? options.prefixSkip
56 | : [options.prefixSkip]
57 | : [];
58 | for (const name of Object.keys(radash)) {
59 | const alias = aliasMap.has(name) ? aliasMap.get(name)! : name;
60 | const prefix =
61 | (!prefixSkip.some((key) => alias.startsWith(key)) && options.prefix) ||
62 | "";
63 | const as = prefix
64 | ? prefix + (options.upperAfterPrefix ? radash.pascal(alias) : alias)
65 | : alias;
66 | addImports({ name, as, from: "radash" });
67 | }
68 | },
69 | });
70 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Radash for Nuxt
2 |
3 | [Radash](https://radash-docs.vercel.app) auto-import module for [Nuxt](https://nuxtjs.org).
4 |
5 | ## 📦 Install
6 |
7 | Install `nuxt-radash` as development dependency:
8 |
9 | ```bash
10 | npm i nuxt-radash -D
11 | ```
12 |
13 | Add it to the `modules` section of your `nuxt.config`:
14 |
15 | ```ts
16 | export default defineNuxtConfig({
17 | modules: ["nuxt-radash"],
18 | });
19 | ```
20 |
21 | ## 🚀 Example
22 |
23 | Use any [Radash](https://radash-docs.vercel.app/) methods in your Nuxt application, they will be auto-imported!
24 |
25 | ```html
26 |
55 |
56 |
57 | {{ text }}
58 | {{ min }}
59 | {{ lowerize }}
60 | {{ snake }}
61 |
62 | ```
63 |
64 | ## 🔨 Config
65 |
66 | | Name | Default | Description |
67 | | ------------------ | ------- | ------------------------------------------------------------------------------------- |
68 | | `prefix` | `'use'` | String to prepend before each Radash function (false to disable) |
69 | | `prefixSkip` | `'is'` | Functions that starts with this keywords will be skipped by prefix (false to disable) |
70 | | `upperAfterPrefix` | `true` | If true it will automatically uppercase first letter after prefix (false to disable) |
71 | | `alias` | `[]` | Array of array pairs to rename specific Radash functions (prefix is still added) |
72 |
73 | ## 💻 Example - Config
74 |
75 | ```ts
76 | export default defineNuxtConfig({
77 | modules: ["nuxt-radash"],
78 | radash: {
79 | prefix: '_',
80 | prefixSkip: ['string'],
81 | upperAfterPrefix: true,
82 | alias: [
83 | ['snake', 'stringToSnake'], // => stringToSnake
84 | ]
85 | }
86 | });
87 | ```
88 |
89 | ## Acknowledgement
90 | The development of nuxt-radash was made possible thanks to the inspiration and code base from [nuxt-lodash](https://github.com/cipami/nuxt-lodash).
91 |
92 | ## 📄 License
93 |
94 | [MIT License](https://github.com/bbg/nuxt-radash/blob/master/LICENSE) © 2023 - [Batuhan Göksu](https://github.com/bbg)
95 |
--------------------------------------------------------------------------------