Comparing version 0.4.1 to 0.5.0
177
dist/str.js
@@ -1,1 +0,176 @@ | ||
var str=function(){"use strict";const e=e=>e.replace(/^\s+/,"").replace(/\s+$/,"");var t=t=>(t=e(t),String(t.charAt(0).toUpperCase())+String(t.slice(1).toLowerCase()));return{slugify:(t,r="-")=>e(t).toLowerCase().replace(/ /g,r).normalize("NFD").replace(/[\u0300-\u036f]/g,""),camelcase:r=>e(r).toLowerCase().split(" ").reduce(((e,r,i)=>e+(0===i?r:t(r))),""),capitalize:t,count:e=>String(e).length,endsWith:(e,t,r)=>{e=String(e),(!r||!isFinite(r)||Math.floor(r)!==r||r>e.length)&&(r=e.length),r-=t.length;const i=e.indexOf(t,r-1);return-1!==i&&i===r},startsWith:(e,t,r)=>String(e).indexOf(t,r||0)===(r||0),lower:e=>e.toLowerCase(),upper:e=>String(e).toUpperCase(),trim:e}}(); | ||
var str = (function () { | ||
'use strict'; | ||
/** | ||
* @function trim | ||
* @description Trims a string by the right and by the left | ||
* @param {String} str | ||
* @return {String} Trimmed string | ||
* @example | ||
* trim(' This is a tesT ') | ||
* // This is a tesT | ||
* @example | ||
* str(' This is a tesT ').trim().value | ||
* // This is a tesT | ||
*/ | ||
const trim = (str) => str | ||
.replace(/^\s+/, '') | ||
.replace(/\s+$/, ''); | ||
/** | ||
* @function capitalize | ||
* @description Capitalizes a string after applying a trim to it | ||
* @param {String} str | ||
* @return {String} | ||
* @example | ||
* capitalize('test') | ||
* // Test | ||
* @example | ||
* str('TEST').capitalize() | ||
* // Test | ||
*/ | ||
var capitalize = str => { | ||
str = trim(str); | ||
return String(str.charAt(0).toUpperCase()) + String(str.slice(1).toLowerCase()); | ||
}; | ||
/** | ||
* @function camelcase | ||
* @description Returns a string in camelcase after trimming it | ||
* @param {String} string | ||
* @return {String} The camelcase string | ||
* @example | ||
* camelcase(' This is a tesT ') | ||
* // thisIsATest | ||
* @example | ||
* str(' This is a tesT ').camelcase().value | ||
* // thisIsATest | ||
*/ | ||
var camelcase = (string) => trim(string) | ||
.toLowerCase() | ||
.split(' ') | ||
.reduce((acc, word, i) => acc + (i === 0 ? word : capitalize(word)), ''); | ||
/** | ||
* @function slugify | ||
* @description Slugifies a string | ||
* @param {String} str | ||
* @param {String} [del=-] Delimiter, defaults to '-' | ||
* @return {String} Slugified string | ||
* @example | ||
* slugify(' This is a tesT ') | ||
* // this-is-a-test | ||
* @example | ||
* slugify(' This is a tesT ', ':') | ||
* // this:is:a:test | ||
* @example | ||
* str(' This is a tesT ').slugify().value | ||
* // this-is-a-test | ||
*/ | ||
const slugify = (str, sep = '-') => trim(str) | ||
.toLowerCase() | ||
.replace(/ /g, sep) // Cambio espacios por el separador | ||
.normalize('NFD') // Quito todas las tildes | ||
.replace(/[\u0300-\u036f]/g, ''); | ||
/** | ||
* @function count | ||
* @description Counts characters in a string | ||
* @param {String} str | ||
* @return {Number} Number of characters | ||
* @example | ||
* count('test') | ||
* // 4 | ||
* @example | ||
* str('test').length | ||
* // 4 | ||
* @example | ||
* str('test').count() | ||
* // 4 | ||
*/ | ||
var count = str => String(str).length; | ||
/** | ||
* @function endsWith | ||
* @description Checks if a string ends with the provided substring | ||
* @param {String} str | ||
* @param {String} substring | ||
* @param {Number} [pos=0] Position to start checking. Defaults to 0 | ||
* @return {Boolean} True / False | ||
* @example | ||
* endsWith('test', 'st') | ||
* // true | ||
* @example | ||
* str('test').endsWith('st') | ||
* // true | ||
*/ | ||
const endsWith = (str, sub, pos) => { | ||
str = String(str); | ||
if (!pos || !isFinite(pos) || Math.floor(pos) !== pos || pos > str.length) { | ||
pos = str.length; | ||
} | ||
pos -= sub.length; | ||
const index = str.indexOf(sub, (pos - 1)); | ||
return index !== -1 && index === pos; | ||
}; | ||
/** | ||
* @function startsWith | ||
* @description Checks if a string starts with the provided substring | ||
* @param {String} str | ||
* @param {String} substring | ||
* @param {Number} [pos=0] Position to start checking. Defaults to 0 | ||
* @return {Boolean} True / False | ||
* @example | ||
* startsWith('test', 'te') | ||
* // true | ||
* @example | ||
* str('test').startsWith('te') | ||
* // true | ||
*/ | ||
var startsWith = (str, sub, pos) => String(str).indexOf(sub, pos || 0) === (pos || 0); | ||
/** | ||
* @function lower | ||
* @description Transform str to lower case | ||
* @param {String} str | ||
* @return {String} Lower cased string | ||
* @example | ||
* lower('TEST') | ||
* // test | ||
* @example | ||
* str('TEST').lower().value | ||
* // test | ||
*/ | ||
var lower = str => str.toLowerCase(); | ||
/** | ||
* @function upper | ||
* @description Transform a string to uppercase | ||
* @param {String} str | ||
* @return {String} Uppercased string | ||
* @example | ||
* upper('test') | ||
* // TEST | ||
* @example | ||
* str('test').upper().value | ||
* // TEST | ||
*/ | ||
var upper = str => String(str).toUpperCase(); | ||
var index = { | ||
slugify, | ||
camelcase, | ||
capitalize, | ||
count, | ||
endsWith, | ||
startsWith, | ||
lower, | ||
upper, | ||
trim | ||
}; | ||
return index; | ||
}()); | ||
//# sourceMappingURL=str.js.map |
{ | ||
"name": "str", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "⚙️ String manipulation library", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/es/index.mjs", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"browser": "dist/str.js", | ||
@@ -13,3 +13,3 @@ "types": "types/index.d.ts", | ||
"prestart": "rimraf ./dist", | ||
"build": "rollup -c && rollup -c rollup.browser.config.js", | ||
"build": "rollup -c rollup.browser.config.js && rollup -c", | ||
"prebuild": "rimraf ./dist", | ||
@@ -16,0 +16,0 @@ "docs:build": "rm -fr ./docs && jsdoc -c .jsdoc.json -R ./README.md", |
@@ -12,3 +12,11 @@ import pkg from './package.json' | ||
format: 'iife', | ||
name: 'str' | ||
name: 'str', | ||
sourcemap: true | ||
}, | ||
{ | ||
file: './dist/str.min.js', | ||
format: 'iife', | ||
name: 'str', | ||
plugins: [terser()], | ||
sourcemap: true | ||
} | ||
@@ -24,4 +32,3 @@ ], | ||
// useTsconfigDeclarationDir: false | ||
}), | ||
terser() | ||
}) | ||
] | ||
@@ -28,0 +35,0 @@ } |
@@ -5,2 +5,3 @@ import pkg from './package.json' | ||
import commonjs from '@rollup/plugin-commonjs' | ||
import copy from 'rollup-plugin-copy' | ||
// import { terser } from "rollup-plugin-terser"; | ||
@@ -17,3 +18,3 @@ // import resolve from "@rollup/plugin-node-resolve" | ||
{ | ||
dir: './dist/cjs', | ||
dir: './dist', | ||
entryFileNames: '[name].js', | ||
@@ -23,7 +24,9 @@ format: 'cjs', | ||
// esModule: false | ||
sourcemap: false | ||
}, | ||
{ | ||
dir: './dist/es', | ||
dir: './dist', | ||
entryFileNames: '[name].mjs', | ||
format: 'es', | ||
sourcemap: false | ||
// esModule: false | ||
@@ -46,3 +49,22 @@ }, | ||
}), | ||
// terser() | ||
// terser(), | ||
copy({ | ||
targets: [ | ||
{ | ||
src: './package.json', | ||
dest: './dist', | ||
transform: (contents) => { | ||
const p = JSON.parse(contents.toString('utf8')) | ||
p.main = p.main.replace('dist/', '') | ||
p.module = p.module.replace('dist/', '') | ||
p.browser = p.browser.replace('dist/', '') | ||
return JSON.stringify(p, null, 2) | ||
} | ||
}, | ||
{ | ||
src: './types', | ||
dest: './dist' | ||
} | ||
] | ||
}) | ||
] | ||
@@ -49,0 +71,0 @@ } |
@@ -1,8 +0,8 @@ | ||
const { slugify } = require('./dist/cjs') | ||
const { slugify } = require('./dist') | ||
console.log('{ slugify }', slugify); | ||
const slugify2 = require('./dist/cjs/slugify') | ||
const slugify2 = require('./dist/slugify') | ||
console.log('str/slugify', slugify2); | ||
const str = require('./dist/cjs') | ||
const str = require('./dist') | ||
console.log('str', str); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
317477
1772
54