This commit is contained in:
2022-07-18 02:50:52 +00:00
parent befd344ab0
commit 06181b34d6
8569 changed files with 818704 additions and 352705 deletions
+25
View File
@@ -0,0 +1,25 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [0.2.1](https://github.com/nuxt-contrib/scule/compare/v0.2.0...v0.2.1) (2021-04-28)
## [0.2.0](https://github.com/nuxt-contrib/scule/compare/v0.1.1...v0.2.0) (2021-04-22)
### ⚠ BREAKING CHANGES
* add `exports` field
### Features
* add `exports` field ([6241d0f](https://github.com/nuxt-contrib/scule/commit/6241d0f2b4892c5edc820fb2271b6666ef564af0)), closes [#2](https://github.com/nuxt-contrib/scule/issues/2)
### [0.1.1](https://github.com/nuxt-contrib/scule/compare/v0.1.0...v0.1.1) (2021-02-16)
### Features
* add dot to default splitters ([db5120f](https://github.com/nuxt-contrib/scule/commit/db5120fddf22850255f7c0d1283aad7d8c53cf5b))
### 0.0.1 (2021-02-16)
Generated Vendored
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Nuxt Contrib
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.
+92
View File
@@ -0,0 +1,92 @@
# 🧵 Scule
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions][github-actions-src]][github-actions-href]
[![Codecov][codecov-src]][codecov-href]
[![bundle][bundle-src]][bundle-href]
<!-- ![](.github/banner.svg) -->
## Install
Install using npm or yarn:
```bash
npm i scule
# or
yarn add scule
```
Import:
```js
// CommonJS
const { pascalCase } = require('scule')
// ESM
import { pascalCase } from 'scule'
```
**Notice:** You may need to transpile package for legacy environments
## Utils
### `pascalCase(str)`
Splits string and joins by PascalCase convention (`foo-bar` => `FooBar`)
**Remarks:**
- If an uppercase letter is followed by other uppercase letters (like `FooBAR`), they are preserved
### `camelCase`
Splits string and joins by camelCase convention (`foo-bar` => `fooBar`)
### `kebabCase(str)`
Splits string and joins by kebab-case convention (`fooBar` => `foo-bar`)
**Remarks:**
- It does **not** preserve case
### `snakeCase`
Splits string and joins by snake_case convention (`foo-bar` => `foo_bar`)
### `upperFirst(str)`
Converts first character to upper case
### `lowerFirst(str)`
Converts first character to lower case
### `splitByCase(str, splitters?)`
- Splits string by the splitters provided (default: `['-', '_', '/', '.]`)
- Splits when case changes from lower to upper (only rising edges)
- Case is preserved in returned value
- Is an irreversible function since splitters are omitted
## License
[MIT](./LICENSE)
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/scule?style=flat-square
[npm-version-href]: https://npmjs.com/package/scule
[npm-downloads-src]: https://img.shields.io/npm/dm/scule?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/scule
[github-actions-src]: https://img.shields.io/github/workflow/status/nuxt-contrib/scule/ci/main?style=flat-square
[github-actions-href]: https://github.com/nuxt-contrib/scule/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/nuxt-contrib/scule/main?style=flat-square
[codecov-href]: https://codecov.io/gh/nuxt-contrib/scule
[bundle-src]: https://img.shields.io/bundlephobia/minzip/scule?style=flat-square
[bundle-href]: https://bundlephobia.com/result?p=scule
+10
View File
@@ -0,0 +1,10 @@
declare function isUppercase(char?: string): boolean;
declare function splitByCase(str: string, splitters?: string[]): string[];
declare function upperFirst(str: string): string;
declare function lowerFirst(str: string): string;
declare function pascalCase(str?: string | string[]): string;
declare function camelCase(str?: string | string[]): string;
declare function kebabCase(str?: string | string[], joiner?: string): string;
declare function snakeCase(str?: string | string[]): string;
export { camelCase, isUppercase, kebabCase, lowerFirst, pascalCase, snakeCase, splitByCase, upperFirst };
+69
View File
@@ -0,0 +1,69 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function isUppercase(char = "") {
return char.toUpperCase() === char;
}
const STR_SPLITTERS = ["-", "_", "/", "."];
function splitByCase(str, splitters = STR_SPLITTERS) {
const parts = [];
let buff = "";
let previusUpper = isUppercase(str[0]);
let previousSplitter = splitters.includes(str[0]);
for (const char of str.split("")) {
const isSplitter = splitters.includes(char);
if (isSplitter) {
parts.push(buff);
buff = "";
previusUpper = false;
previousSplitter = true;
} else if (!previousSplitter && !previusUpper && isUppercase(char)) {
parts.push(buff);
buff = char;
previusUpper = true;
previousSplitter = false;
} else {
buff += char;
previusUpper = isUppercase(char);
previousSplitter = isSplitter;
}
}
if (buff) {
parts.push(buff);
}
return parts;
}
function upperFirst(str) {
if (!str) {
return "";
}
return str[0].toUpperCase() + str.substr(1);
}
function lowerFirst(str) {
if (!str) {
return "";
}
return str[0].toLocaleLowerCase() + str.substr(1);
}
function pascalCase(str = "") {
return (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(p)).join("");
}
function camelCase(str = "") {
return lowerFirst(pascalCase(str));
}
function kebabCase(str = "", joiner = "-") {
return (Array.isArray(str) ? str : splitByCase(str)).map((p = "") => p.toLocaleLowerCase()).join(joiner);
}
function snakeCase(str = "") {
return kebabCase(str, "_");
}
exports.camelCase = camelCase;
exports.isUppercase = isUppercase;
exports.kebabCase = kebabCase;
exports.lowerFirst = lowerFirst;
exports.pascalCase = pascalCase;
exports.snakeCase = snakeCase;
exports.splitByCase = splitByCase;
exports.upperFirst = upperFirst;
+58
View File
@@ -0,0 +1,58 @@
function isUppercase(char = "") {
return char.toUpperCase() === char;
}
const STR_SPLITTERS = ["-", "_", "/", "."];
function splitByCase(str, splitters = STR_SPLITTERS) {
const parts = [];
let buff = "";
let previusUpper = isUppercase(str[0]);
let previousSplitter = splitters.includes(str[0]);
for (const char of str.split("")) {
const isSplitter = splitters.includes(char);
if (isSplitter) {
parts.push(buff);
buff = "";
previusUpper = false;
previousSplitter = true;
} else if (!previousSplitter && !previusUpper && isUppercase(char)) {
parts.push(buff);
buff = char;
previusUpper = true;
previousSplitter = false;
} else {
buff += char;
previusUpper = isUppercase(char);
previousSplitter = isSplitter;
}
}
if (buff) {
parts.push(buff);
}
return parts;
}
function upperFirst(str) {
if (!str) {
return "";
}
return str[0].toUpperCase() + str.substr(1);
}
function lowerFirst(str) {
if (!str) {
return "";
}
return str[0].toLocaleLowerCase() + str.substr(1);
}
function pascalCase(str = "") {
return (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(p)).join("");
}
function camelCase(str = "") {
return lowerFirst(pascalCase(str));
}
function kebabCase(str = "", joiner = "-") {
return (Array.isArray(str) ? str : splitByCase(str)).map((p = "") => p.toLocaleLowerCase()).join(joiner);
}
function snakeCase(str = "") {
return kebabCase(str, "_");
}
export { camelCase, isUppercase, kebabCase, lowerFirst, pascalCase, snakeCase, splitByCase, upperFirst };
+75
View File
@@ -0,0 +1,75 @@
{
"_args": [
[
"scule@0.2.1",
"/home/node/nuxt"
]
],
"_from": "scule@0.2.1",
"_id": "scule@0.2.1",
"_inBundle": false,
"_integrity": "sha512-M9gnWtn3J0W+UhJOHmBxBTwv8mZCan5i1Himp60t6vvZcor0wr+IM0URKmIglsWJ7bRujNAVVN77fp+uZaWoKg==",
"_location": "/scule",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "scule@0.2.1",
"name": "scule",
"escapedName": "scule",
"rawSpec": "0.2.1",
"saveSpec": null,
"fetchSpec": "0.2.1"
},
"_requiredBy": [
"/@nuxt/components"
],
"_resolved": "https://registry.npmjs.org/scule/-/scule-0.2.1.tgz",
"_spec": "0.2.1",
"_where": "/home/node/nuxt",
"bugs": {
"url": "https://github.com/nuxt-contrib/scule/issues"
},
"description": "[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href] [![bundle][bundle-src]][bundle-href]",
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"@types/flat": "latest",
"@types/jest": "latest",
"@types/node": "latest",
"eslint": "latest",
"jest": "latest",
"siroc": "latest",
"standard-version": "latest",
"ts-jest": "latest",
"typescript": "latest"
},
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": "./*"
},
"files": [
"dist"
],
"homepage": "https://github.com/nuxt-contrib/scule#readme",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"name": "scule",
"repository": {
"type": "git",
"url": "git+https://github.com/nuxt-contrib/scule.git"
},
"scripts": {
"build": "siroc build",
"lint": "eslint --ext .ts .",
"prepublishOnly": "yarn build",
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
"test": "yarn lint && jest"
},
"sideEffects": false,
"types": "./dist/index.d.ts",
"version": "0.2.1"
}