npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsmp-infrastucture-task-01-grusheva

v1.0.1

Published

CDP task

Downloads

2

Readme

CDP task package

Curated collection of useful JavaScript snippets that you can understand in 20 seconds or less.

  • Use Ctrl + F or command + F to search for a snippet.

Installation

You can find a package details npm.


# Install with npm

npm install jsmp-infrastucture-task-01-grusheva

Usage examples




// ES Modules

import { compact } from  'jsmp-infrastucture-task-01-grusheva';

compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]);

To import snippets with Node:




const { compact } = require('jsmp-infrastucture-task-01-grusheva');

compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]);

Table of Contents

📚 Array

📜 String

📚 Array

concat

Concatenate some arrays into one array.

Uses _.concat() to concatenate arrays.

const firstArray = [1, null, 'Hello', 1];
const secondArray = [false, 12, 'someString'];
const  concat = concat(firstArray, secondArray);

concat([1, null, 'Hello', 1], [false, 12, 'someString']); // [1, null, 'Hello', 1, false, 12, 'someString']

⬆ Back to top

compact

Removes falsey values from an array.

Uses _.compact() to filter out falsey values (false, null, 0, "", undefined, and NaN).


const  compact = arr  =>  _.compact([1, null, 'Hello', 1]);

compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]); // [ 1, 2, 3, 'a', 's', 34 ]

⬆ Back to top

unique

Returns new array which contains only unique elements.

Create a new array from the given array.


const  unique = unique([1, null, 'Hello', 1]);

unique([1, null, 'Hello', 1]); // [1, null, 'Hello']

⬆ Back to top

📜 String

toCamelCase

Converts a string to camelcase.

Break the string into words and combine them capitalizing the first letter of each word, using a regexp.


const toCamelCase = str => {
  let s =
    str &&
    str
      .match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
      .map(x => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
      .join('');
  return s.slice(0, 1).toLowerCase() + s.slice(1);
};

toCamelCase('some_database_field_name'); // 'someDatabaseFieldName'
toCamelCase('Some label that needs to be camelized'); // 'someLabelThatNeedsToBeCamelized'
toCamelCase('some-javascript-property'); // 'someJavascriptProperty'
toCamelCase('some-mixed_string with spaces_underscores-and-hyphens'); // 'someMixedStringWithSpacesUnderscoresAndHyphens'

⬆ Back to top

toKebabCase

Converts a string to kebab case.

Break the string into words and combine them adding - as a separator, using a regexp.


const toKebabCase = str =>
  str &&
  str
    .match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
    .map(x => x.toLowerCase())
    .join('-');

toKebabCase('camelCase'); // 'camel-case'
toKebabCase('some text'); // 'some-text'
toKebabCase('some-mixed_string With spaces_underscores-and-hyphens'); // 'some-mixed-string-with-spaces-underscores-and-hyphens'
toKebabCase('AllThe-small Things'); // "all-the-small-things"
toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); // "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html"

⬆ Back to top

toSnakeCase

Truncates a string up to a specified length.

Converts a string to snake case.

Break the string into words and combine them adding _ as a separator, using a regexp.


const toSnakeCase = str =>
  str &&
  str
    .match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
    .map(x => x.toLowerCase())
    .join('_');

toSnakeCase('camelCase'); // 'camel_case'
toSnakeCase('some text'); // 'some_text'
toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens'); // 'some_mixed_string_with_spaces_underscores_and_hyphens'
toSnakeCase('AllThe-small Things'); // "all_the_smal_things"
toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); // "i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html"

⬆ Back to top

Credits

Icons made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY.