DEV Community

Sebastian Korotkiewicz
Sebastian Korotkiewicz

Posted on • Updated on

New npm package that may help you with JavaScript

Welcome dev community!

Today I would like to introduce you to my npm package, which can be useful for any beginner or advanced JavaScript developer.

It's a collection of functions inspired from Python and rewritten for JavaScript, so now you can easily e.g. capitalize a string or display e.g. last 4 characters from a string.

To check it out, just install it quickly and easily via npm

$ npm install simhok
# or
$ yarn add simhok
Enter fullscreen mode Exit fullscreen mode

Now all we have to do is import the package into JS project

// Import what you need
import { len, log } from "simhok"

// Import all functions
import * as Sim from "simhok"

// In node.js
const { len, log } = require("simhok");
Enter fullscreen mode Exit fullscreen mode

Available functions

const user = "sebastian";
const users = ["sebastian", "klaudia"];
const hello = "hello world";

len(user);             // number:9
len(users);            // number: 2
capitalize(hello);     // string: Hello world
capitalizeAll(hello);  // string: Hello World
upper(user);           // string: SEBASTIAN
lower(user);           // string: sebastian

startsWith(user, "s"); // boolean: true
startsWith(user, "S"); // boolean: false
endsWith(user, "n");   // boolean: true

rstrip(user, "an");    // string: sebasti
lstrip(user, "s");     // string: ebastian

split(user, [0]);      // string: s
split(user, [0, 2]);   // string: se
split(user, [3, 0]);   // string: astian
split(user, [0, -3]);  // string: ian

let james_bond = 7;
zfill(james_bond, 2);  // string: 007

count([1,2,1,3,1], 1); // number: 3
compareIgnoreCase("Sebastian", "sebastian"); // boolean: true

abs(42);              // number: -42
abs(-42);             // number: 42

n("1_000_000")        // number: 1000000

log("This is pretty awesome 🎉"); // "This is pretty awesome 🎉"
Enter fullscreen mode Exit fullscreen mode

Example in React

import { len, upper } from "simhok"; 

const App = () => {
  let name = upper("Sebastian");
  let users = len(["Sebastian", "Klaudia"]);

  return <div>{users > 0 && name}</div>;
};
Enter fullscreen mode Exit fullscreen mode
import * as Sim from "simhok"; 

const App = () => {
  let name = Sim.upper("Sebastian");
  let users = Sim.len(["Sebastian", "Klaudia"]);

  return <div>{users > 0 && name}</div>;
};
Enter fullscreen mode Exit fullscreen mode

GitHub logo skorotkiewicz / SimHok

A lightweight and easy-to-use library for features you probably use every day

I invite you to test and write a few opinions what you think about the package.
I will gladly accept PR!

Post edited at: 16/06/2021

Top comments (9)

Collapse
 
okikio profile image
Okiki Ojo

It looks awesome, but I'd suggest not using a class, it's best to export each of those methods as individual functions that can be treeshaken at build time

Collapse
 
ali559 profile image
Ali Mohammed

Couldn't agree more

Collapse
 
teamradhq profile image
teamradhq

Hey, I submitted a bugfix for capitalize and some improvements to testing suite. Am happy to answer any questions / feedback here or on PR.

github.com/skorotkiewicz/SimHok/pu...

I've got some additional changes, but I'm late and I'm tired ;)

Collapse
 
skorotkiewicz profile image
Sebastian Korotkiewicz

Thanks for the great PR, merged! 🎉

Collapse
 
jerevick83 profile image
jerevick83

Great!

But creating packages for even the most trivial stuff and which comes handy with vanilla javascript won't help any beginning who's really interested in knowing the out of the box functions won't probably be helpful. It will only lead to surface learning.

Nonetheless, great initiative.

Collapse
 
draftproducts profile image
DraftMan

Most of those concepts are already native integrated in JavaScript, why would you like to make compatibility with a orther language as Python ?

Collapse
 
darrylnoakes profile image
Darryl Noakes

But you can do almost all of those with vanilla JS!?

Collapse
 
marcus-sa profile image
Marcus S. Abildskov

I wouldn't add an extra dependency just for wrappers around top-level API's for JS, lol.

Collapse
 
kalashin1 profile image
Kinanee Samson

I think this library is going to be great