├── .babelrc ├── .eslintrc ├── .gitignore ├── .gitmodules ├── .prettierrc ├── LICENSE ├── README.md ├── media ├── arc_logo.png ├── brave_logo.png ├── chrome_logo.png ├── edge_logo.png ├── firefox_logo.png ├── icon.svg ├── icon_color.svg ├── logo.svg ├── logo_color.svg ├── logotype.svg ├── opera_logo.png ├── promo_0.png ├── promo_1.png ├── promo_2.png ├── promo_3.png ├── promo_4.png ├── promo_5.png ├── react_logo.png └── safari_logo.png ├── package.json ├── src ├── api │ ├── google-analytics.js │ ├── snippets.js │ └── storage.js ├── assets │ ├── icons │ │ ├── icon-1024.png │ │ ├── icon-128.png │ │ ├── icon-16.png │ │ ├── icon-256.png │ │ ├── icon-32.png │ │ ├── icon-512.png │ │ ├── icon-64.png │ │ ├── toolbar-icon-1024.png │ │ ├── toolbar-icon-128.png │ │ ├── toolbar-icon-16.png │ │ ├── toolbar-icon-256.png │ │ ├── toolbar-icon-32.png │ │ ├── toolbar-icon-512.png │ │ └── toolbar-icon-64.png │ └── snippet_sources │ │ ├── cpp │ │ ├── csharp │ │ ├── css │ │ ├── dart │ │ ├── git │ │ ├── golang │ │ ├── html │ │ ├── interview │ │ ├── javascript │ │ ├── php │ │ ├── python │ │ ├── ramda │ │ ├── F.md │ │ ├── T.md │ │ ├── __.md │ │ ├── add.md │ │ ├── addIndex.md │ │ ├── adjust.md │ │ ├── all.md │ │ ├── allPass.md │ │ ├── always.md │ │ ├── and.md │ │ ├── any.md │ │ ├── anyPass.md │ │ ├── ap.md │ │ ├── aperture.md │ │ ├── append.md │ │ ├── apply.md │ │ ├── applySpec.md │ │ ├── applyTo.md │ │ ├── ascend.md │ │ ├── assoc.md │ │ ├── assocPath.md │ │ ├── binary.md │ │ ├── bind.md │ │ ├── both.md │ │ ├── call.md │ │ ├── chain.md │ │ ├── clamp.md │ │ ├── clone.md │ │ ├── comparator.md │ │ ├── complement.md │ │ ├── compose.md │ │ ├── composeK.md │ │ ├── composeP.md │ │ ├── composeWith.md │ │ ├── concat.md │ │ ├── cond.md │ │ ├── construct.md │ │ ├── constructN.md │ │ ├── contains.md │ │ ├── converge.md │ │ ├── countBy.md │ │ ├── curry.md │ │ ├── curryN.md │ │ ├── dec.md │ │ ├── defaultTo.md │ │ ├── descend.md │ │ ├── difference.md │ │ ├── differenceWith.md │ │ ├── dissoc.md │ │ ├── dissocPath.md │ │ ├── divide.md │ │ ├── drop.md │ │ ├── dropLast.md │ │ ├── dropLastWhile.md │ │ ├── dropRepeats.md │ │ ├── dropRepeatsWith.md │ │ ├── dropWhile.md │ │ ├── either.md │ │ ├── empty.md │ │ ├── endsWith.md │ │ ├── eqBy.md │ │ ├── eqProps.md │ │ ├── equals.md │ │ ├── evolve.md │ │ ├── filter.md │ │ ├── find.md │ │ ├── findIndex.md │ │ ├── findLast.md │ │ ├── findLastIndex.md │ │ ├── flatten.md │ │ ├── flip.md │ │ ├── forEach.md │ │ ├── forEachObjIndexed.md │ │ ├── fromPairs.md │ │ ├── groupBy.md │ │ ├── groupWith.md │ │ ├── gt.md │ │ ├── gte.md │ │ ├── has.md │ │ ├── hasIn.md │ │ ├── hasPath.md │ │ ├── head.md │ │ ├── identical.md │ │ ├── identity.md │ │ ├── ifElse.md │ │ ├── inc.md │ │ ├── includes.md │ │ ├── indexBy.md │ │ ├── indexOf.md │ │ ├── init.md │ │ ├── innerJoin.md │ │ ├── insert.md │ │ ├── insertAll.md │ │ ├── intersection.md │ │ ├── intersperse.md │ │ ├── into.md │ │ ├── invert.md │ │ ├── invertObj.md │ │ ├── invoker.md │ │ ├── is.md │ │ ├── isEmpty.md │ │ ├── isNil.md │ │ ├── join.md │ │ ├── juxt.md │ │ ├── keys.md │ │ ├── keysIn.md │ │ ├── last.md │ │ ├── lastIndexOf.md │ │ ├── length.md │ │ ├── lens.md │ │ ├── lensIndex.md │ │ ├── lensPath.md │ │ ├── lensProp.md │ │ ├── lift.md │ │ ├── liftN.md │ │ ├── lt.md │ │ ├── lte.md │ │ ├── map.md │ │ ├── mapAccum.md │ │ ├── mapAccumRight.md │ │ ├── mapObjIndexed.md │ │ ├── match.md │ │ ├── mathMod.md │ │ ├── max.md │ │ ├── maxBy.md │ │ ├── mean.md │ │ ├── median.md │ │ ├── memoizeWith.md │ │ ├── merge.md │ │ ├── mergeAll.md │ │ ├── mergeDeepLeft.md │ │ ├── mergeDeepRight.md │ │ ├── mergeDeepWith.md │ │ ├── mergeDeepWithKey.md │ │ ├── mergeLeft.md │ │ ├── mergeRight.md │ │ ├── mergeWith.md │ │ ├── mergeWithKey.md │ │ ├── min.md │ │ ├── minBy.md │ │ ├── modulo.md │ │ ├── move.md │ │ ├── multiply.md │ │ ├── nAry.md │ │ ├── negate.md │ │ ├── none.md │ │ ├── not.md │ │ ├── nth.md │ │ ├── nthArg.md │ │ ├── o.md │ │ ├── objOf.md │ │ ├── of.md │ │ ├── omit.md │ │ ├── once.md │ │ ├── or.md │ │ ├── otherwise.md │ │ ├── over.md │ │ ├── pair.md │ │ ├── partial.md │ │ ├── partialRight.md │ │ ├── partition.md │ │ ├── path.md │ │ ├── pathEq.md │ │ ├── pathOr.md │ │ ├── pathSatisfies.md │ │ ├── pick.md │ │ ├── pickAll.md │ │ ├── pickBy.md │ │ ├── pipe.md │ │ ├── pipeK.md │ │ ├── pipeP.md │ │ ├── pipeWith.md │ │ ├── pluck.md │ │ ├── prepend.md │ │ ├── product.md │ │ ├── project.md │ │ ├── prop.md │ │ ├── propEq.md │ │ ├── propIs.md │ │ ├── propOr.md │ │ ├── propSatisfies.md │ │ ├── props.md │ │ ├── range.md │ │ ├── reduce.md │ │ ├── reduceBy.md │ │ ├── reduceRight.md │ │ ├── reduceWhile.md │ │ ├── reduced.md │ │ ├── reject.md │ │ ├── remove.md │ │ ├── repeat.md │ │ ├── replace.md │ │ ├── reverse.md │ │ ├── scan.md │ │ ├── sequence.md │ │ ├── set.md │ │ ├── slice.md │ │ ├── sort.md │ │ ├── sortBy.md │ │ ├── sortWith.md │ │ ├── split.md │ │ ├── splitAt.md │ │ ├── splitEvery.md │ │ ├── splitWhen.md │ │ ├── startsWith.md │ │ ├── subtract.md │ │ ├── sum.md │ │ ├── symmetricDifference.md │ │ ├── symmetricDifferenceWith.md │ │ ├── tail.md │ │ ├── take.md │ │ ├── takeLast.md │ │ ├── takeLastWhile.md │ │ ├── takeWhile.md │ │ ├── tap.md │ │ ├── test.md │ │ ├── then.md │ │ ├── thunkify.md │ │ ├── times.md │ │ ├── toLower.md │ │ ├── toPairs.md │ │ ├── toPairsIn.md │ │ ├── toString.md │ │ ├── toUpper.md │ │ ├── transduce.md │ │ ├── transpose.md │ │ ├── traverse.md │ │ ├── trim.md │ │ ├── tryCatch.md │ │ ├── type.md │ │ ├── unapply.md │ │ ├── unary.md │ │ ├── uncurryN.md │ │ ├── unfold.md │ │ ├── union.md │ │ ├── unionWith.md │ │ ├── uniq.md │ │ ├── uniqBy.md │ │ ├── uniqWith.md │ │ ├── unless.md │ │ ├── unnest.md │ │ ├── until.md │ │ ├── update.md │ │ ├── useWith.md │ │ ├── values.md │ │ ├── valuesIn.md │ │ ├── view.md │ │ ├── when.md │ │ ├── where.md │ │ ├── whereEq.md │ │ ├── without.md │ │ ├── xprod.md │ │ ├── zip.md │ │ ├── zipObj.md │ │ └── zipWith.md │ │ ├── react │ │ └── ruby ├── components │ ├── Button │ │ ├── Button.js │ │ ├── Button.module.scss │ │ └── index.js │ ├── CheckBox │ │ ├── CheckBox.js │ │ ├── CheckBox.module.scss │ │ ├── CheckBoxIcon.js │ │ └── index.js │ ├── CheckBoxGroup │ │ ├── CheckBoxGroup.js │ │ ├── CheckBoxGroup.module.scss │ │ └── index.js │ ├── CodePenPreviewButton │ │ ├── CodePenPreviewButton.js │ │ ├── CodePenPreviewButton.module.scss │ │ └── index.js │ ├── Footer │ │ ├── Footer.js │ │ ├── Footer.module.scss │ │ └── index.js │ ├── Header │ │ ├── Header.js │ │ ├── Header.module.scss │ │ └── index.js │ ├── IconButton │ │ ├── IconButton.js │ │ ├── IconButton.module.scss │ │ └── index.js │ ├── Input │ │ ├── Input.js │ │ ├── Input.module.scss │ │ └── index.js │ ├── Label │ │ ├── Label.js │ │ ├── Label.module.scss │ │ └── index.js │ ├── LanguageList │ │ ├── LanguageList.js │ │ ├── LanguageList.module.scss │ │ └── index.js │ ├── LanguageTitle │ │ ├── LanguageTitle.js │ │ ├── LanguageTitle.module.scss │ │ └── index.js │ ├── Loader │ │ ├── Animation.js │ │ ├── Loader.js │ │ ├── Loader.module.scss │ │ └── index.js │ ├── Logo │ │ ├── Logo.js │ │ ├── Logo.module.scss │ │ └── index.js │ ├── MarkdownRenderer │ │ ├── MarkdownRenderer.js │ │ ├── MarkdownRenderer.module.scss │ │ └── index.js │ ├── MarkdownSnippetPreview │ │ ├── MarkdownSnippetPreview.js │ │ ├── MarkdownSnippetPreview.module.scss │ │ └── index.js │ ├── MarkdownSyntaxHighlighter │ │ ├── MarkdownSyntaxHighlighter.js │ │ ├── MarkdownSyntaxHighlighter.module.scss │ │ └── index.js │ ├── PageProvider │ │ ├── PageProvider.js │ │ ├── PageProvider.module.scss │ │ └── index.js │ ├── PlainToast │ │ ├── PlainToast.js │ │ ├── PlainToast.module.scss │ │ └── index.js │ ├── RadioButton │ │ ├── RadioButton.js │ │ ├── RadioButton.module.scss │ │ ├── RadioIcon.js │ │ └── index.js │ ├── RadioButtonGroup │ │ ├── RadioButtonGroup.js │ │ ├── RadioButtonGroup.module.scss │ │ └── index.js │ ├── ScrollTopButton │ │ ├── ScrollTopButton.js │ │ ├── ScrollTopButton.module.scss │ │ └── index.js │ ├── SelectField │ │ ├── Icon.js │ │ ├── SelectField.js │ │ ├── SelectField.module.scss │ │ └── index.js │ ├── SettingsForm │ │ ├── SettingsForm.js │ │ ├── SettingsForm.module.scss │ │ └── index.js │ ├── SettingsProvider │ │ ├── SettingsProvider.js │ │ ├── SettingsProvider.module.scss │ │ └── index.js │ ├── SnippetTitle │ │ ├── SnippetTitle.js │ │ ├── SnippetTitle.module.scss │ │ └── index.js │ └── Toast │ │ ├── Toast.js │ │ ├── ToastController.js │ │ ├── ToastList.js │ │ ├── ToastList.module.scss │ │ └── index.js ├── constants.js ├── icons │ ├── Arrow.js │ ├── Chevron.js │ ├── Close.js │ ├── Codepen.js │ ├── Copy.js │ ├── Cpp.js │ ├── Csharp.js │ ├── Css.js │ ├── Dart.js │ ├── Delete.js │ ├── Git.js │ ├── Github.js │ ├── Go.js │ ├── Html.js │ ├── Info.js │ ├── Interview.js │ ├── Javascript.js │ ├── Php.js │ ├── Python.js │ ├── Ramda.js │ ├── React.js │ ├── Ruby.js │ ├── Save.js │ └── VsCode.js ├── manifest.json ├── pages │ ├── AllSnippetsTab │ │ ├── AllSnippetsTab.js │ │ ├── AllSnippetsTab.module.scss │ │ ├── index.html │ │ └── index.js │ ├── Favourites │ │ ├── Favourites.js │ │ ├── Favourites.module.scss │ │ ├── index.html │ │ └── index.js │ ├── NewTab │ │ ├── NewTab.js │ │ ├── Newtab.module.scss │ │ ├── index.html │ │ └── index.js │ ├── Popup │ │ ├── Popup.js │ │ ├── Popup.module.scss │ │ ├── index.html │ │ └── index.js │ ├── Settings │ │ ├── Settings.js │ │ ├── Settings.module.scss │ │ ├── index.html │ │ └── index.js │ ├── ViewTab │ │ ├── ViewTab.js │ │ ├── ViewTab.module.scss │ │ ├── index.html │ │ └── index.js │ └── index.scss └── themes │ ├── _dark.scss │ ├── _gruvbox_light.scss │ ├── _hackpot.scss │ ├── _laser_wave.scss │ ├── _light.scss │ ├── _shades_of_purple.scss │ └── index.module.scss ├── utils ├── build.js ├── env.js ├── map_snippets.mjs └── webserver.js ├── webpack.config.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "react-app" 4 | ], 5 | "plugins": [ 6 | "react-hot-loader/babel" 7 | ] 8 | } -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "react-app", 3 | "globals": { 4 | "chrome": "readonly" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | /chromium_build 12 | /chromium_build.zip 13 | /opera_build 14 | /opera_build.zip 15 | /gecko_build 16 | /gecko_build.zip 17 | /safari_build 18 | /safari_build.zip 19 | /safari_build_xcode 20 | /src/api/data.js 21 | /src/constants.local.js 22 | 23 | # misc 24 | .DS_Store 25 | .env.local 26 | .env.development.local 27 | .env.test.local 28 | .env.production.local 29 | .history 30 | 31 | # secrets 32 | secrets.*.js 33 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "es5", 4 | "requirePragma": false, 5 | "arrowParens": "always" 6 | } -------------------------------------------------------------------------------- /media/arc_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/arc_logo.png -------------------------------------------------------------------------------- /media/brave_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/brave_logo.png -------------------------------------------------------------------------------- /media/chrome_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/chrome_logo.png -------------------------------------------------------------------------------- /media/edge_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/edge_logo.png -------------------------------------------------------------------------------- /media/firefox_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/firefox_logo.png -------------------------------------------------------------------------------- /media/opera_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/opera_logo.png -------------------------------------------------------------------------------- /media/promo_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/promo_0.png -------------------------------------------------------------------------------- /media/promo_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/promo_1.png -------------------------------------------------------------------------------- /media/promo_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/promo_2.png -------------------------------------------------------------------------------- /media/promo_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/promo_3.png -------------------------------------------------------------------------------- /media/promo_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/promo_4.png -------------------------------------------------------------------------------- /media/promo_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/promo_5.png -------------------------------------------------------------------------------- /media/react_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/react_logo.png -------------------------------------------------------------------------------- /media/safari_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/media/safari_logo.png -------------------------------------------------------------------------------- /src/assets/icons/icon-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/icon-1024.png -------------------------------------------------------------------------------- /src/assets/icons/icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/icon-128.png -------------------------------------------------------------------------------- /src/assets/icons/icon-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/icon-16.png -------------------------------------------------------------------------------- /src/assets/icons/icon-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/icon-256.png -------------------------------------------------------------------------------- /src/assets/icons/icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/icon-32.png -------------------------------------------------------------------------------- /src/assets/icons/icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/icon-512.png -------------------------------------------------------------------------------- /src/assets/icons/icon-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/icon-64.png -------------------------------------------------------------------------------- /src/assets/icons/toolbar-icon-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/toolbar-icon-1024.png -------------------------------------------------------------------------------- /src/assets/icons/toolbar-icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/toolbar-icon-128.png -------------------------------------------------------------------------------- /src/assets/icons/toolbar-icon-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/toolbar-icon-16.png -------------------------------------------------------------------------------- /src/assets/icons/toolbar-icon-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/toolbar-icon-256.png -------------------------------------------------------------------------------- /src/assets/icons/toolbar-icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/toolbar-icon-32.png -------------------------------------------------------------------------------- /src/assets/icons/toolbar-icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/toolbar-icon-512.png -------------------------------------------------------------------------------- /src/assets/icons/toolbar-icon-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petrovicstefanrs/30_seconds_of_knowledge/6d00555b2f5da8fdb36ca2fda007d8234c54ac1a/src/assets/icons/toolbar-icon-64.png -------------------------------------------------------------------------------- /src/assets/snippet_sources/cpp: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-cpp -------------------------------------------------------------------------------- /src/assets/snippet_sources/csharp: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-csharp/snippets -------------------------------------------------------------------------------- /src/assets/snippet_sources/css: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-code/content/snippets/css/s -------------------------------------------------------------------------------- /src/assets/snippet_sources/dart: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-dart/snippets -------------------------------------------------------------------------------- /src/assets/snippet_sources/git: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-code/content/snippets/git/s -------------------------------------------------------------------------------- /src/assets/snippet_sources/golang: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-golang/snippets -------------------------------------------------------------------------------- /src/assets/snippet_sources/html: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-code/content/snippets/html/s -------------------------------------------------------------------------------- /src/assets/snippet_sources/interview: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-interviews/questions -------------------------------------------------------------------------------- /src/assets/snippet_sources/javascript: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-code/content/snippets/js/s -------------------------------------------------------------------------------- /src/assets/snippet_sources/php: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-php/snippets -------------------------------------------------------------------------------- /src/assets/snippet_sources/python: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-code/content/snippets/python/s -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/F.md: -------------------------------------------------------------------------------- 1 | ### F 2 | 3 | > `* → Boolean` 4 | 5 | A function that always returns `false`. Any passed in parameters are ignored. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.F(); //=> false 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/T.md: -------------------------------------------------------------------------------- 1 | ### T 2 | 3 | > `* → Boolean` 4 | 5 | A function that always returns `true`. Any passed in parameters are ignored. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.T(); //=> true 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/__.md: -------------------------------------------------------------------------------- 1 | ### \_\_ 2 | 3 | A special placeholder value used to specify "gaps" within curried functions, allowing partial application of any combination of arguments, regardless of their positions. 4 | 5 | If `g` is a curried ternary function and `_` is `R.__`, the following are equivalent: 6 | 7 | ```js 8 | g(1, 2, 3); 9 | g(_, 2, 3)(1); 10 | g(_, _, 3)(1)(2); 11 | g(_, _, 3)(1, 2); 12 | g(_, 2, _)(1, 3); 13 | g(_, 2)(1)(3); 14 | g(_, 2)(1, 3); 15 | g(_, 2)(_, 3)(1); 16 | ``` 17 | 18 | `Example` 19 | 20 | ```js 21 | const greet = R.replace('{name}', R.__, 'Hello, {name}!'); 22 | 23 | greet('Alice'); //=> 'Hello, Alice!' 24 | ``` 25 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/add.md: -------------------------------------------------------------------------------- 1 | ### add 2 | 3 | > `Number -> Number -> Number` 4 | 5 | Adds two values. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.add(2, 3); //=> 5 11 | R.add(7)(10); //=> 17 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/addIndex.md: -------------------------------------------------------------------------------- 1 | ### addIndex 2 | 3 | > `((a … → b) … → [a] -→ *) → ((a …, Int, [a] → b) … → [a] → *)` 4 | 5 | Creates a new list iteration function from an existing one by adding two new parameters to its callback function: the current index, and the entire list. 6 | 7 | This would turn, for instance, `R.map` function into one that more closely resembles `Array.prototype.map`. Note that this will only work for functions in which the iteration callback function is the first parameter, and where the list is the last parameter. (This latter might be unimportant if the list parameter is not used.) 8 | 9 | `Example` 10 | 11 | ```js 12 | const mapIndexed = R.addIndex(R.map); 13 | 14 | mapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']); 15 | //=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r'] 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/adjust.md: -------------------------------------------------------------------------------- 1 | ### adjust 2 | 3 | > `Number → (a → a) → [a] → [a]` 4 | 5 | Applies a function to the value at the given index of an array, returning a new copy of the array with the element at the given index replaced with the result of the function application. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.adjust(1, R.toUpper, ['a', 'b', 'c', 'd']); //=> ['a', 'B', 'c', 'd'] 11 | R.adjust(-1, R.toUpper, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c', 'D'] 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/all.md: -------------------------------------------------------------------------------- 1 | ### all 2 | 3 | > `(a → Boolean) → [a] → Boolean` 4 | 5 | Returns `true` if all elements of the list match the predicate, `false` if there are any that don't. 6 | 7 | Dispatches to the all method of the second argument, if present. 8 | 9 | Acts as a transducer if a transformer is given in list position. 10 | 11 | `Example` 12 | 13 | ```js 14 | const equals3 = R.equals(3); 15 | 16 | R.all(equals3)([3, 3, 3, 3]); //=> true 17 | R.all(equals3)([3, 3, 1, 3]); //=> false 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/allPass.md: -------------------------------------------------------------------------------- 1 | ### allPass 2 | 3 | > `[(*… → Boolean)] → (*… → Boolean)` 4 | 5 | Takes a list of predicates and returns a predicate that returns true for a given list of arguments if every one of the provided predicates is satisfied by those arguments. 6 | 7 | The function returned is a curried function whose arity matches that of the highest-arity predicate. 8 | 9 | `Example` 10 | 11 | ```js 12 | const isQueen = R.propEq('rank', 'Q'); 13 | const isSpade = R.propEq('suit', '♠︎'); 14 | const isQueenOfSpades = R.allPass([isQueen, isSpade]); 15 | 16 | isQueenOfSpades({ rank: 'Q', suit: '♣︎' }); //=> false 17 | isQueenOfSpades({ rank: 'Q', suit: '♠︎' }); //=> true 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/always.md: -------------------------------------------------------------------------------- 1 | ### always 2 | 3 | > `a → (* → a)` 4 | 5 | Returns a function that always returns the given value. Note that for non-primitives the value returned is a reference to the original value. 6 | 7 | This function is known as const, constant, or `K (for K combinator)` in other languages and libraries. 8 | 9 | `Example` 10 | 11 | ```js 12 | const t = R.always('Tee'); 13 | 14 | t(); //=> 'Tee' 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/and.md: -------------------------------------------------------------------------------- 1 | ### and 2 | 3 | > `a → b → a | b` 4 | 5 | Returns `true` if both arguments are `true`; `false` otherwise. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.and(true, true); //=> true 11 | R.and(true, false); //=> false 12 | R.and(false, true); //=> false 13 | R.and(false, false); //=> false 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/any.md: -------------------------------------------------------------------------------- 1 | ### any 2 | 3 | > `(a → Boolean) → [a] → Boolean` 4 | 5 | Returns `true` if at least one of the elements of the list match the predicate, `false` otherwise. 6 | 7 | Dispatches to the any method of the second argument, if present. 8 | 9 | Acts as a transducer if a transformer is given in list position. 10 | 11 | `Example` 12 | 13 | ```js 14 | const lessThan0 = R.flip(R.lt)(0); 15 | const lessThan2 = R.flip(R.lt)(2); 16 | 17 | R.any(lessThan0)([1, 2]); //=> false 18 | R.any(lessThan2)([1, 2]); //=> true 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/anyPass.md: -------------------------------------------------------------------------------- 1 | ### anyPass 2 | 3 | > `[(*… → Boolean)] → (*… → Boolean)` 4 | 5 | Takes a list of predicates and returns a predicate that returns `true` for a given list of arguments if at least one of the provided predicates is satisfied by those arguments. 6 | 7 | The function returned is a curried function whose arity matches that of the highest-arity predicate. 8 | 9 | `Example` 10 | 11 | ```js 12 | const isClub = R.propEq('suit', '♣'); 13 | const isSpade = R.propEq('suit', '♠'); 14 | const isBlackCard = R.anyPass([isClub, isSpade]); 15 | 16 | isBlackCard({ rank: '10', suit: '♣' }); //=> true 17 | isBlackCard({ rank: 'Q', suit: '♠' }); //=> true 18 | isBlackCard({ rank: 'Q', suit: '♦' }); //=> false 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/ap.md: -------------------------------------------------------------------------------- 1 | ### ap 2 | 3 | > `[a → b] → [a] → [b]` > `Apply f => f (a → b) → f a → f b` > `(r → a → b) → (r → a) → (r → b)` 4 | 5 | `ap` applies a list of functions to a list of values. 6 | 7 | Dispatches to the ap method of the second argument, if present. Also treats curried functions as applicatives. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.ap([R.multiply(2), R.add(3)], [1, 2, 3]); //=> [2, 4, 6, 4, 5, 6] 13 | R.ap([R.concat('tasty '), R.toUpper], ['pizza', 'salad']); //=> ["tasty pizza", "tasty salad", "PIZZA", "SALAD"] 14 | R.ap(R.concat, R.toUpper)('Ramda'); //=> 'RamdaRAMDA' 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/aperture.md: -------------------------------------------------------------------------------- 1 | ### aperture 2 | 3 | > `Number → [a] → [[a]]` 4 | 5 | Returns a new list, composed of n-tuples of consecutive elements. If `n` is greater than the length of the list, an empty list is returned. 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.aperture(2, [1, 2, 3, 4, 5]); //=> [[1, 2], [2, 3], [3, 4], [4, 5]] 13 | R.aperture(3, [1, 2, 3, 4, 5]); //=> [[1, 2, 3], [2, 3, 4], [3, 4, 5]] 14 | R.aperture(7, [1, 2, 3, 4, 5]); //=> [] 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/append.md: -------------------------------------------------------------------------------- 1 | ### append 2 | 3 | > `a → [a] → [a]` 4 | 5 | Returns a new list containing the contents of the given list, followed by the given element. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests'] 11 | R.append('tests', []); //=> ['tests'] 12 | R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/apply.md: -------------------------------------------------------------------------------- 1 | ### apply 2 | 3 | > `(*… → a) → [*] → a` 4 | 5 | Applies function `fn` to the argument list args. This is useful for creating a fixed-arity function from a variadic function. `fn` should be a bound function if context is significant. 6 | 7 | `Example` 8 | 9 | ```js 10 | const nums = [1, 2, 3, -99, 42, 6, 7]; 11 | 12 | R.apply(Math.max, nums); //=> 42 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/applySpec.md: -------------------------------------------------------------------------------- 1 | ### applySpec 2 | 3 | > `{k: ((a, b, …, m) → v)} → ((a, b, …, m) → {k: v})` 4 | 5 | Given a spec object recursively mapping properties to functions, creates a function producing an object of the same structure, by mapping each property to the result of calling its associated function with the supplied arguments. 6 | 7 | `Example` 8 | 9 | ```js 10 | const getMetrics = R.applySpec({ 11 | sum: R.add, 12 | nested: { mul: R.multiply }, 13 | }); 14 | 15 | getMetrics(2, 4); // => { sum: 6, nested: { mul: 8 } } 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/applyTo.md: -------------------------------------------------------------------------------- 1 | ### applyTo 2 | 3 | > `a → (a → b) → b` 4 | 5 | Takes a value and applies a function to it. 6 | 7 | This function is also known as the thrush combinator. 8 | 9 | `Example` 10 | 11 | ```js 12 | const t42 = R.applyTo(42); 13 | 14 | t42(R.identity); //=> 42 15 | t42(R.add(1)); //=> 43 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/ascend.md: -------------------------------------------------------------------------------- 1 | ### ascend 2 | 3 | > `Ord b => (a → b) → a → a → Number` 4 | 5 | Makes an ascending comparator function out of a function that returns a value that can be compared with `<` and `>`. 6 | 7 | `Example` 8 | 9 | ```js 10 | const byAge = R.ascend(R.prop('age')); 11 | const people = [ 12 | { name: 'Emma', age: 70 }, 13 | { name: 'Peter', age: 78 }, 14 | { name: 'Mikhail', age: 62 }, 15 | ]; 16 | const peopleByYoungestFirst = R.sort(byAge, people); 17 | //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }] 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/assoc.md: -------------------------------------------------------------------------------- 1 | ### assoc 2 | 3 | > `String → a → {k: v} → {k: v}` 4 | 5 | Makes a shallow clone of an object, setting or overriding the specified property with the given value. Note that this copies and flattens prototype properties onto the new object as well. All non-primitive properties are copied by reference. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.assoc('c', 3, { a: 1, b: 2 }); //=> {a: 1, b: 2, c: 3} 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/assocPath.md: -------------------------------------------------------------------------------- 1 | ### assocPath 2 | 3 | > `[Idx] → a → {a} → {a}` > `Idx = String | Int` 4 | 5 | Makes a shallow clone of an object, setting or overriding the nodes required to create the given path, and placing the specific value at the tail end of that path. Note that this copies and flattens prototype properties onto the new object as well. All non-primitive properties are copied by reference. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.assocPath(['a', 'b', 'c'], 42, { a: { b: { c: 0 } } }); //=> {a: {b: {c: 42}}} 11 | 12 | // Any missing or non-object keys in path will be overridden 13 | R.assocPath(['a', 'b', 'c'], 42, { a: 5 }); //=> {a: {b: {c: 42}}} 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/binary.md: -------------------------------------------------------------------------------- 1 | ### binary 2 | 3 | > `(* → c) → (a, b → c)` 4 | 5 | Wraps a function of any arity (including nullary) in a function that accepts exactly 2 parameters. Any extraneous parameters will not be passed to the supplied function. 6 | 7 | `Example` 8 | 9 | ```js 10 | const takesThreeArgs = function (a, b, c) { 11 | return [a, b, c]; 12 | }; 13 | 14 | takesThreeArgs.length; //=> 3 15 | takesThreeArgs(1, 2, 3); //=> [1, 2, 3] 16 | 17 | const takesTwoArgs = R.binary(takesThreeArgs); 18 | 19 | takesTwoArgs.length; //=> 2 20 | // Only 2 arguments are passed to the wrapped function 21 | takesTwoArgs(1, 2, 3); //=> [1, 2, undefined] 22 | ``` 23 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/bind.md: -------------------------------------------------------------------------------- 1 | ### bind 2 | 3 | > `(* → *) → {*} → (* → *)` 4 | 5 | Creates a function that is bound to a context. 6 | Note: `R.bind` does not provide the additional argument-binding capabilities of `Function.prototype.bind`. 7 | 8 | `Example` 9 | 10 | ```js 11 | const log = R.bind(console.log, console); 12 | 13 | R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({ a: 1 }); //=> {a: 3} 14 | // logs {a: 2} 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/both.md: -------------------------------------------------------------------------------- 1 | ### both 2 | 3 | > `(*… → Boolean) → (*… → Boolean) → (*… → Boolean)` 4 | 5 | A function which calls the two provided functions and returns the && of the results. It returns the result of the first function if it is false-y and the result of the second function otherwise. Note that this is short-circuited, meaning that the second function will not be invoked if the first returns a false-y value. 6 | 7 | In addition to functions, `R.both` also accepts any `fantasy-land` compatible applicative functor. 8 | 9 | `Example` 10 | 11 | ```js 12 | const gt10 = R.gt(R.__, 10); 13 | const lt20 = R.lt(R.__, 20); 14 | const f = R.both(gt10, lt20); 15 | 16 | f(15); //=> true 17 | f(30); //=> false 18 | 19 | R.both(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(false) 20 | R.both([false, false, 'a'], [11]); //=> [false, false, 11] 21 | ``` 22 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/call.md: -------------------------------------------------------------------------------- 1 | ### call 2 | 3 | > `(*… → a),*… → a` 4 | 5 | Returns the result of calling its first argument with the remaining arguments. This is occasionally useful as a converging function for `R.converge` the first branch can produce a function while the remaining branches produce values to be passed to that function as its arguments. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.call(R.add, 1, 2); //=> 3 11 | 12 | const indentN = R.pipe(R.repeat(' '), R.join(''), R.replace(/^(?!$)/gm)); 13 | 14 | const format = R.converge(R.call, [ 15 | R.pipe(R.prop('indent'), indentN), 16 | R.prop('value'), 17 | ]); 18 | 19 | format({ indent: 2, value: 'foo\nbar\nbaz\n' }); //=> ' foo\n bar\n baz\n' 20 | ``` 21 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/chain.md: -------------------------------------------------------------------------------- 1 | ### chain 2 | 3 | > `Chain m => (a → m b) → m a → m b` 4 | 5 | `chain` maps a function over a list and concatenates the results. `chain` is also known as `flatMap` in some libraries. 6 | 7 | Dispatches to the chain method of the second argument, if present, according to the FantasyLand Chain spec. 8 | 9 | If second argument is a function, `chain(f, g)(x)` is equivalent to `f(g(x), x)`. 10 | 11 | Acts as a transducer if a transformer is given in list position. 12 | 13 | `Example` 14 | 15 | ```js 16 | const duplicate = (n) => [n, n]; 17 | 18 | R.chain(duplicate, [1, 2, 3]); //=> [1, 1, 2, 2, 3, 3] 19 | R.chain(R.append, R.head)([1, 2, 3]); //=> [1, 2, 3, 1] 20 | ``` 21 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/clamp.md: -------------------------------------------------------------------------------- 1 | ### clamp 2 | 3 | > `Ord a => a → a → a → a` 4 | 5 | Restricts a number to be within a range. 6 | 7 | Also works for other ordered types such as `Strings` and `Dates`. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.clamp(1, 10, -5); // => 1 13 | R.clamp(1, 10, 15); // => 10 14 | R.clamp(1, 10, 4); // => 4 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/clone.md: -------------------------------------------------------------------------------- 1 | ### clone 2 | 3 | > `{*} → {*}` 4 | 5 | Creates a deep copy of the value which may contain (nested) Arrays and Objects, Numbers, Strings, Booleans and Dates. Functions are assigned by reference rather than copied 6 | 7 | Dispatches to a clone method if present. 8 | 9 | `Example` 10 | 11 | ```js 12 | const objects = [{}, {}, {}]; 13 | const objectsClone = R.clone(objects); 14 | 15 | objects === objectsClone; //=> false 16 | objects[0] === objectsClone[0]; //=> false 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/comparator.md: -------------------------------------------------------------------------------- 1 | ### comparator 2 | 3 | > `((a, b) → Boolean) → ((a, b) → Number)` 4 | 5 | Makes a comparator function out of a function that reports whether the first element is less than the second. 6 | 7 | `Example` 8 | 9 | ```js 10 | const byAge = R.comparator((a, b) => a.age < b.age); 11 | const people = [ 12 | { name: 'Emma', age: 70 }, 13 | { name: 'Peter', age: 78 }, 14 | { name: 'Mikhail', age: 62 }, 15 | ]; 16 | const peopleByIncreasingAge = R.sort(byAge, people); 17 | //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }] 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/complement.md: -------------------------------------------------------------------------------- 1 | ### complement 2 | 3 | > `(*… → *) → (*… → Boolean)` 4 | 5 | Takes a function `f` and returns a function `g` such that if called with the same arguments when `f` returns a "truthy" value, `g` returns `false` and when `f` returns a "falsy" value `g` returns true. 6 | 7 | `R.complement` may be applied to any functor 8 | 9 | `Example` 10 | 11 | ```js 12 | const isNotNil = R.complement(R.isNil); 13 | 14 | isNil(null); //=> true 15 | isNotNil(null); //=> false 16 | isNil(7); //=> false 17 | isNotNil(7); //=> true 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/compose.md: -------------------------------------------------------------------------------- 1 | ### compose 2 | 3 | > `((y → z), (x → y), …, (o → p), ((a, b, …, n) → o)) → ((a, b, …, n) → z)` 4 | 5 | Performs right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary. 6 | 7 | Note: The result of compose is not automatically curried. 8 | 9 | `Example` 10 | 11 | ```js 12 | const classyGreeting = (firstName, lastName) => 13 | "The name's " + lastName + ', ' + firstName + ' ' + lastName; 14 | const yellGreeting = R.compose(R.toUpper, classyGreeting); 15 | 16 | yellGreeting('James', 'Bond'); //=> "THE NAME'S BOND, JAMES BOND" 17 | 18 | R.compose(Math.abs, R.add(1), R.multiply(2))(-4); //=> 7 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/composeK.md: -------------------------------------------------------------------------------- 1 | ### composeK 2 | 3 | > `Chain m => ((y → m z), (x → m y), …, (a → m b)) → (a → m z)` 4 | 5 | Returns the right-to-left `Kleisli` composition of the provided functions, each of which must return a value of a type supported by chain. 6 | 7 | `R.composeK(h, g, f)` is equivalent to `R.compose(R.chain(h)`, `R.chain(g), f)`. 8 | 9 | `Example` 10 | 11 | ```js 12 | const get = R.curry((propName, obj) => Maybe(obj[propName])); 13 | 14 | const getStateCode = R.composeK( 15 | R.compose(Maybe.of, R.toUpper), 16 | get('state'), 17 | get('address'), 18 | get('user') 19 | ); 20 | 21 | getStateCode({ user: { address: { state: 'ny' } } }); //=> Maybe.Just("NY") 22 | getStateCode({}); //=> Maybe.Nothing() 23 | ``` 24 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/composeP.md: -------------------------------------------------------------------------------- 1 | ### composeP 2 | 3 | > `((y → Promise z), (x → Promise y), …, (a → Promise b)) → (a → Promise z)` 4 | 5 | Performs right-to-left composition of one or more Promise-returning functions. The rightmost function may have any arity; the remaining functions must be unary. 6 | 7 | `Example` 8 | 9 | ```js 10 | const db = { 11 | users: { 12 | JOE: { 13 | name: 'Joe', 14 | followers: ['STEVE', 'SUZY'], 15 | }, 16 | }, 17 | }; 18 | 19 | // We'll pretend to do a db lookup which returns a promise 20 | const lookupUser = (userId) => Promise.resolve(db.users[userId]); 21 | const lookupFollowers = (user) => Promise.resolve(user.followers); 22 | 23 | lookupUser('JOE').then(lookupFollowers); 24 | 25 | // followersForUser :: String -> Promise [UserId] 26 | const followersForUser = R.composeP(lookupFollowers, lookupUser); 27 | 28 | followersForUser('JOE').then((followers) => 29 | console.log('Followers:', followers) 30 | ); 31 | // Followers: ["STEVE","SUZY"] 32 | ``` 33 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/composeWith.md: -------------------------------------------------------------------------------- 1 | ### composeWith 2 | 3 | > `((* → *), [(y → z), (x → y), …, (o → p), ((a, b, …, n) → o)]) → ((a, b, …, n) → z)` 4 | 5 | Performs right-to-left function composition using transforming function. The rightmost function may have any arity; the remaining functions must be unary. 6 | 7 | Note: The result of compose is not automatically curried. 8 | 9 | `Example` 10 | 11 | ```js 12 | const composeWhileNotNil = R.composeWith((f, res) => 13 | R.isNil(res) ? res : f(res) 14 | ); 15 | 16 | composeWhileNotNil([R.inc, R.prop('age')])({ age: 1 }); //=> 2 17 | composeWhileNotNil([R.inc, R.prop('age')])({}); //=> undefined 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/concat.md: -------------------------------------------------------------------------------- 1 | ### concat 2 | 3 | > `[a] → [a] → [a]` > `String → String → String` 4 | 5 | Returns the result of concatenating the given lists or strings. 6 | 7 | Note: `R.concat` expects both arguments to be of the same type, unlike the native `Array.prototype.concat` method. It will throw an error if you concat an Array with a non-Array value. 8 | 9 | Dispatches to the `concat` method of the first argument, if present. Can also concatenate two members of a `fantasy-land` compatible semigroup. 10 | 11 | `Example` 12 | 13 | ```js 14 | R.concat('ABC', 'DEF'); // 'ABCDEF' 15 | R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3] 16 | R.concat([], []); //=> [] 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/cond.md: -------------------------------------------------------------------------------- 1 | ### cond 2 | 3 | > `[[(*… → Boolean),(*… → *)]] → (*… → *)` 4 | 5 | Returns a function, `fn`, which encapsulates `if/else`, `if/else`, ... logic. `R.cond` takes a list of `[predicate, transformer]` pairs. All of the arguments to `fn` are applied to each of the predicates in turn until one returns a "truthy" value, at which point `fn` returns the result of applying its arguments to the corresponding transformer. If none of the predicates matches, `fn` returns undefined. 6 | 7 | `Example` 8 | 9 | ```js 10 | const fn = R.cond([ 11 | [R.equals(0), R.always('water freezes at 0°C')], 12 | [R.equals(100), R.always('water boils at 100°C')], 13 | [R.T, (temp) => 'nothing special happens at ' + temp + '°C'], 14 | ]); 15 | 16 | fn(0); //=> 'water freezes at 0°C' 17 | fn(50); //=> 'nothing special happens at 50°C' 18 | fn(100); //=> 'water boils at 100°C' 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/construct.md: -------------------------------------------------------------------------------- 1 | ### construct 2 | 3 | > `(* → {*}) → (* → {*})` 4 | 5 | Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type. 6 | 7 | `Example` 8 | 9 | ```js 10 | // Constructor function 11 | function Animal(kind) { 12 | this.kind = kind; 13 | } 14 | 15 | Animal.prototype.sighting = function () { 16 | return "It's a " + this.kind + '!'; 17 | }; 18 | 19 | const AnimalConstructor = R.construct(Animal); 20 | 21 | // Notice we no longer need the 'new' keyword: 22 | AnimalConstructor('Pig'); //=> {"kind": "Pig", "sighting": function (){...}}; 23 | 24 | const animalTypes = ['Lion', 'Tiger', 'Bear']; 25 | const animalSighting = R.invoker(0, 'sighting'); 26 | const sightNewAnimal = R.compose(animalSighting, AnimalConstructor); 27 | 28 | R.map(sightNewAnimal, animalTypes); //=> ["It's a Lion!", "It's a Tiger!", "It's a Bear!"] 29 | ``` 30 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/contains.md: -------------------------------------------------------------------------------- 1 | ### contains 2 | 3 | > `a → [a] → Boolean` 4 | 5 | Returns true if the specified value is equal, in `R.equals` terms, to at least one element of the given list; false otherwise. Works also with strings. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.contains(3, [1, 2, 3]); //=> true 11 | R.contains(4, [1, 2, 3]); //=> false 12 | R.contains({ name: 'Fred' }, [{ name: 'Fred' }]); //=> true 13 | R.contains([42], [[42]]); //=> true 14 | R.contains('ba', 'banana'); //=>true 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/converge.md: -------------------------------------------------------------------------------- 1 | ### converge 2 | 3 | > `((x1, x2, …) → z) → [((a, b, …) → x1), ((a, b, …) → x2), …] → (a → b → … → z)` 4 | 5 | Accepts a converging function and a list of branching functions and returns a new function. The arity of the new function is the same as the arity of the longest branching function. When invoked, this new function is applied to some arguments, and each branching function is applied to those same arguments. The results of each branching function are passed as arguments to the converging function to produce the return value. 6 | 7 | `Example` 8 | 9 | ```js 10 | const average = R.converge(R.divide, [R.sum, R.length]); 11 | 12 | average([1, 2, 3, 4, 5, 6, 7]); //=> 4 13 | 14 | const strangeConcat = R.converge(R.concat, [R.toUpper, R.toLower]); 15 | 16 | strangeConcat('Yodel'); //=> "YODELyodel" 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/countBy.md: -------------------------------------------------------------------------------- 1 | ### countBy 2 | 3 | > `(a → String) → [a] → {*}` 4 | 5 | Counts the elements of a list according to how many match each value of a key generated by the supplied function. Returns an object mapping the keys produced by fn to the number of occurrences in the list. Note that all keys are coerced to strings because of how JavaScript objects work. 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | const numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2]; 13 | 14 | R.countBy(Math.floor)(numbers); //=> {'1': 3, '2': 2, '3': 1} 15 | 16 | const letters = ['a', 'b', 'A', 'a', 'B', 'c']; 17 | 18 | R.countBy(R.toLower)(letters); //=> {'a': 3, 'b': 2, 'c': 1} 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/dec.md: -------------------------------------------------------------------------------- 1 | ### dec 2 | 3 | > `Number → Number` 4 | 5 | Decrements its argument. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.dec(42); //=> 41 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/defaultTo.md: -------------------------------------------------------------------------------- 1 | ### defaultTo 2 | 3 | > `a → b → a | b` 4 | 5 | Returns the second argument if it is not `null`, `undefined` or `NaN`; otherwise the first argument is returned. 6 | 7 | `Example` 8 | 9 | ```js 10 | const defaultTo42 = R.defaultTo(42); 11 | 12 | defaultTo42(null); //=> 42 13 | defaultTo42(undefined); //=> 42 14 | defaultTo42(false); //=> false 15 | defaultTo42('Ramda'); //=> 'Ramda' 16 | // parseInt('string') results in NaN 17 | defaultTo42(parseInt('string')); //=> 42 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/descend.md: -------------------------------------------------------------------------------- 1 | ### descend 2 | 3 | > `Ord b => (a → b) → a → a → Number` 4 | 5 | Makes a descending comparator function out of a function that returns a value that can be compared with `<` and `>`. 6 | 7 | `Example` 8 | 9 | ```js 10 | const byAge = R.descend(R.prop('age')); 11 | const people = [ 12 | { name: 'Emma', age: 70 }, 13 | { name: 'Peter', age: 78 }, 14 | { name: 'Mikhail', age: 62 }, 15 | ]; 16 | const peopleByOldestFirst = R.sort(byAge, people); 17 | //=> [{ name: 'Peter', age: 78 }, { name: 'Emma', age: 70 }, { name: 'Mikhail', age: 62 }] 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/difference.md: -------------------------------------------------------------------------------- 1 | ### difference 2 | 3 | > `[*] → [*] → [*]` 4 | 5 | Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list. Objects and Arrays are compared in terms of value equality, not reference equality. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.difference([1, 2, 3, 4], [7, 6, 5, 4, 3]); //=> [1,2] 11 | R.difference([7, 6, 5, 4, 3], [1, 2, 3, 4]); //=> [7,6,5] 12 | R.difference([{ a: 1 }, { b: 2 }], [{ a: 1 }, { c: 3 }]); //=> [{b: 2}] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/differenceWith.md: -------------------------------------------------------------------------------- 1 | ### differenceWith 2 | 3 | > `((a, a) → Boolean) → [a] → [a] → [a]` 4 | 5 | Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list. Duplication is determined according to the value returned by applying the supplied predicate to two list elements. 6 | 7 | `Example` 8 | 9 | ```js 10 | const cmp = (x, y) => x.a === y.a; 11 | const l1 = [{ a: 1 }, { a: 2 }, { a: 3 }]; 12 | const l2 = [{ a: 3 }, { a: 4 }]; 13 | 14 | R.differenceWith(cmp, l1, l2); //=> [{a: 1}, {a: 2}] 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/dissoc.md: -------------------------------------------------------------------------------- 1 | ### dissoc 2 | 3 | > `String → {k: v} → {k: v}` 4 | 5 | Returns a new object that does not contain a prop property. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.dissoc('b', { a: 1, b: 2, c: 3 }); //=> {a: 1, c: 3} 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/dissocPath.md: -------------------------------------------------------------------------------- 1 | ### dissocPath 2 | 3 | > `[Idx] → {k: v} → {k: v}` > `Idx = String | Int` 4 | 5 | Makes a shallow clone of an object, omitting the property at the given path. Note that this copies and flattens prototype properties onto the new object as well. All non-primitive properties are copied by reference. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.dissocPath(['a', 'b', 'c'], { a: { b: { c: 42 } } }); //=> {a: {b: {}}} 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/divide.md: -------------------------------------------------------------------------------- 1 | ### divide 2 | 3 | > `Number → Number → Number` 4 | 5 | Divides two numbers. Equivalent to `a / b`. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.divide(71, 100); //=> 0.71 11 | 12 | const half = R.divide(R.__, 2); 13 | 14 | half(42); //=> 21 15 | 16 | const reciprocal = R.divide(1); 17 | 18 | reciprocal(4); //=> 0.25 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/drop.md: -------------------------------------------------------------------------------- 1 | ### drop 2 | 3 | > `Number → [a] → [a]` > `Number → String → String` 4 | 5 | Returns all but the first n elements of the given list, string, or transducer/transformer (or object with a drop method). 6 | 7 | Dispatches to the drop method of the second argument, if present. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.drop(1, ['foo', 'bar', 'baz']); //=> ['bar', 'baz'] 13 | R.drop(2, ['foo', 'bar', 'baz']); //=> ['baz'] 14 | R.drop(3, ['foo', 'bar', 'baz']); //=> [] 15 | R.drop(4, ['foo', 'bar', 'baz']); //=> [] 16 | R.drop(3, 'ramda'); //=> 'da' 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/dropLast.md: -------------------------------------------------------------------------------- 1 | ### dropLast 2 | 3 | > `Number → [a] → [a]` > `Number → String → String` 4 | 5 | Returns a list containing all but the last n elements of the given list. 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.dropLast(1, ['foo', 'bar', 'baz']); //=> ['foo', 'bar'] 13 | R.dropLast(2, ['foo', 'bar', 'baz']); //=> ['foo'] 14 | R.dropLast(3, ['foo', 'bar', 'baz']); //=> [] 15 | R.dropLast(4, ['foo', 'bar', 'baz']); //=> [] 16 | R.dropLast(3, 'ramda'); //=> 'ra' 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/dropLastWhile.md: -------------------------------------------------------------------------------- 1 | ### dropLastWhile 2 | 3 | > `(a → Boolean) → [a] → [a]` > `(a → Boolean) → String → String` 4 | 5 | Returns a new list excluding all the tailing elements of a given list which satisfy the supplied predicate function. It passes each value from the right to the supplied predicate function, skipping elements until the predicate function returns a falsy value. The predicate function is applied to one argument: (value). 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | const lteThree = (x) => x <= 3; 13 | 14 | R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3, 4] 15 | 16 | R.dropLastWhile((x) => x !== 'd', 'Ramda'); //=> 'Ramd' 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/dropRepeats.md: -------------------------------------------------------------------------------- 1 | ### dropRepeats 2 | 3 | > `[a] → [a]` 4 | 5 | Returns a new list without any consecutively repeating elements. `R.equals` is used to determine equality. 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]); //=> [1, 2, 3, 4, 2] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/dropRepeatsWith.md: -------------------------------------------------------------------------------- 1 | ### dropRepeatsWith 2 | 3 | > `((a, a) → Boolean) → [a] → [a]` 4 | 5 | Returns a new list without any consecutively repeating elements. Equality is determined by applying the supplied predicate to each pair of consecutive elements. The first element in a series of equal elements will be preserved. 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3]; 13 | R.dropRepeatsWith(R.eqBy(Math.abs), l); //=> [1, 3, 4, -5, 3] 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/dropWhile.md: -------------------------------------------------------------------------------- 1 | ### dropWhile 2 | 3 | > `(a → Boolean) → [a] → [a]` > `(a → Boolean) → String → String` 4 | 5 | Returns a new list excluding the leading elements of a given list which satisfy the supplied predicate function. It passes each value to the supplied predicate function, skipping elements while the predicate function returns true. The predicate function is applied to one argument: (value). 6 | 7 | Dispatches to the `dropWhile` method of the second argument, if present. 8 | 9 | Acts as a transducer if a transformer is given in list position. 10 | 11 | `Example` 12 | 13 | ```js 14 | const lteTwo = (x) => x <= 2; 15 | 16 | R.dropWhile(lteTwo, [1, 2, 3, 4, 3, 2, 1]); //=> [3, 4, 3, 2, 1] 17 | R.dropWhile((x) => x !== 'd', 'Ramda'); //=> 'da' 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/either.md: -------------------------------------------------------------------------------- 1 | ### either 2 | 3 | > `(*… → Boolean) → (*… → Boolean) → (*… → Boolean)` 4 | 5 | A function wrapping calls to the two functions in an `||` operation, returning the result of the first function if it is truth-y and the result of the second function otherwise. Note that this is short-circuited, meaning that the second function will not be invoked if the first returns a truth-y value. 6 | 7 | In addition to functions, `R.either` also accepts any `fantasy-land` compatible applicative functor. 8 | 9 | `Example` 10 | 11 | ```js 12 | const gt10 = (x) => x > 10; 13 | const even = (x) => x % 2 === 0; 14 | const f = R.either(gt10, even); 15 | 16 | f(101); //=> true 17 | f(8); //=> true 18 | 19 | R.either(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(55) 20 | R.either([false, false, 'a'], [11]); // => [11, 11, "a"] 21 | ``` 22 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/empty.md: -------------------------------------------------------------------------------- 1 | ### empty 2 | 3 | > `a → a` 4 | 5 | Returns the empty value of its argument's type. Ramda defines the empty value of `Array ([])`, `Object ({})`, `String ('')`, and Arguments. Other types are supported if they define `.empty`, `.prototype.empty` or implement the `FantasyLand Monoid` spec. 6 | 7 | Dispatches to the empty method of the first argument, if present. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.empty(Just(42)); //=> Nothing() 13 | R.empty([1, 2, 3]); //=> [] 14 | R.empty('unicorns'); //=> '' 15 | R.empty({ x: 1, y: 2 }); //=> {} 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/endsWith.md: -------------------------------------------------------------------------------- 1 | ### endsWith 2 | 3 | > `[a] → [a] → Boolean` > `String → String → Boolean` 4 | 5 | Checks if a list ends with the provided sublist. 6 | 7 | Similarly, checks if a string ends with the provided substring. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.endsWith('c', 'abc'); //=> true 13 | R.endsWith('b', 'abc'); //=> false 14 | R.endsWith(['c'], ['a', 'b', 'c']); //=> true 15 | R.endsWith(['b'], ['a', 'b', 'c']); //=> false 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/eqBy.md: -------------------------------------------------------------------------------- 1 | ### eqBy 2 | 3 | > `(a → b) → a → a → Boolean` 4 | 5 | Takes a function and two values in its domain and returns `true` if the values map to the same value in the codomain; `false` otherwise. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.eqBy(Math.abs, 5, -5); //=> true 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/eqProps.md: -------------------------------------------------------------------------------- 1 | ### eqProps 2 | 3 | > `k → {k: v} → {k: v} → Boolean` 4 | 5 | Reports whether two objects have the same value, in `R.equals` terms, for the specified property. Useful as a curried predicate. 6 | 7 | `Example` 8 | 9 | ```js 10 | const o1 = { a: 1, b: 2, c: 3, d: 4 }; 11 | const o2 = { a: 10, b: 20, c: 3, d: 40 }; 12 | 13 | R.eqProps('a', o1, o2); //=> false 14 | R.eqProps('c', o1, o2); //=> true 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/equals.md: -------------------------------------------------------------------------------- 1 | ### equals 2 | 3 | > `a → b → Boolean` 4 | 5 | Returns `true` if its arguments are equivalent, `false` otherwise. Handles cyclical data structures. 6 | 7 | Dispatches symmetrically to the equals methods of both arguments, if present. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.equals(1, 1); //=> true 13 | R.equals(1, '1'); //=> false 14 | R.equals([1, 2, 3], [1, 2, 3]); //=> true 15 | 16 | const a = {}; 17 | a.v = a; 18 | const b = {}; 19 | b.v = b; 20 | 21 | R.equals(a, b); //=> true 22 | ``` 23 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/evolve.md: -------------------------------------------------------------------------------- 1 | ### evolve 2 | 3 | > `{k: (v → v)} → {k: v} → {k: v}` 4 | 5 | Creates a new object by recursively evolving a shallow copy of object, according to the transformation functions. All non-primitive properties are copied by reference. 6 | 7 | A transformation function will not be invoked if its corresponding key does not exist in the evolved object. 8 | 9 | `Example` 10 | 11 | ```js 12 | const tomato = { 13 | firstName: ' Tomato ', 14 | data: { elapsed: 100, remaining: 1400 }, 15 | id: 123, 16 | }; 17 | const transformations = { 18 | firstName: R.trim, 19 | lastName: R.trim, // Will not get invoked. 20 | data: { elapsed: R.add(1), remaining: R.add(-1) }, 21 | }; 22 | R.evolve(transformations, tomato); //=> {firstName: 'Tomato', data: {elapsed: 101, remaining: 1399}, id:123} 23 | ``` 24 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/filter.md: -------------------------------------------------------------------------------- 1 | ### filter 2 | 3 | > `Filterable f => (a → Boolean) → f a → f a` 4 | 5 | Takes a predicate and a Filterable, and returns a new filterable of the same type containing the members of the given filterable which satisfy the given predicate. Filterable objects include plain objects or any object that has a filter method such as Array. 6 | 7 | Dispatches to the `filter` method of the second argument, if present. 8 | 9 | Acts as a transducer if a transformer is given in list position. 10 | 11 | `Example` 12 | 13 | ```js 14 | const isEven = (n) => n % 2 === 0; 15 | 16 | R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4] 17 | R.filter(isEven, { a: 1, b: 2, c: 3, d: 4 }); //=> {b: 2, d: 4} 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/find.md: -------------------------------------------------------------------------------- 1 | ### find 2 | 3 | > `(a → Boolean) → [a] → a | undefined` 4 | 5 | Returns the first element of the list which matches the predicate, or `undefined` if no element matches. 6 | 7 | Dispatches to the find method of the second argument, if present. 8 | 9 | Acts as a transducer if a transformer is given in list position. 10 | 11 | `Example` 12 | 13 | ```js 14 | const xs = [{ a: 1 }, { a: 2 }, { a: 3 }]; 15 | 16 | R.find(R.propEq('a', 2))(xs); //=> {a: 2} 17 | R.find(R.propEq('a', 4))(xs); //=> undefined 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/findIndex.md: -------------------------------------------------------------------------------- 1 | ### findIndex 2 | 3 | > `(a → Boolean) → [a] → Number` 4 | 5 | Returns the index of the first element of the list which matches the predicate, or -1 if no element matches. 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | const xs = [{ a: 1 }, { a: 2 }, { a: 3 }]; 13 | 14 | R.findIndex(R.propEq('a', 2))(xs); //=> 1 15 | R.findIndex(R.propEq('a', 4))(xs); //=> -1 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/findLast.md: -------------------------------------------------------------------------------- 1 | ### findLast 2 | 3 | > `(a → Boolean) → [a] → a | undefined` 4 | 5 | Returns the last element of the list which matches the predicate, or `undefined` if no element matches. 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | const xs = [ 13 | { a: 1, b: 0 }, 14 | { a: 1, b: 1 }, 15 | ]; 16 | R.findLast(R.propEq('a', 1))(xs); //=> {a: 1, b: 1} 17 | R.findLast(R.propEq('a', 4))(xs); //=> undefined 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/findLastIndex.md: -------------------------------------------------------------------------------- 1 | ### findLastIndex 2 | 3 | > `(a → Boolean) → [a] → Number` 4 | 5 | Returns the index of the last element of the list which matches the predicate, or -1 if no element matches. 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | const xs = [ 13 | { a: 1, b: 0 }, 14 | { a: 1, b: 1 }, 15 | ]; 16 | 17 | R.findLastIndex(R.propEq('a', 1))(xs); //=> 1 18 | R.findLastIndex(R.propEq('a', 4))(xs); //=> -1 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/flatten.md: -------------------------------------------------------------------------------- 1 | ### flatten 2 | 3 | > `[a] → [b]` 4 | 5 | Returns a new list by pulling every item out of it (and all its sub-arrays) and putting them in a new array, depth-first. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]); 11 | //=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/flip.md: -------------------------------------------------------------------------------- 1 | ### flip 2 | 3 | > `((a, b, c, …) → z) → (b → a → c → … → z)` 4 | 5 | Returns a new function much like the supplied one, except that the first two arguments' order is reversed. 6 | 7 | `Example` 8 | 9 | ```js 10 | const mergeThree = (a, b, c) => [].concat(a, b, c); 11 | 12 | mergeThree(1, 2, 3); //=> [1, 2, 3] 13 | 14 | R.flip(mergeThree)(1, 2, 3); //=> [2, 1, 3] 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/forEach.md: -------------------------------------------------------------------------------- 1 | ### forEach 2 | 3 | > `(a → *) → [a] → [a]` 4 | 5 | Iterate over an input list, calling a provided function `fn` for each element in the list. 6 | 7 | `fn` receives one argument: (value). 8 | 9 | Note: R.forEach does not skip deleted or unassigned indices (sparse arrays), unlike the native Array.prototype.forEach method. For more details on this behavior, see: [forEach description](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description) 10 | 11 | Also note that, unlike `Array.prototype.forEach`, Ramda's `forEach` returns the original array. In some libraries this function is named `each`. 12 | 13 | Dispatches to the `forEach` method of the second argument, if present. 14 | 15 | `Example` 16 | 17 | ```js 18 | const printXPlusFive = (x) => console.log(x + 5); 19 | 20 | R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3] 21 | // logs 6 22 | // logs 7 23 | // logs 8 24 | ``` 25 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/forEachObjIndexed.md: -------------------------------------------------------------------------------- 1 | ### forEachObjIndexed 2 | 3 | > `((a, String, StrMap a) → Any) → StrMap a → StrMap a` 4 | 5 | Iterate over an input object, calling a provided function fn for each key and value in the object. 6 | 7 | `fn` receives three argument: `(value, key, obj)`. 8 | 9 | `Example` 10 | 11 | ```js 12 | const printKeyConcatValue = (value, key) => console.log(key + ':' + value); 13 | 14 | R.forEachObjIndexed(printKeyConcatValue, { x: 1, y: 2 }); //=> {x: 1, y: 2} 15 | // logs x:1 16 | // logs y:2 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/fromPairs.md: -------------------------------------------------------------------------------- 1 | ### fromPairs 2 | 3 | > `[[k,v]] → {k: v}` 4 | 5 | Creates a new object from a list key-value pairs. If a key appears in multiple pairs, the rightmost pair is included in the object. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.fromPairs([ 11 | ['a', 1], 12 | ['b', 2], 13 | ['c', 3], 14 | ]); //=> {a: 1, b: 2, c: 3} 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/groupWith.md: -------------------------------------------------------------------------------- 1 | ### groupWith 2 | 3 | > `((a, a) → Boolean) → [a] → [[a]]` 4 | 5 | Takes a list and returns a list of lists where each sublist's elements are all satisfied pairwise comparison according to the provided function. Only adjacent elements are passed to the comparison function. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.groupWith(R.equals, [0, 1, 1, 2, 3, 5, 8, 13, 21]); 11 | //=> [[0], [1, 1], [2], [3], [5], [8], [13], [21]] 12 | 13 | R.groupWith((a, b) => a + 1 === b, [0, 1, 1, 2, 3, 5, 8, 13, 21]); 14 | //=> [[0, 1], [1, 2, 3], [5], [8], [13], [21]] 15 | 16 | R.groupWith((a, b) => a % 2 === b % 2, [0, 1, 1, 2, 3, 5, 8, 13, 21]); 17 | //=> [[0], [1, 1], [2], [3, 5], [8], [13, 21]] 18 | 19 | R.groupWith(R.eqBy(isVowel), 'aestiou'); 20 | //=> ['ae', 'st', 'iou'] 21 | ``` 22 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/gt.md: -------------------------------------------------------------------------------- 1 | ### gt 2 | 3 | > `Ord a => a → a → Boolean` 4 | 5 | Returns `true` if the first argument is greater than the second; `false` otherwise. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.gt(2, 1); //=> true 11 | R.gt(2, 2); //=> false 12 | R.gt(2, 3); //=> false 13 | R.gt('a', 'z'); //=> false 14 | R.gt('z', 'a'); //=> true 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/gte.md: -------------------------------------------------------------------------------- 1 | ### gte 2 | 3 | > `Ord a => a → a → Boolean` 4 | 5 | Returns `true` if the first argument is greater than or equal to the second; `false` otherwise. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.gte(2, 1); //=> true 11 | R.gte(2, 2); //=> true 12 | R.gte(2, 3); //=> false 13 | R.gte('a', 'z'); //=> false 14 | R.gte('z', 'a'); //=> true 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/has.md: -------------------------------------------------------------------------------- 1 | ### has 2 | 3 | > `s → {s: x} → Boolean` 4 | 5 | Returns whether or not an object has an own property with the specified name 6 | 7 | `Example` 8 | 9 | ```js 10 | const hasName = R.has('name'); 11 | 12 | hasName({ name: 'alice' }); //=> true 13 | hasName({ name: 'bob' }); //=> true 14 | hasName({}); //=> false 15 | 16 | const point = { x: 0, y: 0 }; 17 | const pointHas = R.has(R.__, point); 18 | 19 | pointHas('x'); //=> true 20 | pointHas('y'); //=> true 21 | pointHas('z'); //=> false 22 | ``` 23 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/hasIn.md: -------------------------------------------------------------------------------- 1 | ### hasIn 2 | 3 | > `s → {s: x} → Boolean` 4 | 5 | Returns whether or not an object or its prototype chain has a property with the specified name 6 | 7 | `Example` 8 | 9 | ```js 10 | function Rectangle(width, height) { 11 | this.width = width; 12 | this.height = height; 13 | } 14 | 15 | Rectangle.prototype.area = function () { 16 | return this.width * this.height; 17 | }; 18 | 19 | const square = new Rectangle(2, 2); 20 | 21 | R.hasIn('width', square); //=> true 22 | R.hasIn('area', square); //=> true 23 | ``` 24 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/hasPath.md: -------------------------------------------------------------------------------- 1 | ### hasPath 2 | 3 | > `[Idx] → {a} → Boolean` > `Idx = String | Int` 4 | 5 | Returns whether or not a path exists in an object. Only the object's own properties are checked. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.hasPath(['a', 'b'], { a: { b: 2 } }); // => true 11 | R.hasPath(['a', 'b'], { a: { b: undefined } }); // => true 12 | R.hasPath(['a', 'b'], { a: { c: 2 } }); // => false 13 | R.hasPath(['a', 'b'], {}); // => false 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/head.md: -------------------------------------------------------------------------------- 1 | ### head 2 | 3 | > `[a] → a | Undefined` > `String → String` 4 | 5 | Returns the first element of the given list or string. In some libraries this function is named first. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.head(['fi', 'fo', 'fum']); //=> 'fi' 11 | R.head([]); //=> undefined 12 | 13 | R.head('abc'); //=> 'a' 14 | R.head(''); //=> '' 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/identical.md: -------------------------------------------------------------------------------- 1 | ### identical 2 | 3 | > `a → a → Boolean` 4 | 5 | Returns `true` if its arguments are identical, `false` otherwise. Values are identical if they reference the same memory. NaN is identical to `NaN`; 0 and -0 are not identical. 6 | 7 | Note this is merely a curried version of ES6 Object.is. 8 | 9 | `Example` 10 | 11 | ```js 12 | const o = {}; 13 | 14 | R.identical(o, o); //=> true 15 | R.identical(1, 1); //=> true 16 | R.identical(1, '1'); //=> false 17 | R.identical([], []); //=> false 18 | R.identical(0, -0); //=> false 19 | R.identical(NaN, NaN); //=> true 20 | ``` 21 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/identity.md: -------------------------------------------------------------------------------- 1 | ### identity 2 | 3 | > `a → a` 4 | 5 | A function that does nothing but return the parameter supplied to it. Good as a default or placeholder function. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.identity(1); //=> 1 11 | 12 | const obj = {}; 13 | 14 | R.identity(obj) === obj; //=> true 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/ifElse.md: -------------------------------------------------------------------------------- 1 | ### ifElse 2 | 3 | > `(*… → Boolean) → (*… → *) → (*… → *) → (*… → *)` 4 | 5 | Creates a function that will process either the `onTrue` or the `onFalse` function depending upon the result of the condition predicate. 6 | 7 | `Example` 8 | 9 | ```js 10 | const incCount = R.ifElse( 11 | R.has('count'), 12 | R.over(R.lensProp('count'), R.inc), 13 | R.assoc('count', 1) 14 | ); 15 | 16 | incCount({}); //=> { count: 1 } 17 | incCount({ count: 1 }); //=> { count: 2 } 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/inc.md: -------------------------------------------------------------------------------- 1 | ### inc 2 | 3 | > `Number → Number` 4 | 5 | Increments its argument. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.inc(42); //=> 43 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/includes.md: -------------------------------------------------------------------------------- 1 | ### includes 2 | 3 | > `a → [a] → Boolean` 4 | 5 | Returns `true` if the specified value is equal, in `R.equals` terms, to at least one element of the given list; `false` otherwise. Works also with strings. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.includes(3, [1, 2, 3]); //=> true 11 | R.includes(4, [1, 2, 3]); //=> false 12 | R.includes({ name: 'Fred' }, [{ name: 'Fred' }]); //=> true 13 | R.includes([42], [[42]]); //=> true 14 | R.includes('ba', 'banana'); //=>true 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/indexBy.md: -------------------------------------------------------------------------------- 1 | ### indexBy 2 | 3 | > `(a → String) → [{k: v}] → {k: {k: v}}` 4 | 5 | Given a function that generates a key, turns a list of objects into an object indexing the objects by the given key. Note that if multiple objects generate the same value for the indexing key only the last value will be included in the generated object. 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | const list = [ 13 | { id: 'xyz', title: 'A' }, 14 | { id: 'abc', title: 'B' }, 15 | ]; 16 | R.indexBy(R.prop('id'), list); 17 | //=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}} 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/indexOf.md: -------------------------------------------------------------------------------- 1 | ### indexOf 2 | 3 | > `a → [a] → Number` 4 | 5 | Returns the position of the first occurrence of an item in an array, or -1 if the item is not included in the array. `R.equals` is used to determine equality. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.indexOf(3, [1, 2, 3, 4]); //=> 2 11 | R.indexOf(10, [1, 2, 3, 4]); //=> -1 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/init.md: -------------------------------------------------------------------------------- 1 | ### init 2 | 3 | > `[a] → [a]` > `String → String` 4 | 5 | Returns all but the last element of the given list or string. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.init([1, 2, 3]); //=> [1, 2] 11 | R.init([1, 2]); //=> [1] 12 | R.init([1]); //=> [] 13 | R.init([]); //=> [] 14 | 15 | R.init('abc'); //=> 'ab' 16 | R.init('ab'); //=> 'a' 17 | R.init('a'); //=> '' 18 | R.init(''); //=> '' 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/insert.md: -------------------------------------------------------------------------------- 1 | ### insert 2 | 3 | > `Number → a → [a] → [a]` 4 | 5 | Inserts the supplied element into the list, at the specified index. Note that this is not destructive: it returns a copy of the list with the changes. No lists have been harmed in the application of this function. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.insert(2, 'x', [1, 2, 3, 4]); //=> [1,2,'x',3,4] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/insertAll.md: -------------------------------------------------------------------------------- 1 | ### insertAll 2 | 3 | > `Number → [a] → [a] → [a]` 4 | 5 | Inserts the sub-list into the list, at the specified index. Note that this is not destructive: it returns a copy of the list with the changes. No lists have been harmed in the application of this function. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.insertAll(2, ['x', 'y', 'z'], [1, 2, 3, 4]); //=> [1,2,'x','y','z',3,4] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/intersection.md: -------------------------------------------------------------------------------- 1 | ### intersection 2 | 3 | > `[*] → [*] → [*]` 4 | 5 | Combines two lists into a set (i.e. no duplicates) composed of those elements common to both lists. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.intersection([1, 2, 3, 4], [7, 6, 5, 4, 3]); //=> [4, 3] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/intersperse.md: -------------------------------------------------------------------------------- 1 | ### intersperse 2 | 3 | > `a → [a] → [a]` 4 | 5 | Creates a new list with the separator interposed between elements. 6 | 7 | Dispatches to the intersperse method of the second argument, if present. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.intersperse('a', ['b', 'n', 'n', 's']); //=> ['b', 'a', 'n', 'a', 'n', 'a', 's'] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/invert.md: -------------------------------------------------------------------------------- 1 | ### invert 2 | 3 | > `{s: x} → {x: [ s, … ]}` 4 | 5 | Same as `R.invertObj`, however this accounts for objects with duplicate values by putting the values into an array. 6 | 7 | `Example` 8 | 9 | ```js 10 | const raceResultsByFirstName = { 11 | first: 'alice', 12 | second: 'jake', 13 | third: 'alice', 14 | }; 15 | R.invert(raceResultsByFirstName); 16 | //=> { 'alice': ['first', 'third'], 'jake':['second'] } 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/invertObj.md: -------------------------------------------------------------------------------- 1 | ### invertObj 2 | 3 | > `{s: x} → {x: s}` 4 | 5 | Returns a new object with the keys of the given object as values, and the values of the given object, which are coerced to strings, as keys. Note that the last key found is preferred when handling the same value. 6 | 7 | `Example` 8 | 9 | ```js 10 | const raceResults = { 11 | first: 'alice', 12 | second: 'jake', 13 | }; 14 | R.invertObj(raceResults); 15 | //=> { 'alice': 'first', 'jake':'second' } 16 | 17 | // Alternatively: 18 | const raceResults = ['alice', 'jake']; 19 | R.invertObj(raceResults); 20 | //=> { 'alice': '0', 'jake':'1' } 21 | ``` 22 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/invoker.md: -------------------------------------------------------------------------------- 1 | ### invoker 2 | 3 | > `Number → String → (a → b → … → n → Object → *)` 4 | 5 | Turns a named method with a specified arity into a function that can be called directly supplied with arguments and a target object. 6 | 7 | The returned function is curried and accepts arity + 1 parameters where the final parameter is the target object. 8 | 9 | `Example` 10 | 11 | ```js 12 | const sliceFrom = R.invoker(1, 'slice'); 13 | 14 | sliceFrom(6, 'abcdefghijklm'); //=> 'ghijklm' 15 | 16 | const sliceFrom6 = R.invoker(2, 'slice')(6); 17 | 18 | sliceFrom6(8, 'abcdefghijklm'); //=> 'gh' 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/is.md: -------------------------------------------------------------------------------- 1 | ### is 2 | 3 | > `(* → {*}) → a → Boolean` 4 | 5 | See if an object (val) is an instance of the supplied constructor. This function will check up the inheritance chain, if any. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.is(Object, {}); //=> true 11 | R.is(Number, 1); //=> true 12 | R.is(Object, 1); //=> false 13 | R.is(String, 's'); //=> true 14 | R.is(String, new String('')); //=> true 15 | R.is(Object, new String('')); //=> true 16 | R.is(Object, 's'); //=> false 17 | R.is(Number, {}); //=> false 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/isEmpty.md: -------------------------------------------------------------------------------- 1 | ### isEmpty 2 | 3 | > `a → Boolean` 4 | 5 | Returns `true` if the given value is its type's empty value; `false` otherwise. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.isEmpty([1, 2, 3]); //=> false 11 | R.isEmpty([]); //=> true 12 | R.isEmpty(''); //=> true 13 | R.isEmpty(null); //=> false 14 | R.isEmpty({}); //=> true 15 | R.isEmpty({ length: 0 }); //=> false 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/isNil.md: -------------------------------------------------------------------------------- 1 | ### isNil 2 | 3 | > `* → Boolean` 4 | 5 | Checks if the input value is `null` or `undefined`. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.isNil(null); //=> true 11 | R.isNil(undefined); //=> true 12 | R.isNil(0); //=> false 13 | R.isNil([]); //=> false 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/join.md: -------------------------------------------------------------------------------- 1 | ### join 2 | 3 | > `String → [a] → String` 4 | 5 | Returns a `string` made by inserting the separator between each element and concatenating all the elements into a single `string`. 6 | 7 | `Example` 8 | 9 | ```js 10 | const spacer = R.join(' '); 11 | 12 | spacer(['a', 2, 3.4]); //=> 'a 2 3.4' 13 | 14 | R.join('|', [1, 2, 3]); //=> '1|2|3' 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/juxt.md: -------------------------------------------------------------------------------- 1 | ### juxt 2 | 3 | > `[(a, b, …, m) → n] → ((a, b, …, m) → [n])` 4 | 5 | juxt applies a list of functions to a list of values. 6 | 7 | `Example` 8 | 9 | ```js 10 | const getRange = R.juxt([Math.min, Math.max]); 11 | 12 | getRange(3, 4, 9, -3); //=> [-3, 9] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/keys.md: -------------------------------------------------------------------------------- 1 | ### keys 2 | 3 | > `{k: v} → [k]` 4 | 5 | Returns a list containing the names of all the enumerable own properties of the supplied object. Note that the order of the output array is not guaranteed to be consistent across different JS platforms. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.keys({ a: 1, b: 2, c: 3 }); //=> ['a', 'b', 'c'] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/keysIn.md: -------------------------------------------------------------------------------- 1 | ### keysIn 2 | 3 | > `{k: v} → [k]` 4 | 5 | Returns a list containing the names of all the properties of the supplied object, including prototype properties. Note that the order of the output array is not guaranteed to be consistent across different JS platforms. 6 | 7 | `Example` 8 | 9 | ```js 10 | const F = function () { 11 | this.x = 'X'; 12 | }; 13 | 14 | F.prototype.y = 'Y'; 15 | 16 | const f = new F(); 17 | 18 | R.keysIn(f); //=> ['x', 'y'] 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/last.md: -------------------------------------------------------------------------------- 1 | ### last 2 | 3 | > `[a] → a | Undefined` > `String → String` 4 | 5 | Returns the last element of the given list or string. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.last(['fi', 'fo', 'fum']); //=> 'fum' 11 | R.last([]); //=> undefined 12 | 13 | R.last('abc'); //=> 'c' 14 | R.last(''); //=> '' 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/lastIndexOf.md: -------------------------------------------------------------------------------- 1 | ### lastIndexOf 2 | 3 | > `a → [a] → Number` 4 | 5 | Returns the position of the last occurrence of an item in an array, or -1 if the item is not included in the array. `R.equals` is used to determine equality. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.lastIndexOf(3, [-1, 3, 3, 0, 1, 2, 3, 4]); //=> 6 11 | R.lastIndexOf(10, [1, 2, 3, 4]); //=> -1 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/length.md: -------------------------------------------------------------------------------- 1 | ### length 2 | 3 | > `[a] → Number` 4 | 5 | Returns the number of elements in the array by returning `list.length`. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.length([]); //=> 0 11 | R.length([1, 2, 3]); //=> 3 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/lens.md: -------------------------------------------------------------------------------- 1 | ### lens 2 | 3 | > `(s → a) → ((a, s) → s) → Lens s a` > `Lens s a = Functor f => (a → f a) → s → f s` 4 | 5 | Returns a lens for the given `getter` and `setter` functions. The `getter` "gets" the value of the focus; the `setter` "sets" the value of the focus. The `setter` should not mutate the data structure. 6 | 7 | `Example` 8 | 9 | ```js 10 | const xLens = R.lens(R.prop('x'), R.assoc('x')); 11 | 12 | R.view(xLens, { x: 1, y: 2 }); //=> 1 13 | R.set(xLens, 4, { x: 1, y: 2 }); //=> {x: 4, y: 2} 14 | R.over(xLens, R.negate, { x: 1, y: 2 }); //=> {x: -1, y: 2} 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/lensIndex.md: -------------------------------------------------------------------------------- 1 | ### lensIndex 2 | 3 | > `Number → Lens s a` > `Lens s a = Functor f => (a → f a) → s → f s` 4 | 5 | Returns a lens whose focus is the specified index. 6 | 7 | `Example` 8 | 9 | ```js 10 | const headLens = R.lensIndex(0); 11 | 12 | R.view(headLens, ['a', 'b', 'c']); //=> 'a' 13 | R.set(headLens, 'x', ['a', 'b', 'c']); //=> ['x', 'b', 'c'] 14 | R.over(headLens, R.toUpper, ['a', 'b', 'c']); //=> ['A', 'b', 'c'] 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/lensPath.md: -------------------------------------------------------------------------------- 1 | ### lensPath 2 | 3 | > `[Idx] → Lens s a` > `Idx = String | Int` > `Lens s a = Functor f => (a → f a) → s → f s` 4 | 5 | Returns a lens whose focus is the specified path. 6 | 7 | `Example` 8 | 9 | ```js 10 | const xHeadYLens = R.lensPath(['x', 0, 'y']); 11 | 12 | R.view(xHeadYLens, { 13 | x: [ 14 | { y: 2, z: 3 }, 15 | { y: 4, z: 5 }, 16 | ], 17 | }); 18 | //=> 2 19 | R.set(xHeadYLens, 1, { 20 | x: [ 21 | { y: 2, z: 3 }, 22 | { y: 4, z: 5 }, 23 | ], 24 | }); 25 | //=> {x: [{y: 1, z: 3}, {y: 4, z: 5}]} 26 | R.over(xHeadYLens, R.negate, { 27 | x: [ 28 | { y: 2, z: 3 }, 29 | { y: 4, z: 5 }, 30 | ], 31 | }); 32 | //=> {x: [{y: -2, z: 3}, {y: 4, z: 5}]} 33 | ``` 34 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/lensProp.md: -------------------------------------------------------------------------------- 1 | ### lensProp 2 | 3 | > `String → Lens s a` > `Lens s a = Functor f => (a → f a) → s → f s` 4 | 5 | Returns a lens whose focus is the specified property. 6 | 7 | `Example` 8 | 9 | ```js 10 | const xLens = R.lensProp('x'); 11 | 12 | R.view(xLens, { x: 1, y: 2 }); //=> 1 13 | R.set(xLens, 4, { x: 1, y: 2 }); //=> {x: 4, y: 2} 14 | R.over(xLens, R.negate, { x: 1, y: 2 }); //=> {x: -1, y: 2} 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/lift.md: -------------------------------------------------------------------------------- 1 | ### lift 2 | 3 | > `(*… → *) → ([*]… → [*])` 4 | 5 | "lifts" a function of arity `>` 1 so that it may "map over" a list, Function or other object that satisfies the `FantasyLand Apply` spec. 6 | 7 | `Example` 8 | 9 | ```js 10 | const madd3 = R.lift((a, b, c) => a + b + c); 11 | 12 | madd3([1, 2, 3], [1, 2, 3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7] 13 | 14 | const madd5 = R.lift((a, b, c, d, e) => a + b + c + d + e); 15 | 16 | madd5([1, 2], [3], [4, 5], [6], [7, 8]); //=> [21, 22, 22, 23, 22, 23, 23, 24] 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/liftN.md: -------------------------------------------------------------------------------- 1 | ### liftN 2 | 3 | > `Number → (*… → *) → ([*]… → [*])` 4 | 5 | "lifts" a function to be the specified arity, so that it may "map over" that many lists, Functions or other objects that satisfy the `FantasyLand Apply` spec. 6 | 7 | `Example` 8 | 9 | ```js 10 | const madd3 = R.liftN(3, (...args) => R.sum(args)); 11 | 12 | madd3([1, 2, 3], [1, 2, 3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/lt.md: -------------------------------------------------------------------------------- 1 | ### lt 2 | 3 | > `Ord a => a → a → Boolean` 4 | 5 | Returns `true` if the first argument is less than the second; `false` otherwise. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.lt(2, 1); //=> false 11 | R.lt(2, 2); //=> false 12 | R.lt(2, 3); //=> true 13 | R.lt('a', 'z'); //=> true 14 | R.lt('z', 'a'); //=> false 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/lte.md: -------------------------------------------------------------------------------- 1 | ### lte 2 | 3 | > `Ord a => a → a → Boolean` 4 | 5 | Returns `true` if the first argument is less than or equal to the second; `false` otherwise. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.lte(2, 1); //=> false 11 | R.lte(2, 2); //=> true 12 | R.lte(2, 3); //=> true 13 | R.lte('a', 'z'); //=> true 14 | R.lte('z', 'a'); //=> false 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/map.md: -------------------------------------------------------------------------------- 1 | ### map 2 | 3 | > `Functor f => (a → b) → f a → f b` 4 | 5 | Takes a function and a functor, applies the function to each of the functor's values, and returns a functor of the same shape. 6 | 7 | Ramda provides suitable map implementations for `Array` and `Object`, so this function may be applied to `[1, 2, 3]` or `{x: 1, y: 2, z: 3}`. 8 | 9 | Dispatches to the map method of the second argument, if present. 10 | 11 | Acts as a transducer if a transformer is given in list position. 12 | 13 | Also treats functions as functors and will compose them together. 14 | 15 | `Example` 16 | 17 | ```js 18 | const double = (x) => x * 2; 19 | 20 | R.map(double, [1, 2, 3]); //=> [2, 4, 6] 21 | 22 | R.map(double, { x: 1, y: 2, z: 3 }); //=> {x: 2, y: 4, z: 6} 23 | ``` 24 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mapAccum.md: -------------------------------------------------------------------------------- 1 | ### mapAccum 2 | 3 | > `((acc, x) → (acc, y)) → acc → [x] → (acc, [y])` 4 | 5 | The `mapAccum` function behaves like a combination of `map` and `reduce`; it applies a function to each element of a list, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list. 6 | 7 | The iterator function receives two arguments, acc and value, and should return a tuple `[acc, value]`. 8 | 9 | `Example` 10 | 11 | ```js 12 | const digits = ['1', '2', '3', '4']; 13 | const appender = (a, b) => [a + b, a + b]; 14 | 15 | R.mapAccum(appender, 0, digits); //=> ['01234', ['01', '012', '0123', '01234']] 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mapAccumRight.md: -------------------------------------------------------------------------------- 1 | ### mapAccumRight 2 | 3 | > `((acc, x) → (acc, y)) → acc → [x] → (acc, [y])` 4 | 5 | The `mapAccumRight` function behaves like a combination of `map` and `reduce`; it applies a function to each element of a list, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new list. 6 | 7 | Similar to `mapAccum`, except moves through the input list from the right to the left. 8 | 9 | The iterator function receives two arguments, acc and value, and should return a tuple `[acc, value]`. 10 | 11 | `Example` 12 | 13 | ```js 14 | const digits = ['1', '2', '3', '4']; 15 | const appender = (a, b) => [b + a, b + a]; 16 | 17 | R.mapAccumRight(appender, 5, digits); //=> ['12345', ['12345', '2345', '345', '45']] 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mapObjIndexed.md: -------------------------------------------------------------------------------- 1 | ### mapObjIndexed 2 | 3 | > `((*, String, Object) → *) → Object → Object` 4 | 5 | An Object-specific version of map. The function is applied to three arguments: `(value, key, obj)`. If only the value is significant, use `map` instead. 6 | 7 | `Example` 8 | 9 | ```js 10 | const xyz = { x: 1, y: 2, z: 3 }; 11 | const prependKeyAndDouble = (num, key, obj) => key + num * 2; 12 | 13 | R.mapObjIndexed(prependKeyAndDouble, xyz); //=> { x: 'x2', y: 'y4', z: 'z6' } 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/match.md: -------------------------------------------------------------------------------- 1 | ### match 2 | 3 | > `RegExp → String → [String | Undefined]` 4 | 5 | Tests a regular expression against a `String`. Note that this function will return an empty array when there are no matches. This differs from `String.prototype.match` which returns null when there are no matches. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na'] 11 | R.match(/a/, 'b'); //=> [] 12 | R.match(/a/, null); //=> TypeError: null does not have a method named "match" 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mathMod.md: -------------------------------------------------------------------------------- 1 | ### mathMod 2 | 3 | > `Number → Number → Number` 4 | 5 | `mathMod` behaves like the `modulo` operator should mathematically, unlike the `%` operator (and by extension, `R.modulo`). So while `-17 % 5 is -2, mathMod(-17, 5)` is 3. `mathMod` requires Integer arguments, and returns `NaN` when the modulus is zero or negative. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.mathMod(-17, 5); //=> 3 11 | R.mathMod(17, 5); //=> 2 12 | R.mathMod(17, -5); //=> NaN 13 | R.mathMod(17, 0); //=> NaN 14 | R.mathMod(17.2, 5); //=> NaN 15 | R.mathMod(17, 5.3); //=> NaN 16 | 17 | const clock = R.mathMod(R.__, 12); 18 | 19 | clock(15); //=> 3 20 | clock(24); //=> 0 21 | 22 | const seventeenMod = R.mathMod(17); 23 | 24 | seventeenMod(3); //=> 2 25 | seventeenMod(4); //=> 1 26 | seventeenMod(10); //=> 7 27 | ``` 28 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/max.md: -------------------------------------------------------------------------------- 1 | ### max 2 | 3 | > `Ord a => a → a → a` 4 | 5 | Returns the larger of its two arguments. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.max(789, 123); //=> 789 11 | R.max('a', 'b'); //=> 'b' 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/maxBy.md: -------------------------------------------------------------------------------- 1 | ### maxBy 2 | 3 | > `Ord b => (a → b) → a → a → a` 4 | 5 | Takes a function and two values, and returns whichever value produces the larger result when passed to the provided function. 6 | 7 | `Example` 8 | 9 | ```js 10 | // square :: Number -> Number 11 | const square = (n) => n * n; 12 | 13 | R.maxBy(square, -3, 2); //=> -3 14 | 15 | R.reduce(R.maxBy(square), 0, [3, -5, 4, 1, -2]); //=> -5 16 | R.reduce(R.maxBy(square), 0, []); //=> 0 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mean.md: -------------------------------------------------------------------------------- 1 | ### mean 2 | 3 | > `[Number] → Number` 4 | 5 | Returns the mean of the given list of numbers. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.mean([2, 7, 9]); //=> 6 11 | R.mean([]); //=> NaN 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/median.md: -------------------------------------------------------------------------------- 1 | ### median 2 | 3 | > `[Number] → Number` 4 | 5 | Returns the median of the given list of numbers. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.median([2, 9, 7]); //=> 7 11 | R.median([7, 2, 10, 9]); //=> 8 12 | R.median([]); //=> NaN 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/memoizeWith.md: -------------------------------------------------------------------------------- 1 | ### memoizeWith 2 | 3 | > `(*… → String) → (*… → a) → (*… → a)` 4 | 5 | Creates a new function that, when invoked, caches the result of calling `fn` for a given argument set and returns the result. Subsequent calls to the `memoized` `fn` with the same argument set will not result in an additional call to `fn`; instead, the cached result for that set of arguments will be returned. 6 | 7 | `Example` 8 | 9 | ```js 10 | let count = 0; 11 | const factorial = R.memoizeWith(R.identity, (n) => { 12 | count += 1; 13 | return R.product(R.range(1, n + 1)); 14 | }); 15 | 16 | factorial(5); //=> 120 17 | factorial(5); //=> 120 18 | factorial(5); //=> 120 19 | count; //=> 1 20 | ``` 21 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/merge.md: -------------------------------------------------------------------------------- 1 | ### merge 2 | 3 | > `{k: v} → {k: v} → {k: v}` 4 | 5 | Create a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects, the value from the second object will be used. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.merge({ name: 'fred', age: 10 }, { age: 40 }); 11 | //=> { 'name': 'fred', 'age': 40 } 12 | 13 | const withDefaults = R.merge({ x: 0, y: 0 }); 14 | 15 | withDefaults({ y: 2 }); //=> {x: 0, y: 2} 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mergeAll.md: -------------------------------------------------------------------------------- 1 | ### mergeAll 2 | 3 | > `[{k: v}] → {k: v}` 4 | 5 | Merges a list of objects together into one object. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.mergeAll([{ foo: 1 }, { bar: 2 }, { baz: 3 }]); //=> {foo:1,bar:2,baz:3} 11 | R.mergeAll([{ foo: 1 }, { foo: 2 }, { bar: 2 }]); //=> {foo:2,bar:2} 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mergeDeepLeft.md: -------------------------------------------------------------------------------- 1 | ### mergeDeepLeft 2 | 3 | > `{a} → {a} → {a}` 4 | 5 | Creates a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects and both values are objects, the two values will be recursively merged otherwise the value from the first object will be used. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.mergeDeepLeft( 11 | { name: 'fred', age: 10, contact: { email: 'moo@example.com' } }, 12 | { age: 40, contact: { email: 'baa@example.com' } } 13 | ); 14 | //=> { name: 'fred', age: 10, contact: { email: 'moo@example.com' }} 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mergeDeepRight.md: -------------------------------------------------------------------------------- 1 | ### mergeDeepRight 2 | 3 | > `{a} → {a} → {a}` 4 | 5 | Creates a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects and both values are objects, the two values will be recursively merged otherwise the value from the second object will be used. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.mergeDeepRight( 11 | { name: 'fred', age: 10, contact: { email: 'moo@example.com' } }, 12 | { age: 40, contact: { email: 'baa@example.com' } } 13 | ); 14 | //=> { name: 'fred', age: 40, contact: { email: 'baa@example.com' }} 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mergeDeepWith.md: -------------------------------------------------------------------------------- 1 | ### mergeDeepWith 2 | 3 | > `((a, a) → a) → {a} → {a} → {a}` 4 | 5 | Creates a new object with the own properties of the two provided objects. If a key exists in both objects and both associated values are also objects then the values will be recursively merged. 6 | 7 | Otherwise the provided function is applied to associated values using the resulting value as the new value associated with the key. If a key only exists in one object, the value will be associated with the key of the resulting object. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.mergeDeepWith( 13 | R.concat, 14 | { a: true, c: { values: [10, 20] } }, 15 | { b: true, c: { values: [15, 35] } } 16 | ); 17 | //=> { a: true, b: true, c: { values: [10, 20, 15, 35] }} 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mergeDeepWithKey.md: -------------------------------------------------------------------------------- 1 | ### mergeDeepWithKey 2 | 3 | > `((String, a, a) → a) → {a} → {a} → {a}` 4 | 5 | Creates a new object with the own properties of the two provided objects. If a key exists in both objects and both associated values are also objects then the values will be recursively merged. 6 | 7 | Otherwise the provided function is applied to the key and associated values using the resulting value as the new value associated with the key. If a key only exists in one object, the value will be associated with the key of the resulting object. 8 | 9 | `Example` 10 | 11 | ```js 12 | let concatValues = (k, l, r) => (k == 'values' ? R.concat(l, r) : r); 13 | 14 | R.mergeDeepWithKey( 15 | concatValues, 16 | { a: true, c: { thing: 'foo', values: [10, 20] } }, 17 | { b: true, c: { thing: 'bar', values: [15, 35] } } 18 | ); 19 | //=> { a: true, b: true, c: { thing: 'bar', values: [10, 20, 15, 35] }} 20 | ``` 21 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mergeLeft.md: -------------------------------------------------------------------------------- 1 | ### mergeLeft 2 | 3 | > `{k: v} → {k: v} → {k: v}` 4 | 5 | Create a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects, the value from the first object will be used. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.mergeLeft({ age: 40 }, { name: 'fred', age: 10 }); 11 | //=> { 'name': 'fred', 'age': 40 } 12 | 13 | const resetToDefault = R.mergeLeft({ x: 0 }); 14 | 15 | resetToDefault({ x: 5, y: 2 }); //=> {x: 0, y: 2} 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mergeRight.md: -------------------------------------------------------------------------------- 1 | ### mergeRight 2 | 3 | > `{k: v} → {k: v} → {k: v}` 4 | 5 | Create a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects, the value from the second object will be used. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.mergeRight({ name: 'fred', age: 10 }, { age: 40 }); 11 | //=> { 'name': 'fred', 'age': 40 } 12 | 13 | const withDefaults = R.mergeRight({ x: 0, y: 0 }); 14 | 15 | withDefaults({ y: 2 }); //=> {x: 0, y: 2} 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mergeWith.md: -------------------------------------------------------------------------------- 1 | ### mergeWith 2 | 3 | > `((a, a) → a) → {a} → {a} → {a}` 4 | 5 | Creates a new object with the own properties of the two provided objects. If a key exists in both objects, the provided function is applied to the values associated with the key in each object, with the result being used as the value associated with the key in the returned object. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.mergeWith( 11 | R.concat, 12 | { a: true, values: [10, 20] }, 13 | { b: true, values: [15, 35] } 14 | ); 15 | //=> { a: true, b: true, values: [10, 20, 15, 35] } 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/mergeWithKey.md: -------------------------------------------------------------------------------- 1 | ### mergeWithKey 2 | 3 | > `((String, a, a) → a) → {a} → {a} → {a}` 4 | 5 | Creates a new object with the own properties of the two provided objects. If a key exists in both objects, the provided function is applied to the key and the values associated with the key in each object, with the result being used as the value associated with the key in the returned object. 6 | 7 | `Example` 8 | 9 | ```js 10 | let concatValues = (k, l, r) => (k == 'values' ? R.concat(l, r) : r); 11 | 12 | R.mergeWithKey( 13 | concatValues, 14 | { a: true, thing: 'foo', values: [10, 20] }, 15 | { b: true, thing: 'bar', values: [15, 35] } 16 | ); 17 | //=> { a: true, b: true, thing: 'bar', values: [10, 20, 15, 35] } 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/min.md: -------------------------------------------------------------------------------- 1 | ### min 2 | 3 | > `Ord a => a → a → a` 4 | 5 | Returns the smaller of its two arguments. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.min(789, 123); //=> 123 11 | R.min('a', 'b'); //=> 'a' 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/minBy.md: -------------------------------------------------------------------------------- 1 | ### minBy 2 | 3 | > `Ord b => (a → b) → a → a → a` 4 | 5 | Takes a function and two values, and returns whichever value produces the smaller result when passed to the provided function. 6 | 7 | `Example` 8 | 9 | ```js 10 | // square :: Number -> Number 11 | const square = (n) => n * n; 12 | 13 | R.minBy(square, -3, 2); //=> 2 14 | 15 | R.reduce(R.minBy(square), Infinity, [3, -5, 4, 1, -2]); //=> 1 16 | R.reduce(R.minBy(square), Infinity, []); //=> Infinity 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/modulo.md: -------------------------------------------------------------------------------- 1 | ### modulo 2 | 3 | > `Number → Number → Number` 4 | 5 | Divides the first parameter by the second and returns the remainder. Note that this function preserves the `JavaScript-style` behavior for `modulo`. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.modulo(17, 3); //=> 2 11 | // JS behavior: 12 | R.modulo(-17, 3); //=> -2 13 | R.modulo(17, -3); //=> 2 14 | 15 | const isOdd = R.modulo(R.__, 2); 16 | 17 | isOdd(42); //=> 0 18 | isOdd(21); //=> 1 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/move.md: -------------------------------------------------------------------------------- 1 | ### move 2 | 3 | > `Number → Number → [a] → [a]` 4 | 5 | Move an item, at `index` from, to `index` to, in a list of elements. A new list will be created containing the new elements order. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.move(0, 2, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['b', 'c', 'a', 'd', 'e', 'f'] 11 | R.move(-1, 0, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['f', 'a', 'b', 'c', 'd', 'e'] list rotation 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/multiply.md: -------------------------------------------------------------------------------- 1 | ### multiply 2 | 3 | > `Number → Number → Number` 4 | 5 | Multiplies two numbers. Equivalent to `a * b` but curried. 6 | 7 | `Example` 8 | 9 | ```js 10 | const double = R.multiply(2); 11 | const triple = R.multiply(3); 12 | 13 | double(3); //=> 6 14 | triple(4); //=> 12 15 | 16 | R.multiply(2, 5); //=> 10 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/nAry.md: -------------------------------------------------------------------------------- 1 | ### nAry 2 | 3 | > `Number → (* → a) → (* → a)` 4 | 5 | Wraps a function of any arity (including nullary) in a function that accepts exactly `n` parameters. Any extraneous parameters will not be passed to the supplied function. 6 | 7 | `Example` 8 | 9 | ```js 10 | const takesTwoArgs = (a, b) => [a, b]; 11 | 12 | takesTwoArgs.length; //=> 2 13 | takesTwoArgs(1, 2); //=> [1, 2] 14 | 15 | const takesOneArg = R.nAry(1, takesTwoArgs); 16 | takesOneArg.length; //=> 1 17 | // Only `n` arguments are passed to the wrapped function 18 | takesOneArg(1, 2); //=> [1, undefined] 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/negate.md: -------------------------------------------------------------------------------- 1 | ### negate 2 | 3 | > `Number → Number` 4 | 5 | Negates its argument. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.negate(42); //=> -42 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/none.md: -------------------------------------------------------------------------------- 1 | ### none 2 | 3 | > `(a → Boolean) → [a] → Boolean` 4 | 5 | Returns `true` if no elements of the list match the predicate, `false` otherwise. 6 | 7 | Dispatches to the all method of the second argument, if present. 8 | 9 | Acts as a transducer if a transformer is given in list position. 10 | 11 | `Example` 12 | 13 | ```js 14 | const isEven = (n) => n % 2 === 0; 15 | const isOdd = (n) => n % 2 === 1; 16 | 17 | R.none(isEven, [1, 3, 5, 7, 9, 11]); //=> true 18 | R.none(isOdd, [1, 3, 5, 7, 8, 11]); //=> false 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/not.md: -------------------------------------------------------------------------------- 1 | ### not 2 | 3 | > `* → Boolean` 4 | 5 | A function that returns the `!` of its argument. It will return `true` when passed false-y value, and `false` when passed a truth-y one. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.not(true); //=> false 11 | R.not(false); //=> true 12 | R.not(0); //=> true 13 | R.not(1); //=> false 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/nth.md: -------------------------------------------------------------------------------- 1 | ### nth 2 | 3 | > `Number → [a] → a | Undefined` > `Number → String → String` 4 | 5 | Returns the `nth` element of the given list or string. If `n` is negative the element at index length + `n` is returned. 6 | 7 | `Example` 8 | 9 | ```js 10 | const list = ['foo', 'bar', 'baz', 'quux']; 11 | 12 | R.nth(1, list); //=> 'bar' 13 | R.nth(-1, list); //=> 'quux' 14 | R.nth(-99, list); //=> undefined 15 | 16 | R.nth(2, 'abc'); //=> 'c' 17 | R.nth(3, 'abc'); //=> '' 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/nthArg.md: -------------------------------------------------------------------------------- 1 | ### nthArg 2 | 3 | > `Number → *… → *` 4 | 5 | Returns a function which returns its nth argument. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.nthArg(1)('a', 'b', 'c'); //=> 'b' 11 | R.nthArg(-1)('a', 'b', 'c'); //=> 'c' 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/o.md: -------------------------------------------------------------------------------- 1 | ### o 2 | 3 | > `(b → c) → (a → b) → a → c` 4 | 5 | `o` is a curried composition function that returns a unary function. Like `compose`, `o` performs right-to-left function composition. Unlike `compose`, the rightmost function passed to `o` will be invoked with only one argument. Also, unlike `compose`, `o` is limited to accepting only 2 unary functions. The name `o` was chosen because of its similarity to the mathematical composition operator `∘`. 6 | 7 | `Example` 8 | 9 | ```js 10 | const classyGreeting = (name) => 11 | "The name's " + name.last + ', ' + name.first + ' ' + name.last; 12 | const yellGreeting = R.o(R.toUpper, classyGreeting); 13 | 14 | yellGreeting({ first: 'James', last: 'Bond' }); //=> "THE NAME'S BOND, JAMES BOND" 15 | 16 | R.o(R.multiply(10), R.add(10))(-4); //=> 60 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/objOf.md: -------------------------------------------------------------------------------- 1 | ### objOf 2 | 3 | > `String → a → {String:a}` 4 | 5 | Creates an object containing a single `key:value` pair. 6 | 7 | `Example` 8 | 9 | ```js 10 | const matchPhrases = R.compose(R.objOf('must'), R.map(R.objOf('match_phrase'))); 11 | 12 | matchPhrases(['foo', 'bar', 'baz']); //=> {must: [{match_phrase: 'foo'}, {match_phrase: 'bar'}, {match_phrase: 'baz'}]} 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/of.md: -------------------------------------------------------------------------------- 1 | ### of 2 | 3 | > `a → [a]` 4 | 5 | Returns a singleton array containing the value provided. 6 | 7 | Note this of is different from the `ES6 of`. See [of](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of) 8 | 9 | `Example` 10 | 11 | ```js 12 | R.of(null); //=> [null] 13 | R.of([42]); //=> [[42]] 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/omit.md: -------------------------------------------------------------------------------- 1 | ### omit 2 | 3 | > `[String] → {String: *} → {String: *}` 4 | 5 | Returns a partial copy of an object omitting the keys specified. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.omit(['a', 'd'], { a: 1, b: 2, c: 3, d: 4 }); //=> {b: 2, c: 3} 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/once.md: -------------------------------------------------------------------------------- 1 | ### once 2 | 3 | > `(a… → b) → (a… → b)` 4 | 5 | Accepts a function `fn` and returns a function that guards invocation of `fn` such that `fn` can only ever be called once, no matter how many times the returned function is invoked. The first value calculated is returned in subsequent invocations. 6 | 7 | `Example` 8 | 9 | ```js 10 | const addOneOnce = R.once((x) => x + 1); 11 | 12 | addOneOnce(10); //=> 11 13 | addOneOnce(addOneOnce(50)); //=> 11 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/or.md: -------------------------------------------------------------------------------- 1 | ### or 2 | 3 | > `a → b → a | b` 4 | 5 | Returns `true` if one or both of its arguments are `true`. Returns `false` if both arguments are `false`. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.or(true, true); //=> true 11 | R.or(true, false); //=> true 12 | R.or(false, true); //=> true 13 | R.or(false, false); //=> false 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/otherwise.md: -------------------------------------------------------------------------------- 1 | ### otherwise 2 | 3 | > `(e → b) → (Promise e a) → (Promise e b)` > `(e → (Promise f b)) → (Promise e a) → (Promise f b)` 4 | 5 | Returns the result of applying the `onFailure` function to the value inside a failed `promise`. This is useful for handling rejected promises inside function compositions. 6 | 7 | `Example` 8 | 9 | ```js 10 | var failedFetch = (id) => Promise.reject('bad ID'); 11 | var useDefault = () => ({ firstName: 'Bob', lastName: 'Loblaw' }); 12 | 13 | //recoverFromFailure :: String -> Promise ({firstName, lastName}) 14 | var recoverFromFailure = R.pipe( 15 | failedFetch, 16 | R.otherwise(useDefault), 17 | R.then(R.pick(['firstName', 'lastName'])) 18 | ); 19 | 20 | recoverFromFailure(12345).then(console.log); 21 | ``` 22 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/over.md: -------------------------------------------------------------------------------- 1 | ### over 2 | 3 | > `Lens s a → (a → a) → s → s` > `Lens s a = Functor f => (a → f a) → s → f s` 4 | 5 | Returns the result of "setting" the portion of the given data structure focused by the given lens to the result of applying the given function to the focused value. 6 | 7 | `Example` 8 | 9 | ```js 10 | const headLens = R.lensIndex(0); 11 | 12 | R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']); //=> ['FOO', 'bar', 'baz'] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pair.md: -------------------------------------------------------------------------------- 1 | ### pair 2 | 3 | > `a → b → (a,b)` 4 | 5 | Takes two arguments, `fst` and `snd`, and returns `[fst, snd]`. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.pair('foo', 'bar'); //=> ['foo', 'bar'] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/partial.md: -------------------------------------------------------------------------------- 1 | ### partial 2 | 3 | > `((a, b, c, …, n) → x) → [a, b, c, …] → ((d, e, f, …, n) → x)` 4 | 5 | Takes a function `f` and a list of arguments, and returns a function `g`. When applied, `g` returns the result of applying `f` to the arguments provided initially followed by the arguments provided to `g`. 6 | 7 | `Example` 8 | 9 | ```js 10 | const multiply2 = (a, b) => a * b; 11 | const double = R.partial(multiply2, [2]); 12 | 13 | double(2); //=> 4 14 | 15 | const greet = (salutation, title, firstName, lastName) => 16 | salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!'; 17 | 18 | const sayHello = R.partial(greet, ['Hello']); 19 | const sayHelloToMs = R.partial(sayHello, ['Ms.']); 20 | 21 | sayHelloToMs('Jane', 'Jones'); //=> 'Hello, Ms. Jane Jones!' 22 | ``` 23 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/partialRight.md: -------------------------------------------------------------------------------- 1 | ### partialRight 2 | 3 | > `((a, b, c, …, n) → x) → [d, e, f, …, n] → ((a, b, c, …) → x)` 4 | 5 | Takes a function `f` and a list of arguments, and returns a function `g`. When applied, `g` returns the result of applying `f` to the arguments provided to `g` followed by the arguments provided initially. 6 | 7 | `Example` 8 | 9 | ```js 10 | const greet = (salutation, title, firstName, lastName) => 11 | salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!'; 12 | 13 | const greetMsJaneJones = R.partialRight(greet, ['Ms.', 'Jane', 'Jones']); 14 | 15 | greetMsJaneJones('Hello'); //=> 'Hello, Ms. Jane Jones!' 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/partition.md: -------------------------------------------------------------------------------- 1 | ### partition 2 | 3 | > `Filterable f => (a → Boolean) → f a → [f a, f a]` 4 | 5 | Takes a predicate and a list or other Filterable object and returns the pair of filterable objects of the same type of elements which do and do not satisfy, the predicate, respectively. Filterable objects include plain objects or any object that has a filter method such as `Array`. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.partition(R.includes('s'), ['sss', 'ttt', 'foo', 'bars']); 11 | // => [ [ 'sss', 'bars' ], [ 'ttt', 'foo' ] ] 12 | 13 | R.partition(R.includes('s'), { a: 'sss', b: 'ttt', foo: 'bars' }); 14 | // => [ { a: 'sss', foo: 'bars' }, { b: 'ttt' } ] 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/path.md: -------------------------------------------------------------------------------- 1 | ### path 2 | 3 | > `[Idx] → {a} → a | Undefined` > `Idx = String | Int` 4 | 5 | Retrieve the value at a given path. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.path(['a', 'b'], { a: { b: 2 } }); //=> 2 11 | R.path(['a', 'b'], { c: { b: 2 } }); //=> undefined 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pathEq.md: -------------------------------------------------------------------------------- 1 | ### pathEq 2 | 3 | > `[Idx] → a → {a} → Boolean` > `Idx = String | Int` 4 | 5 | Determines whether a nested path on an object has a specific value, in `R.equals` terms. Most likely used to filter a list. 6 | 7 | `Example` 8 | 9 | ```js 10 | const user1 = { address: { zipCode: 90210 } }; 11 | const user2 = { address: { zipCode: 55555 } }; 12 | const user3 = { name: 'Bob' }; 13 | const users = [user1, user2, user3]; 14 | const isFamous = R.pathEq(['address', 'zipCode'], 90210); 15 | 16 | R.filter(isFamous, users); //=> [ user1 ] 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pathOr.md: -------------------------------------------------------------------------------- 1 | ### pathOr 2 | 3 | > `a → [Idx] → {a} → a` > `Idx = String | Int` 4 | 5 | If the given, non-null object has a value at the given path, returns the value at that path. Otherwise returns the provided default value. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.pathOr('N/A', ['a', 'b'], { a: { b: 2 } }); //=> 2 11 | R.pathOr('N/A', ['a', 'b'], { c: { b: 2 } }); //=> "N/A" 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pathSatisfies.md: -------------------------------------------------------------------------------- 1 | ### pathSatisfies 2 | 3 | > `(a → Boolean) → [Idx] → {a} → Boolean` > `Idx = String | Int` 4 | 5 | Returns `true` if the specified object property at given path satisfies the given predicate; `false` otherwise. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.pathSatisfies((y) => y > 0, ['x', 'y'], { x: { y: 2 } }); //=> true 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pick.md: -------------------------------------------------------------------------------- 1 | ### pick 2 | 3 | > `[k] → {k: v} → {k: v}` 4 | 5 | Returns a partial copy of an object containing only the keys specified. If the key does not exist, the property is ignored. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.pick(['a', 'd'], { a: 1, b: 2, c: 3, d: 4 }); //=> {a: 1, d: 4} 11 | R.pick(['a', 'e', 'f'], { a: 1, b: 2, c: 3, d: 4 }); //=> {a: 1} 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pickAll.md: -------------------------------------------------------------------------------- 1 | ### pickAll 2 | 3 | > `[k] → {k: v} → {k: v}` 4 | 5 | Similar to pick except that this one includes a key: undefined pair for properties that don't exist. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.pickAll(['a', 'd'], { a: 1, b: 2, c: 3, d: 4 }); //=> {a: 1, d: 4} 11 | R.pickAll(['a', 'e', 'f'], { a: 1, b: 2, c: 3, d: 4 }); //=> {a: 1, e: undefined, f: undefined} 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pickBy.md: -------------------------------------------------------------------------------- 1 | ### pickBy 2 | 3 | > `((v, k) → Boolean) → {k: v} → {k: v}` 4 | 5 | Returns a partial copy of an object containing only the keys that satisfy the supplied predicate. 6 | 7 | `Example` 8 | 9 | ```js 10 | const isUpperCase = (val, key) => key.toUpperCase() === key; 11 | 12 | R.pickBy(isUpperCase, { a: 1, b: 2, A: 3, B: 4 }); //=> {A: 3, B: 4} 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pipe.md: -------------------------------------------------------------------------------- 1 | ### pipe 2 | 3 | > `(((a, b, …, n) → o), (o → p), …, (x → y), (y → z)) → ((a, b, …, n) → z)` 4 | 5 | Performs left-to-right function composition. The leftmost function may have any arity; the remaining functions must be unary. 6 | 7 | In some libraries this function is named sequence. 8 | 9 | Note: The result of pipe is not automatically curried. 10 | 11 | `Example` 12 | 13 | ```js 14 | const f = R.pipe(Math.pow, R.negate, R.inc); 15 | 16 | f(3, 4); // -(3^4) + 1 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pipeK.md: -------------------------------------------------------------------------------- 1 | ### pipeK 2 | 3 | > `Chain m => ((a → m b), (b → m c), …, (y → m z)) → (a → m z)` 4 | 5 | Returns the left-to-right `Kleisli` composition of the provided functions, each of which must return a value of a type supported by chain. 6 | 7 | `R.pipeK(f, g, h)` is equivalent to `R.pipe(f, R.chain(g)`, `R.chain(h))`. 8 | 9 | `Example` 10 | 11 | ```js 12 | // parseJson :: String -> Maybe * 13 | // get :: String -> Object -> Maybe * 14 | 15 | // getStateCode :: Maybe String -> Maybe String 16 | const getStateCode = R.pipeK( 17 | parseJson, 18 | get('user'), 19 | get('address'), 20 | get('state'), 21 | R.compose(Maybe.of, R.toUpper) 22 | ); 23 | 24 | getStateCode('{"user":{"address":{"state":"ny"}}}'); 25 | //=> Just('NY') 26 | getStateCode('[Invalid JSON]'); 27 | //=> Nothing() 28 | ``` 29 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pipeP.md: -------------------------------------------------------------------------------- 1 | ### pipeP 2 | 3 | > `((a → Promise b), (b → Promise c), …, (y → Promise z)) → (a → Promise z)` 4 | 5 | Performs left-to-right composition of one or more `Promise-returning` functions. The leftmost function may have any arity. The remaining functions must be unary. 6 | 7 | `Example` 8 | 9 | ```js 10 | // followersForUser :: String -> Promise [User] 11 | const followersForUser = R.pipeP(db.getUserById, db.getFollowers); 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pipeWith.md: -------------------------------------------------------------------------------- 1 | ### pipeWith 2 | 3 | > `((* → *), [((a, b, …, n) → o), (o → p), …, (x → y), (y → z)]) → ((a, b, …, n) → z)` 4 | 5 | Performs left-to-right function composition using transforming function. The leftmost function may have any arity; the remaining functions must be unary. 6 | 7 | Note: The result of `pipeWith` is not automatically curried. 8 | 9 | `Example` 10 | 11 | ```js 12 | const pipeWhileNotNil = R.pipeWith((f, res) => (R.isNil(res) ? res : f(res))); 13 | const f = pipeWhileNotNil([Math.pow, R.negate, R.inc]); 14 | 15 | f(3, 4); // -(3^4) + 1 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/pluck.md: -------------------------------------------------------------------------------- 1 | ### pluck 2 | 3 | > `Functor f => k → f {k: v} → f v` 4 | 5 | Returns a new list by plucking the same named property off all objects in the list supplied. 6 | 7 | `pluck` will work on any functor in addition to arrays, as it is equivalent to `R.map(R.prop(k), f)`. 8 | 9 | `Example` 10 | 11 | ```js 12 | var getAges = R.pluck('age'); 13 | 14 | getAges([ 15 | { name: 'fred', age: 29 }, 16 | { name: 'wilma', age: 27 }, 17 | ]); //=> [29, 27] 18 | 19 | R.pluck(0, [ 20 | [1, 2], 21 | [3, 4], 22 | ]); //=> [1, 3] 23 | R.pluck('val', { a: { val: 3 }, b: { val: 5 } }); //=> {a: 3, b: 5} 24 | ``` 25 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/prepend.md: -------------------------------------------------------------------------------- 1 | ### prepend 2 | 3 | > `a → [a] → [a]` 4 | 5 | Returns a new list with the given element at the front, followed by the contents of the list. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum'] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/product.md: -------------------------------------------------------------------------------- 1 | ### product 2 | 3 | > `[Number] → Number` 4 | 5 | Multiplies together all the elements of a list. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.product([2, 4, 6, 8, 100, 1]); //=> 38400 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/project.md: -------------------------------------------------------------------------------- 1 | ### project 2 | 3 | > `[k] → [{k: v}] → [{k: v}]` 4 | 5 | Reasonable analog to SQL select statement. 6 | 7 | `Example` 8 | 9 | ```js 10 | const abby = { name: 'Abby', age: 7, hair: 'blond', grade: 2 }; 11 | const fred = { name: 'Fred', age: 12, hair: 'brown', grade: 7 }; 12 | const kids = [abby, fred]; 13 | 14 | R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}] 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/prop.md: -------------------------------------------------------------------------------- 1 | ### prop 2 | 3 | > `s → {s: a} → a | Undefined` 4 | 5 | Returns a function that when supplied an object returns the indicated property of that object, if it exists. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.prop('x', { x: 100 }); //=> 100 11 | R.prop('x', {}); //=> undefined 12 | R.compose(R.inc, R.prop('x'))({ x: 3 }); //=> 4 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/propEq.md: -------------------------------------------------------------------------------- 1 | ### propEq 2 | 3 | > `String → a → Object → Boolean` 4 | 5 | Returns `true` if the specified object property is equal, in `R.equals` terms, to the given value; `false` otherwise. You can test multiple properties with `R.whereEq`. 6 | 7 | `Example` 8 | 9 | ```js 10 | const abby = { name: 'Abby', age: 7, hair: 'blond' }; 11 | const fred = { name: 'Fred', age: 12, hair: 'brown' }; 12 | const rusty = { name: 'Rusty', age: 10, hair: 'brown' }; 13 | const alois = { name: 'Alois', age: 15, disposition: 'surly' }; 14 | const kids = [abby, fred, rusty, alois]; 15 | const hasBrownHair = R.propEq('hair', 'brown'); 16 | 17 | R.filter(hasBrownHair, kids); //=> [fred, rusty] 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/propIs.md: -------------------------------------------------------------------------------- 1 | ### propIs 2 | 3 | > `Type → String → Object → Boolean` 4 | 5 | Returns `true` if the specified object property is of the given type; `false` otherwise. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.propIs(Number, 'x', { x: 1, y: 2 }); //=> true 11 | R.propIs(Number, 'x', { x: 'foo' }); //=> false 12 | R.propIs(Number, 'x', {}); //=> false 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/propOr.md: -------------------------------------------------------------------------------- 1 | ### propOr 2 | 3 | > `a → String → Object → a` 4 | 5 | If the given, non-null object has an own property with the specified name, returns the value of that property. Otherwise returns the provided default value. 6 | 7 | `Example` 8 | 9 | ```js 10 | const alice = { 11 | name: 'ALICE', 12 | age: 101, 13 | }; 14 | const favorite = R.prop('favoriteLibrary'); 15 | const favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary'); 16 | 17 | favorite(alice); //=> undefined 18 | favoriteWithDefault(alice); //=> 'Ramda' 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/propSatisfies.md: -------------------------------------------------------------------------------- 1 | ### propSatisfies 2 | 3 | > `(a → Boolean) → String → {String: a} → Boolean` 4 | 5 | Returns `true` if the specified object property satisfies the given predicate; `false` otherwise. You can test multiple properties with `R.where`. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.propSatisfies((x) => x > 0, 'x', { x: 1, y: 2 }); //=> true 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/props.md: -------------------------------------------------------------------------------- 1 | ### props 2 | 3 | > `[k] → {k: v} → [v]` 4 | 5 | Acts as multiple prop: array of keys in, array of values out. Preserves order. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.props(['x', 'y'], { x: 1, y: 2 }); //=> [1, 2] 11 | R.props(['c', 'a', 'b'], { b: 2, a: 1 }); //=> [undefined, 1, 2] 12 | 13 | const fullName = R.compose(R.join(' '), R.props(['first', 'last'])); 14 | 15 | fullName({ last: 'Bullet-Tooth', age: 33, first: 'Tony' }); //=> 'Tony Bullet-Tooth' 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/range.md: -------------------------------------------------------------------------------- 1 | ### range 2 | 3 | > `Number → Number → [Number]` 4 | 5 | Returns a list of numbers from from (inclusive) to to (exclusive). 6 | 7 | `Example` 8 | 9 | ```js 10 | R.range(1, 5); //=> [1, 2, 3, 4] 11 | R.range(50, 53); //=> [50, 51, 52] 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/reduceWhile.md: -------------------------------------------------------------------------------- 1 | ### reduceWhile 2 | 3 | > `((a, b) → Boolean) → ((a, b) → a) → a → [b] → a` 4 | 5 | Like `reduce`, `reduceWhile` returns a single item by iterating through the list, successively calling the iterator function. `reduceWhile` also takes a predicate that is evaluated before each step. If the predicate returns `false`, it "short-circuits" the iteration and returns the current value of the accumulator. 6 | 7 | `Example` 8 | 9 | ```js 10 | const isOdd = (acc, x) => x % 2 === 1; 11 | const xs = [1, 3, 5, 60, 777, 800]; 12 | 13 | R.reduceWhile(isOdd, R.add, 0, xs); //=> 9 14 | 15 | const ys = [2, 4, 6]; 16 | 17 | R.reduceWhile(isOdd, R.add, 111, ys); //=> 111 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/reduced.md: -------------------------------------------------------------------------------- 1 | ### reduced 2 | 3 | > `a → *` 4 | 5 | Returns a value wrapped to indicate that it is the final value of the reduce and transduce functions. The returned value should be considered a black box. The internal structure is not guaranteed to be stable. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.reduce( 11 | (acc, item) => (item > 3 ? R.reduced(acc) : acc.concat(item)), 12 | [], 13 | [1, 2, 3, 4, 5] 14 | ); // [1, 2, 3] 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/reject.md: -------------------------------------------------------------------------------- 1 | ### reject 2 | 3 | > `Filterable f => (a → Boolean) → f a → f a` 4 | 5 | The complement of filter. 6 | 7 | Acts as a transducer if a transformer is given in list position. Filterable objects include plain objects or any object that has a filter method such as `Array`. 8 | 9 | `Example` 10 | 11 | ```js 12 | const isOdd = (n) => n % 2 === 1; 13 | 14 | R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4] 15 | 16 | R.reject(isOdd, { a: 1, b: 2, c: 3, d: 4 }); //=> {b: 2, d: 4} 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/remove.md: -------------------------------------------------------------------------------- 1 | ### remove 2 | 3 | > `Number → Number → [a] → [a]` 4 | 5 | Removes the sub-list of list starting at index start and containing count elements. Note that this is not destructive: it returns a copy of the list with the changes. No lists have been harmed in the application of this function. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.remove(2, 3, [1, 2, 3, 4, 5, 6, 7, 8]); //=> [1,2,6,7,8] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/repeat.md: -------------------------------------------------------------------------------- 1 | ### repeat 2 | 3 | > `a → n → [a]` 4 | 5 | Returns a fixed list of size `n` containing a specified identical value. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi'] 11 | 12 | const obj = {}; 13 | const repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}] 14 | 15 | repeatedObjs[0] === repeatedObjs[1]; //=> true 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/replace.md: -------------------------------------------------------------------------------- 1 | ### replace 2 | 3 | > `RegExp|String → String → String → String` 4 | 5 | Replace a substring or regex match in a string with a replacement. 6 | 7 | The first two parameters correspond to the parameters of the `String.prototype.replace()` function, so the second parameter can also be a function. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo' 13 | R.replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo' 14 | 15 | // Use the "g" (global) flag to replace all occurrences: 16 | R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar' 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/reverse.md: -------------------------------------------------------------------------------- 1 | ### reverse 2 | 3 | > `[a] → [a]` > `String → String` 4 | 5 | Returns a new list or string with the elements or characters in reverse order. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.reverse([1, 2, 3]); //=> [3, 2, 1] 11 | R.reverse([1, 2]); //=> [2, 1] 12 | R.reverse([1]); //=> [1] 13 | R.reverse([]); //=> [] 14 | 15 | R.reverse('abc'); //=> 'cba' 16 | R.reverse('ab'); //=> 'ba' 17 | R.reverse('a'); //=> 'a' 18 | R.reverse(''); //=> '' 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/scan.md: -------------------------------------------------------------------------------- 1 | ### scan 2 | 3 | > `((a, b) → a) → a → [b] → [a]` 4 | 5 | Scan is similar to `reduce`, but returns a list of successively reduced values from the left 6 | 7 | `Example` 8 | 9 | ```js 10 | const numbers = [1, 2, 3, 4]; 11 | const factorials = R.scan(R.multiply, 1, numbers); //=> [1, 1, 2, 6, 24] 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/sequence.md: -------------------------------------------------------------------------------- 1 | ### sequence 2 | 3 | > `(Applicative f, Traversable t) => (a → f a) → t (f a) → f (t a)` 4 | 5 | Transforms a Traversable of Applicative into an Applicative of Traversable. 6 | 7 | Dispatches to the sequence method of the second argument, if present. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.sequence(Maybe.of, [Just(1), Just(2), Just(3)]); //=> Just([1, 2, 3]) 13 | R.sequence(Maybe.of, [Just(1), Just(2), Nothing()]); //=> Nothing() 14 | 15 | R.sequence(R.of, Just([1, 2, 3])); //=> [Just(1), Just(2), Just(3)] 16 | R.sequence(R.of, Nothing()); //=> [Nothing()] 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/set.md: -------------------------------------------------------------------------------- 1 | ### set 2 | 3 | > `Lens s a → a → s → s` > `Lens s a = Functor f => (a → f a) → s → f s` 4 | 5 | Returns the result of "setting" the portion of the given data structure focused by the given lens to the given value. 6 | 7 | `Example` 8 | 9 | ```js 10 | const xLens = R.lensProp('x'); 11 | 12 | R.set(xLens, 4, { x: 1, y: 2 }); //=> {x: 4, y: 2} 13 | R.set(xLens, 8, { x: 1, y: 2 }); //=> {x: 8, y: 2} 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/slice.md: -------------------------------------------------------------------------------- 1 | ### slice 2 | 3 | > `Number → Number → [a] → [a]` > `Number → Number → String → String` 4 | 5 | Returns the elements of the given list or string (or object with a slice method) from `fromIndex` (inclusive) to `toIndex` (exclusive). 6 | 7 | Dispatches to the slice method of the third argument, if present. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.slice(1, 3, ['a', 'b', 'c', 'd']); //=> ['b', 'c'] 13 | R.slice(1, Infinity, ['a', 'b', 'c', 'd']); //=> ['b', 'c', 'd'] 14 | R.slice(0, -1, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c'] 15 | R.slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c'] 16 | R.slice(0, 3, 'ramda'); //=> 'ram' 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/sort.md: -------------------------------------------------------------------------------- 1 | ### sort 2 | 3 | > `((a, a) → Number) → [a] → [a]` 4 | 5 | Returns a copy of the list, sorted according to the comparator function, which should accept two values at a time and return a negative number if the first value is smaller, a positive number if it's larger, and zero if they are equal. Please note that this is a copy of the list. It does not modify the original. 6 | 7 | `Example` 8 | 9 | ```js 10 | const diff = function (a, b) { 11 | return a - b; 12 | }; 13 | R.sort(diff, [4, 2, 7, 5]); //=> [2, 4, 5, 7] 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/sortBy.md: -------------------------------------------------------------------------------- 1 | ### sortBy 2 | 3 | > `Ord b => (a → b) → [a] → [a]` 4 | 5 | Sorts the list according to the supplied function. 6 | 7 | `Example` 8 | 9 | ```js 10 | const sortByFirstItem = R.sortBy(R.prop(0)); 11 | const pairs = [ 12 | [-1, 1], 13 | [-2, 2], 14 | [-3, 3], 15 | ]; 16 | 17 | sortByFirstItem(pairs); //=> [[-3, 3], [-2, 2], [-1, 1]] 18 | 19 | const sortByNameCaseInsensitive = R.sortBy( 20 | R.compose(R.toLower, R.prop('name')) 21 | ); 22 | 23 | const alice = { 24 | name: 'ALICE', 25 | age: 101, 26 | }; 27 | 28 | const bob = { 29 | name: 'Bob', 30 | age: -10, 31 | }; 32 | 33 | const clara = { 34 | name: 'clara', 35 | age: 314.159, 36 | }; 37 | 38 | const people = [clara, bob, alice]; 39 | 40 | sortByNameCaseInsensitive(people); //=> [alice, bob, clara] 41 | ``` 42 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/sortWith.md: -------------------------------------------------------------------------------- 1 | ### sortWith 2 | 3 | > `[(a, a) → Number] → [a] → [a]` 4 | 5 | Sorts a list according to a list of comparators. 6 | 7 | `Example` 8 | 9 | ```js 10 | const alice = { 11 | name: 'alice', 12 | age: 40, 13 | }; 14 | 15 | const bob = { 16 | name: 'bob', 17 | age: 30, 18 | }; 19 | 20 | const clara = { 21 | name: 'clara', 22 | age: 40, 23 | }; 24 | 25 | const people = [clara, bob, alice]; 26 | const ageNameSort = R.sortWith([ 27 | R.descend(R.prop('age')), 28 | R.ascend(R.prop('name')), 29 | ]); 30 | 31 | ageNameSort(people); //=> [alice, clara, bob] 32 | ``` 33 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/split.md: -------------------------------------------------------------------------------- 1 | ### split 2 | 3 | > `(String | RegExp) → String → [String]` 4 | 5 | Splits a string into an array of strings based on the given separator. 6 | 7 | `Example` 8 | 9 | ```js 10 | const pathComponents = R.split('/'); 11 | R.tail(pathComponents('/usr/local/bin/node')); //=> ['usr', 'local', 'bin', 'node'] 12 | 13 | R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd'] 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/splitAt.md: -------------------------------------------------------------------------------- 1 | ### splitAt 2 | 3 | > `Number → [a] → [[a], [a]]` > `Number → String → [String, String]` 4 | 5 | Splits a given list or string at a given index. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.splitAt(1, [1, 2, 3]); //=> [[1], [2, 3]] 11 | R.splitAt(5, 'hello world'); //=> ['hello', ' world'] 12 | R.splitAt(-1, 'foobar'); //=> ['fooba', 'r'] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/splitEvery.md: -------------------------------------------------------------------------------- 1 | ### splitEvery 2 | 3 | > `Number → [a] → [[a]]` > `Number → String → [String]` 4 | 5 | Splits a collection into slices of the specified length. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); //=> [[1, 2, 3], [4, 5, 6], [7]] 11 | R.splitEvery(3, 'foobarbaz'); //=> ['foo', 'bar', 'baz'] 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/splitWhen.md: -------------------------------------------------------------------------------- 1 | ### splitWhen 2 | 3 | > `(a → Boolean) → [a] → [[a], [a]]` 4 | 5 | Takes a list and a predicate and returns a pair of lists with the following properties: 6 | 7 | The result of concatenating the two output lists is equivalent to the input list, none of the elements of the first output list satisfies the predicate and if the second output list is non-empty, its first element satisfies the predicate. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); //=> [[1], [2, 3, 1, 2, 3]] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/startsWith.md: -------------------------------------------------------------------------------- 1 | ### startsWith 2 | 3 | > `[a] → [a] → Boolean` > `String → String → Boolean` 4 | 5 | Checks if a list starts with the provided sublist. 6 | 7 | Similarly, checks if a string starts with the provided substring. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.startsWith('a', 'abc'); //=> true 13 | R.startsWith('b', 'abc'); //=> false 14 | R.startsWith(['a'], ['a', 'b', 'c']); //=> true 15 | R.startsWith(['b'], ['a', 'b', 'c']); //=> false 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/subtract.md: -------------------------------------------------------------------------------- 1 | ### subtract 2 | 3 | > `Number → Number → Number` 4 | 5 | Subtracts its second argument from its first argument. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.subtract(10, 8); //=> 2 11 | 12 | const minus5 = R.subtract(R.__, 5); 13 | 14 | minus5(17); //=> 12 15 | 16 | const complementaryAngle = R.subtract(90); 17 | 18 | complementaryAngle(30); //=> 60 19 | complementaryAngle(72); //=> 18 20 | ``` 21 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/sum.md: -------------------------------------------------------------------------------- 1 | ### sum 2 | 3 | > `[Number] → Number` 4 | 5 | Adds together all the elements of a list. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.sum([2, 4, 6, 8, 100, 1]); //=> 121 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/symmetricDifference.md: -------------------------------------------------------------------------------- 1 | ### symmetricDifference 2 | 3 | > `[*] → [*] → [*]` 4 | 5 | Finds the set (i.e. no duplicates) of all elements contained in the first or second list, but not both. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.symmetricDifference([1, 2, 3, 4], [7, 6, 5, 4, 3]); //=> [1,2,7,6,5] 11 | R.symmetricDifference([7, 6, 5, 4, 3], [1, 2, 3, 4]); //=> [7,6,5,1,2] 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/symmetricDifferenceWith.md: -------------------------------------------------------------------------------- 1 | ### symmetricDifferenceWith 2 | 3 | > `((a, a) → Boolean) → [a] → [a] → [a]` 4 | 5 | Finds the set (i.e. no duplicates) of all elements contained in the first or second list, but not both. Duplication is determined according to the value returned by applying the supplied predicate to two list elements. 6 | 7 | `Example` 8 | 9 | ```js 10 | const eqA = R.eqBy(R.prop('a')); 11 | const l1 = [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }]; 12 | const l2 = [{ a: 3 }, { a: 4 }, { a: 5 }, { a: 6 }]; 13 | R.symmetricDifferenceWith(eqA, l1, l2); //=> [{a: 1}, {a: 2}, {a: 5}, {a: 6}] 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/tail.md: -------------------------------------------------------------------------------- 1 | ### tail 2 | 3 | > `[a] → [a]` > `String → String` 4 | 5 | Returns all but the first element of the given list or string (or object with a tail method). 6 | 7 | Dispatches to the slice method of the first argument, if present. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.tail([1, 2, 3]); //=> [2, 3] 13 | R.tail([1, 2]); //=> [2] 14 | R.tail([1]); //=> [] 15 | R.tail([]); //=> [] 16 | 17 | R.tail('abc'); //=> 'bc' 18 | R.tail('ab'); //=> 'b' 19 | R.tail('a'); //=> '' 20 | R.tail(''); //=> '' 21 | ``` 22 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/take.md: -------------------------------------------------------------------------------- 1 | ### take 2 | 3 | > `Number → [a] → [a]` > `Number → String → String` 4 | 5 | Returns the first `n` elements of the given list, string, or transducer/transformer (or object with a take method). 6 | 7 | Dispatches to the take method of the second argument, if present. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.take(1, ['foo', 'bar', 'baz']); //=> ['foo'] 13 | R.take(2, ['foo', 'bar', 'baz']); //=> ['foo', 'bar'] 14 | R.take(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] 15 | R.take(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] 16 | R.take(3, 'ramda'); //=> 'ram' 17 | 18 | const personnel = [ 19 | 'Dave Brubeck', 20 | 'Paul Desmond', 21 | 'Eugene Wright', 22 | 'Joe Morello', 23 | 'Gerry Mulligan', 24 | 'Bob Bates', 25 | 'Joe Dodge', 26 | 'Ron Crotty', 27 | ]; 28 | 29 | const takeFive = R.take(5); 30 | 31 | takeFive(personnel); 32 | //=> ['Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan'] 33 | ``` 34 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/takeLast.md: -------------------------------------------------------------------------------- 1 | ### takeLast 2 | 3 | > `Number → [a] → [a]` > `Number → String → String` 4 | 5 | Returns a new list containing the last `n` elements of the given list. If `n > list.length`, returns a list of `list.length` elements. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.takeLast(1, ['foo', 'bar', 'baz']); //=> ['baz'] 11 | R.takeLast(2, ['foo', 'bar', 'baz']); //=> ['bar', 'baz'] 12 | R.takeLast(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] 13 | R.takeLast(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] 14 | R.takeLast(3, 'ramda'); //=> 'mda' 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/takeLastWhile.md: -------------------------------------------------------------------------------- 1 | ### takeLastWhile 2 | 3 | > `(a → Boolean) → [a] → [a]` > `(a → Boolean) → String → String` 4 | 5 | Returns a new list containing the last `n` elements of a given list, passing each value to the supplied predicate function, and terminating when the predicate function returns `false`. Excludes the element that caused the predicate function to fail. The predicate function is passed one argument: (value). 6 | 7 | `Example` 8 | 9 | ```js 10 | const isNotOne = (x) => x !== 1; 11 | 12 | R.takeLastWhile(isNotOne, [1, 2, 3, 4]); //=> [2, 3, 4] 13 | 14 | R.takeLastWhile((x) => x !== 'R', 'Ramda'); //=> 'amda' 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/takeWhile.md: -------------------------------------------------------------------------------- 1 | ### takeWhile 2 | 3 | > `(a → Boolean) → [a] → [a]` > `(a → Boolean) → String → String` 4 | 5 | Returns a new list containing the first `n` elements of a given list, passing each value to the supplied predicate function, and terminating when the predicate function returns `false`. Excludes the element that caused the predicate function to fail. The predicate function is passed one argument: (value). 6 | 7 | Dispatches to the `takeWhile` method of the second argument, if present. 8 | 9 | Acts as a transducer if a transformer is given in list position. 10 | 11 | `Example` 12 | 13 | ```js 14 | const isNotFour = (x) => x !== 4; 15 | 16 | R.takeWhile(isNotFour, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3] 17 | 18 | R.takeWhile((x) => x !== 'd', 'Ramda'); //=> 'Ram' 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/tap.md: -------------------------------------------------------------------------------- 1 | ### tap 2 | 3 | > `(a → *) → a → a` 4 | 5 | Runs the given function with the supplied object, then returns the object. 6 | 7 | Acts as a transducer if a transformer is given as second parameter. 8 | 9 | `Example` 10 | 11 | ```js 12 | const sayX = (x) => console.log('x is ' + x); 13 | 14 | R.tap(sayX, 100); //=> 100 15 | // logs 'x is 100' 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/test.md: -------------------------------------------------------------------------------- 1 | ### test 2 | 3 | > `RegExp → String → Boolean` 4 | 5 | Determines whether a given string matches a given regular expression. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.test(/^x/, 'xyz'); //=> true 11 | R.test(/^y/, 'xyz'); //=> false 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/then.md: -------------------------------------------------------------------------------- 1 | ### then 2 | 3 | > `(a → b) → (Promise e a) → (Promise e b)` > `(a → (Promise e b)) → (Promise e a) → (Promise e b)` 4 | 5 | Returns the result of applying the `onSuccess` function to the value inside a successfully resolved promise. This is useful for working with `promises` inside function compositions. 6 | 7 | `Example` 8 | 9 | ```js 10 | var makeQuery = (email) => ({ query: { email } }); 11 | 12 | //getMemberName :: String -> Promise ({firstName, lastName}) 13 | var getMemberName = R.pipe( 14 | makeQuery, 15 | fetchMember, 16 | R.then(R.pick(['firstName', 'lastName'])) 17 | ); 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/thunkify.md: -------------------------------------------------------------------------------- 1 | ### thunkify 2 | 3 | > `((a, b, …, j) → k) → (a, b, …, j) → (() → k)` 4 | 5 | Creates a thunk out of a function. A thunk delays a calculation until its result is needed, providing lazy evaluation of arguments. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.thunkify(R.identity)(42)(); //=> 42 11 | R.thunkify((a, b) => a + b)(25, 17)(); //=> 42 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/times.md: -------------------------------------------------------------------------------- 1 | ### times 2 | 3 | > `(Number → a) → Number → [a]` 4 | 5 | Calls an input function `n` times, returning an array containing the results of those function calls. 6 | 7 | `fn` is passed one argument: The current value of `n`, which begins at 0 and is gradually incremented to `n - 1`. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.times(R.identity, 5); //=> [0, 1, 2, 3, 4] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/toLower.md: -------------------------------------------------------------------------------- 1 | ### toLower 2 | 3 | > `String → String` 4 | 5 | The lower case version of a string. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.toLower('XYZ'); //=> 'xyz' 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/toPairs.md: -------------------------------------------------------------------------------- 1 | ### toPairs 2 | 3 | > `{String: *} → [[String,*]]` 4 | 5 | Converts an object into an array of key, value arrays. Only the object's own properties are used. Note that the order of the output array is not guaranteed to be consistent across different JS platforms. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.toPairs({ a: 1, b: 2, c: 3 }); //=> [['a', 1], ['b', 2], ['c', 3]] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/toPairsIn.md: -------------------------------------------------------------------------------- 1 | ### toPairsIn 2 | 3 | > `{String: *} → [[String,*]]` 4 | 5 | Converts an object into an array of key, value arrays. The object's own properties and prototype properties are used. Note that the order of the output array is not guaranteed to be consistent across different JS platforms. 6 | 7 | `Example` 8 | 9 | ```js 10 | const F = function () { 11 | this.x = 'X'; 12 | }; 13 | 14 | F.prototype.y = 'Y'; 15 | 16 | const f = new F(); 17 | 18 | R.toPairsIn(f); //=> [['x','X'], ['y','Y']] 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/toUpper.md: -------------------------------------------------------------------------------- 1 | ### toUpper 2 | 3 | > `String → String` 4 | 5 | The upper case version of a string. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.toUpper('abc'); //=> 'ABC' 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/transpose.md: -------------------------------------------------------------------------------- 1 | ### transpose 2 | 3 | > `[[a]] → [[a]]` 4 | 5 | Transposes the rows and columns of a 2D list. When passed a list of n lists of length `x`, returns a list of `x` lists of length `n`. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.transpose([ 11 | [1, 'a'], 12 | [2, 'b'], 13 | [3, 'c'], 14 | ]); //=> [[1, 2, 3], ['a', 'b', 'c']] 15 | R.transpose([ 16 | [1, 2, 3], 17 | ['a', 'b', 'c'], 18 | ]); //=> [[1, 'a'], [2, 'b'], [3, 'c']] 19 | 20 | // If some of the rows are shorter than the following rows, their elements are skipped: 21 | R.transpose([[10, 11], [20], [], [30, 31, 32]]); //=> [[10, 20, 30], [11, 31], [32]] 22 | ``` 23 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/traverse.md: -------------------------------------------------------------------------------- 1 | ### traverse 2 | 3 | > `(Applicative f, Traversable t) => (a → f a) → (a → f b) → t a → f (t b)` 4 | 5 | Maps an `Applicative-returning` function over a `Traversable`, then uses sequence to transform the resulting `Traversable` of `Applicative` into an `Applicative` of `Traversable`. 6 | 7 | Dispatches to the traverse method of the third argument, if present. 8 | 9 | `Example` 10 | 11 | ```js 12 | // Returns `Maybe.Nothing` if the given divisor is `0` 13 | const safeDiv = (n) => (d) => d === 0 ? Maybe.Nothing() : Maybe.Just(n / d); 14 | 15 | R.traverse(Maybe.of, safeDiv(10), [2, 4, 5]); //=> Maybe.Just([5, 2.5, 2]) 16 | R.traverse(Maybe.of, safeDiv(10), [2, 0, 5]); //=> Maybe.Nothing 17 | ``` 18 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/trim.md: -------------------------------------------------------------------------------- 1 | ### trim 2 | 3 | > `String → String` 4 | 5 | Removes (strips) whitespace from both ends of the string. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.trim(' xyz '); //=> 'xyz' 11 | R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z'] 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/tryCatch.md: -------------------------------------------------------------------------------- 1 | ### tryCatch 2 | 3 | > `(…x → a) → ((e, …x) → a) → (…x → a)` 4 | 5 | `tryCatch` takes two functions, a `tryer` and a `catcher`. The returned function evaluates the `tryer`; if it does not `throw`, it simply returns the result. If the `tryer` does `throw`, the returned function evaluates the `catcher` function and returns its result. Note that for effective composition with this function, both the `tryer` and `catcher` functions must return the same type of results. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.tryCatch(R.prop('x'), R.F)({ x: true }); //=> true 11 | R.tryCatch(() => { 12 | throw 'foo'; 13 | }, R.always('catched'))('bar'); // => 'catched' 14 | R.tryCatch(R.times(R.identity), R.always([]))('s'); // => [] 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/type.md: -------------------------------------------------------------------------------- 1 | ### type 2 | 3 | > `(* → {*}) → String` 4 | 5 | Gives a single-word string description of the (native) type of a value, returning such answers as '`Object`', '`Number`', '`Array`', or '`Null`'. Does not attempt to distinguish user `Object` types any further, reporting them all as '`Object`'. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.type({}); //=> "Object" 11 | R.type(1); //=> "Number" 12 | R.type(false); //=> "Boolean" 13 | R.type('s'); //=> "String" 14 | R.type(null); //=> "Null" 15 | R.type([]); //=> "Array" 16 | R.type(/[A-z]/); //=> "RegExp" 17 | R.type(() => {}); //=> "Function" 18 | R.type(undefined); //=> "Undefined" 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/unapply.md: -------------------------------------------------------------------------------- 1 | ### unapply 2 | 3 | > `([*…] → a) → (*… → a)` 4 | 5 | Takes a function `fn`, which takes a single array argument, and returns a function which: 6 | 7 | Takes any number of positional arguments, passes these arguments to `fn` as an array, and returns the result. 8 | In other words, `R.unapply` derives a variadic function from a function which takes an array. `R.unapply` is the inverse of `R.apply`. 9 | 10 | `Example` 11 | 12 | ```js 13 | R.unapply(JSON.stringify)(1, 2, 3); //=> '[1,2,3]' 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/unary.md: -------------------------------------------------------------------------------- 1 | ### unary 2 | 3 | > `(* → b) → (a → b)` 4 | 5 | Wraps a function of any arity (including nullary) in a function that accepts exactly 1 parameter. Any extraneous parameters will not be passed to the supplied function. 6 | 7 | `Example` 8 | 9 | ```js 10 | const takesTwoArgs = function (a, b) { 11 | return [a, b]; 12 | }; 13 | 14 | takesTwoArgs.length; //=> 2 15 | takesTwoArgs(1, 2); //=> [1, 2] 16 | 17 | const takesOneArg = R.unary(takesTwoArgs); 18 | 19 | takesOneArg.length; //=> 1 20 | // Only 1 argument is passed to the wrapped function 21 | takesOneArg(1, 2); //=> [1, undefined] 22 | ``` 23 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/uncurryN.md: -------------------------------------------------------------------------------- 1 | ### uncurryN 2 | 3 | > `Number → (a → b) → (a → c)` 4 | 5 | Returns a function of arity n from a (manually) curried function. 6 | 7 | `Example` 8 | 9 | ```js 10 | const addFour = (a) => (b) => (c) => (d) => a + b + c + d; 11 | 12 | const uncurriedAddFour = R.uncurryN(4, addFour); 13 | 14 | uncurriedAddFour(1, 2, 3, 4); //=> 10 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/unfold.md: -------------------------------------------------------------------------------- 1 | ### unfold 2 | 3 | > `(a → [b]) → * → [b]` 4 | 5 | Builds a list from a seed value. Accepts an iterator function, which returns either false to stop iteration or an array of length 2 containing the value to add to the resulting list and the seed to be used in the next call to the iterator function. 6 | 7 | The iterator function receives one argument: (seed). 8 | 9 | `Example` 10 | 11 | ```js 12 | const f = (n) => (n > 50 ? false : [-n, n + 10]); 13 | 14 | R.unfold(f, 10); //=> [-10, -20, -30, -40, -50] 15 | ``` 16 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/union.md: -------------------------------------------------------------------------------- 1 | ### union 2 | 3 | > `[*] → [*] → [*]` 4 | 5 | Combines two lists into a set (i.e. no duplicates) composed of the elements of each list. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.union([1, 2, 3], [2, 3, 4]); //=> [1, 2, 3, 4] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/unionWith.md: -------------------------------------------------------------------------------- 1 | ### unionWith 2 | 3 | > `((a, a) → Boolean) → [*] → [*] → [*]` 4 | 5 | Combines two lists into a set (i.e. no duplicates) composed of the elements of each list. Duplication is determined according to the value returned by applying the supplied predicate to two list elements. 6 | 7 | `Example` 8 | 9 | ```js 10 | const l1 = [{ a: 1 }, { a: 2 }]; 11 | const l2 = [{ a: 1 }, { a: 4 }]; 12 | 13 | R.unionWith(R.eqBy(R.prop('a')), l1, l2); //=> [{a: 1}, {a: 2}, {a: 4}] 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/uniq.md: -------------------------------------------------------------------------------- 1 | ### uniq 2 | 3 | > `[a] → [a]` 4 | 5 | Returns a new list containing only one copy of each element in the original list. `R.equals` is used to determine equality. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.uniq([1, 1, 2, 1]); //=> [1, 2] 11 | R.uniq([1, '1']); //=> [1, '1'] 12 | R.uniq([[42], [42]]); //=> [[42]] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/uniqBy.md: -------------------------------------------------------------------------------- 1 | ### uniqBy 2 | 3 | > `(a → b) → [a] → [a]` 4 | 5 | Returns a new list containing only one copy of each element in the original list, based upon the value returned by applying the supplied function to each list element. Prefers the first item if the supplied function produces the same value on two items. `R.equals` is used for comparison. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.uniqBy(Math.abs, [-1, -5, 2, 10, 1, 2]); //=> [-1, -5, 2, 10] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/uniqWith.md: -------------------------------------------------------------------------------- 1 | ### uniqWith 2 | 3 | > `((a, a) → Boolean) → [a] → [a]` 4 | 5 | Returns a new list containing only one copy of each element in the original list, based upon the value returned by applying the supplied predicate to two list elements. Prefers the first item if two items compare equal based on the predicate. 6 | 7 | `Example` 8 | 9 | ```js 10 | const strEq = R.eqBy(String); 11 | 12 | R.uniqWith(strEq)([1, '1', 2, 1]); //=> [1, 2] 13 | R.uniqWith(strEq)([{}, {}]); //=> [{}] 14 | R.uniqWith(strEq)([1, '1', 1]); //=> [1] 15 | R.uniqWith(strEq)(['1', 1, 1]); //=> ['1'] 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/unless.md: -------------------------------------------------------------------------------- 1 | ### unless 2 | 3 | > `(a → Boolean) → (a → a) → a → a` 4 | 5 | Tests the final argument by passing it to the given predicate function. If the predicate is not satisfied, the function will return the result of calling the `whenFalseFn` function with the same argument. If the predicate is satisfied, the argument is returned as is. 6 | 7 | `Example` 8 | 9 | ```js 10 | let safeInc = R.unless(R.isNil, R.inc); 11 | 12 | safeInc(null); //=> null 13 | safeInc(1); //=> 2 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/unnest.md: -------------------------------------------------------------------------------- 1 | ### unnest 2 | 3 | > `Chain c => c (c a) → c a` 4 | 5 | Shorthand for `R.chain(R.identity)`, which removes one level of nesting from any `Chain`. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.unnest([1, [2], [[3]]]); //=> [1, 2, [3]] 11 | R.unnest([ 12 | [1, 2], 13 | [3, 4], 14 | [5, 6], 15 | ]); //=> [1, 2, 3, 4, 5, 6] 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/until.md: -------------------------------------------------------------------------------- 1 | ### until 2 | 3 | > `(a → Boolean) → (a → a) → a → a` 4 | 5 | Takes a predicate, a transformation function, and an initial value, and returns a value of the same type as the initial value. It does so by applying the transformation until the predicate is satisfied, at which point it returns the satisfactory value. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.until(R.gt(R.__, 100), R.multiply(2))(1); // => 128 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/update.md: -------------------------------------------------------------------------------- 1 | ### update 2 | 3 | > `Number → a → [a] → [a]` 4 | 5 | Returns a new copy of the array with the element at the provided index replaced with the given value. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.update(1, '_', ['a', 'b', 'c']); //=> ['a', '_', 'c'] 11 | R.update(-1, '_', ['a', 'b', 'c']); //=> ['a', 'b', '_'] 12 | ``` 13 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/useWith.md: -------------------------------------------------------------------------------- 1 | ### useWith 2 | 3 | > `((x1, x2, …) → z) → [(a → x1), (b → x2), …] → (a → b → … → z)` 4 | 5 | Accepts a function `fn` and a list of transformer functions and returns a new curried function. When the new function is invoked, it calls the function `fn` with parameters consisting of the result of calling each supplied handler on successive arguments to the new function. 6 | 7 | If more arguments are passed to the returned function than transformer functions, those arguments are passed directly to `fn` as additional parameters. If you expect additional arguments that don't need to be transformed, although you can ignore them, it's best to pass an identity function so that the new function reports the correct arity. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.useWith(Math.pow, [R.identity, R.identity])(3, 4); //=> 81 13 | R.useWith(Math.pow, [R.identity, R.identity])(3)(4); //=> 81 14 | R.useWith(Math.pow, [R.dec, R.inc])(3, 4); //=> 32 15 | R.useWith(Math.pow, [R.dec, R.inc])(3)(4); //=> 32 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/values.md: -------------------------------------------------------------------------------- 1 | ### values 2 | 3 | > `{k: v} → [v]` 4 | 5 | Returns a list of all the enumerable own properties of the supplied object. Note that the order of the output array is not guaranteed across different JS platforms. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.values({ a: 1, b: 2, c: 3 }); //=> [1, 2, 3] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/valuesIn.md: -------------------------------------------------------------------------------- 1 | ### valuesIn 2 | 3 | > `{k: v} → [v]` 4 | 5 | Returns a list of all the properties, including prototype properties, of the supplied object. Note that the order of the output array is not guaranteed to be consistent across different JS platforms. 6 | 7 | `Example` 8 | 9 | ```js 10 | const F = function () { 11 | this.x = 'X'; 12 | }; 13 | 14 | F.prototype.y = 'Y'; 15 | 16 | const f = new F(); 17 | 18 | R.valuesIn(f); //=> ['X', 'Y'] 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/view.md: -------------------------------------------------------------------------------- 1 | ### view 2 | 3 | > `Lens s a → s → a` > `Lens s a = Functor f => (a → f a) → s → f s` 4 | 5 | Returns a "view" of the given data structure, determined by the given lens. The lens's focus determines which portion of the data structure is visible. 6 | 7 | `Example` 8 | 9 | ```js 10 | const xLens = R.lensProp('x'); 11 | 12 | R.view(xLens, { x: 1, y: 2 }); //=> 1 13 | R.view(xLens, { x: 4, y: 2 }); //=> 4 14 | ``` 15 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/when.md: -------------------------------------------------------------------------------- 1 | ### when 2 | 3 | > `(a → Boolean) → (a → a) → a → a` 4 | 5 | Tests the final argument by passing it to the given predicate function. If the predicate is satisfied, the function will return the result of calling the `whenTrueFn` function with the same argument. If the predicate is not satisfied, the argument is returned as is. 6 | 7 | `Example` 8 | 9 | ```js 10 | // truncate :: String -> String 11 | const truncate = R.when( 12 | R.propSatisfies(R.gt(R.__, 10), 'length'), 13 | R.pipe(R.take(10), R.append('…'), R.join('')) 14 | ); 15 | 16 | truncate('12345'); //=> '12345' 17 | truncate('0123456789ABC'); //=> '0123456789…' 18 | ``` 19 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/whereEq.md: -------------------------------------------------------------------------------- 1 | ### whereEq 2 | 3 | > `{String: *} → {String: *} → Boolean` 4 | 5 | Takes a spec object and a test object; returns `true` if the test satisfies the spec, `false` otherwise. An object satisfies the spec if, for each of the spec's own properties, accessing that property of the object gives the same value (in `R.equals` terms) as accessing that property of the spec. 6 | 7 | `whereEq` is a specialization of where. 8 | 9 | `Example` 10 | 11 | ```js 12 | // pred :: Object -> Boolean 13 | const pred = R.whereEq({ a: 1, b: 2 }); 14 | 15 | pred({ a: 1 }); //=> false 16 | pred({ a: 1, b: 2 }); //=> true 17 | pred({ a: 1, b: 2, c: 3 }); //=> true 18 | pred({ a: 1, b: 1 }); //=> false 19 | ``` 20 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/without.md: -------------------------------------------------------------------------------- 1 | ### without 2 | 3 | > `[a] → [a] → [a]` 4 | 5 | Returns a new list without values in the first argument. `R.equals` is used to determine equality. 6 | 7 | Acts as a transducer if a transformer is given in list position. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.without([1, 2], [1, 2, 1, 3, 4]); //=> [3, 4] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/xprod.md: -------------------------------------------------------------------------------- 1 | ### xprod 2 | 3 | > `[a] → [b] → [[a,b]]` 4 | 5 | Creates a new list out of the two supplied by creating each possible pair from the lists. 6 | 7 | `Example` 8 | 9 | ```js 10 | R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] 11 | ``` 12 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/zip.md: -------------------------------------------------------------------------------- 1 | ### zip 2 | 3 | > `[a] → [b] → [[a,b]]` 4 | 5 | Creates a new list out of the two supplied by pairing up equally-positioned items from both lists. The returned list is truncated to the length of the shorter of the two input lists. 6 | 7 | Note: `zip` is equivalent to `zipWith(function(a, b) { return [a, b] })`. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']] 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/zipObj.md: -------------------------------------------------------------------------------- 1 | ### zipObj 2 | 3 | > `[String] → [*] → {String: *}` 4 | 5 | Creates a new object out of a list of keys and a list of values. `Key/value` pairing is truncated to the length of the shorter of the two lists. 6 | 7 | Note: `zipObj` is equivalent to `pipe(zip, fromPairs)`. 8 | 9 | `Example` 10 | 11 | ```js 12 | R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3} 13 | ``` 14 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/ramda/zipWith.md: -------------------------------------------------------------------------------- 1 | ### zipWith 2 | 3 | > `((a, b) → c) → [a] → [b] → [c]` 4 | 5 | Creates a new list out of the two supplied by applying the function to each equally-positioned pair in the lists. The returned list is truncated to the length of the shorter of the two input lists. 6 | 7 | `Example` 8 | 9 | ```js 10 | const f = (x, y) => { 11 | // ... 12 | }; 13 | 14 | R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']); 15 | //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')] 16 | ``` 17 | -------------------------------------------------------------------------------- /src/assets/snippet_sources/react: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-code/content/snippets/react/s -------------------------------------------------------------------------------- /src/assets/snippet_sources/ruby: -------------------------------------------------------------------------------- 1 | ../../../submodules/30-seconds-of-ruby/snippets -------------------------------------------------------------------------------- /src/components/Button/Button.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | cursor: pointer; 3 | overflow: hidden; 4 | outline: none; 5 | border-radius: 4px; 6 | border: 2px solid var(--secondary_translucent); 7 | background: transparent; 8 | color: var(--secondary); 9 | font-size: 14px; 10 | display: flex; 11 | justify-content: center; 12 | align-items: center; 13 | height: 32px; 14 | width: 100%; 15 | text-transform: uppercase; 16 | font-weight: 500; 17 | text-decoration: none; 18 | font-family: inherit; 19 | 20 | .icon { 21 | fill: var(--secondary); 22 | margin-right: 4px; 23 | 24 | &.iconAfter { 25 | margin-right: 0; 26 | margin-left: 4px; 27 | } 28 | } 29 | 30 | &.disabled { 31 | cursor: default; 32 | opacity: 0.7; 33 | } 34 | 35 | @media (hover: hover) { 36 | &:hover, 37 | &:active { 38 | border-color: var(--secondary); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/components/Button/index.js: -------------------------------------------------------------------------------- 1 | import Button from './Button'; 2 | 3 | export default Button; 4 | -------------------------------------------------------------------------------- /src/components/CheckBox/CheckBoxIcon.js: -------------------------------------------------------------------------------- 1 | import PropTypes from 'prop-types'; 2 | import React from 'react'; 3 | 4 | const RadioIcon = ({ checked, className }) => ( 5 | 21 | ); 22 | 23 | RadioIcon.propTypes = { 24 | className: PropTypes.string, 25 | checked: PropTypes.bool, 26 | }; 27 | 28 | export default RadioIcon; 29 | -------------------------------------------------------------------------------- /src/components/CheckBox/index.js: -------------------------------------------------------------------------------- 1 | import CheckBox from './CheckBox'; 2 | 3 | export default CheckBox; 4 | -------------------------------------------------------------------------------- /src/components/CheckBoxGroup/CheckBoxGroup.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | display: flex; 3 | flex-direction: column; 4 | margin-bottom: 16px; 5 | 6 | .wrap { 7 | .cbContainer { 8 | display: flex; 9 | align-items: center; 10 | margin-bottom: 8px; 11 | cursor: pointer; 12 | 13 | .cbLabel { 14 | margin-left: 4px; 15 | } 16 | } 17 | 18 | &.horizontal { 19 | flex-direction: row; 20 | 21 | .cbContainer { 22 | margin-right: 24px; 23 | 24 | .checkbox { 25 | &:last-of-type { 26 | margin-bottom: 0px; 27 | } 28 | } 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/components/CheckBoxGroup/index.js: -------------------------------------------------------------------------------- 1 | import CheckBoxGroup from './CheckBoxGroup'; 2 | 3 | export default CheckBoxGroup; 4 | -------------------------------------------------------------------------------- /src/components/CodePenPreviewButton/CodePenPreviewButton.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | .action { 3 | height: 24px; 4 | border: none; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/components/CodePenPreviewButton/index.js: -------------------------------------------------------------------------------- 1 | import CodePenPreviewButton from './CodePenPreviewButton'; 2 | 3 | export default CodePenPreviewButton; 4 | -------------------------------------------------------------------------------- /src/components/Footer/Footer.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | width: 100%; 3 | height: 96px; 4 | font-size: 12px; 5 | display: flex; 6 | align-items: center; 7 | border-top: 1px dotted var(--secondary_translucent); 8 | 9 | .link { 10 | font-weight: 900; 11 | cursor: pointer; 12 | padding-bottom: 2px; 13 | } 14 | 15 | .links { 16 | margin-left: auto; 17 | 18 | .link { 19 | margin-right: 24px; 20 | 21 | &:last-child { 22 | margin-right: 0; 23 | } 24 | 25 | &:hover, 26 | &:active { 27 | border-bottom: 1px dotted; 28 | text-decoration: none; 29 | } 30 | } 31 | } 32 | 33 | .creds { 34 | display: flex; 35 | flex-direction: column; 36 | 37 | & > span { 38 | margin-bottom: 4px; 39 | 40 | &:last-child { 41 | margin-bottom: 0; 42 | } 43 | } 44 | 45 | .link { 46 | text-decoration: underline dotted; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/components/Footer/index.js: -------------------------------------------------------------------------------- 1 | import Footer from './Footer'; 2 | 3 | export default Footer; 4 | -------------------------------------------------------------------------------- /src/components/Header/Header.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | width: 100%; 3 | height: 96px; 4 | font-size: 12px; 5 | display: flex; 6 | align-items: center; 7 | position: relative; 8 | 9 | .logo { 10 | width: auto; 11 | height: 32px; 12 | } 13 | 14 | .links { 15 | margin-left: auto; 16 | 17 | .link { 18 | padding-bottom: 2px; 19 | font-weight: 900; 20 | cursor: pointer; 21 | margin-right: 24px; 22 | 23 | &:last-child { 24 | margin-right: 0; 25 | } 26 | 27 | &:hover, 28 | &:active, 29 | &.active { 30 | border-bottom: 1px dotted; 31 | text-decoration: none; 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/components/Header/index.js: -------------------------------------------------------------------------------- 1 | import Header from './Header'; 2 | 3 | export default Header; 4 | -------------------------------------------------------------------------------- /src/components/IconButton/IconButton.module.scss: -------------------------------------------------------------------------------- 1 | .button { 2 | cursor: pointer; 3 | position: relative; 4 | display: inline-flex; 5 | align-items: center; 6 | justify-content: center; 7 | padding: 0; 8 | background: transparent; 9 | border: 0; 10 | 11 | &.disabled { 12 | cursor: default; 13 | opacity: 0.7; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/components/IconButton/index.js: -------------------------------------------------------------------------------- 1 | import IconButton from './IconButton'; 2 | 3 | export default IconButton; 4 | -------------------------------------------------------------------------------- /src/components/Input/Input.js: -------------------------------------------------------------------------------- 1 | import PropTypes from 'prop-types'; 2 | import React from 'react'; 3 | import cx from 'classnames'; 4 | 5 | import styles from './Input.module.scss'; 6 | 7 | const Input = React.forwardRef( 8 | ({ className, id, disabled, onChange, value, ...props }, ref) => { 9 | const handleChange = (e) => { 10 | onChange(e.target.value); 11 | }; 12 | 13 | return ( 14 | 28 | ); 29 | } 30 | ); 31 | 32 | Input.propTypes = { 33 | className: PropTypes.string, 34 | id: PropTypes.string, 35 | disabled: PropTypes.bool, 36 | value: PropTypes.string, 37 | onChange: PropTypes.func, 38 | }; 39 | 40 | export default Input; 41 | -------------------------------------------------------------------------------- /src/components/Input/Input.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | position: relative; 3 | cursor: pointer; 4 | display: flex; 5 | align-items: center; 6 | height: 48px; 7 | 8 | input { 9 | background-color: transparent; 10 | border: none; 11 | outline: none; 12 | color: var(--secondary); 13 | cursor: pointer; 14 | z-index: 1; 15 | width: 100%; 16 | height: 100%; 17 | padding: 8px 16px; 18 | font-size: 32px; 19 | font-weight: 500; 20 | } 21 | 22 | &.disabled { 23 | opacity: 0.7; 24 | 25 | input { 26 | color: var(--secondary_translucent); 27 | cursor: default; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/components/Input/index.js: -------------------------------------------------------------------------------- 1 | import Input from './Input'; 2 | 3 | export default Input; 4 | -------------------------------------------------------------------------------- /src/components/Label/Label.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import cx from 'classnames'; 4 | import styles from './Label.module.scss'; 5 | 6 | const Label = ({ className, children, htmlFor, subLabel, ...props }) => ( 7 | 8 | 11 | {subLabel && {subLabel}} 12 | 13 | ); 14 | 15 | Label.propTypes = { 16 | className: PropTypes.string, 17 | htmlFor: PropTypes.string.isRequired, 18 | children: PropTypes.node, 19 | subLabel: PropTypes.string, 20 | }; 21 | 22 | export default Label; 23 | -------------------------------------------------------------------------------- /src/components/Label/Label.module.scss: -------------------------------------------------------------------------------- 1 | .label { 2 | display: block; 3 | color: var(--secondary); 4 | font-size: 16px; 5 | font-weight: 900; 6 | margin-bottom: 8px; 7 | } 8 | 9 | .subLabel { 10 | margin-bottom: 8px; 11 | font-size: 12px; 12 | color: var(--secondary_translucent); 13 | } 14 | -------------------------------------------------------------------------------- /src/components/Label/index.js: -------------------------------------------------------------------------------- 1 | import Label from './Label'; 2 | 3 | export default Label; 4 | -------------------------------------------------------------------------------- /src/components/LanguageList/index.js: -------------------------------------------------------------------------------- 1 | import LanguageList from './LanguageList'; 2 | 3 | export default LanguageList; 4 | -------------------------------------------------------------------------------- /src/components/LanguageTitle/LanguageTitle.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | display: flex; 3 | margin-bottom: 8px; 4 | 5 | .icon { 6 | width: 32px; 7 | height: 32px; 8 | border-radius: 4px; 9 | display: flex; 10 | justify-content: center; 11 | align-items: center; 12 | margin-right: 16px; 13 | background: var(--secondary); 14 | 15 | svg { 16 | width: 24px; 17 | height: 24px; 18 | fill: var(--primary); 19 | color: var(--primary); 20 | } 21 | } 22 | 23 | .data { 24 | display: flex; 25 | flex-direction: column; 26 | justify-content: space-between; 27 | 28 | .title { 29 | display: flex; 30 | 31 | h2 { 32 | margin: 0; 33 | font-size: 36px; 34 | line-height: 36px; 35 | margin-right: 16px; 36 | } 37 | } 38 | 39 | span { 40 | font-size: 12px; 41 | line-height: 12px; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/components/LanguageTitle/index.js: -------------------------------------------------------------------------------- 1 | import LanguageTitle from './LanguageTitle'; 2 | 3 | export default LanguageTitle; 4 | -------------------------------------------------------------------------------- /src/components/Loader/Loader.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import cx from 'classnames'; 4 | 5 | import Animation from './Animation'; 6 | 7 | import styles from './Loader.module.scss'; 8 | 9 | const Loader = ({ className }) => ( 10 |
11 | 12 |
13 | ); 14 | 15 | Loader.propTypes = { 16 | className: PropTypes.string, 17 | }; 18 | 19 | export default Loader; 20 | -------------------------------------------------------------------------------- /src/components/Loader/Loader.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | position: fixed; 3 | top: 0; 4 | left: 0; 5 | right: 0; 6 | bottom: 0; 7 | display: flex; 8 | justify-content: center; 9 | align-items: center; 10 | z-index: 9999; 11 | 12 | .pulse { 13 | & > * { 14 | fill: var(--secondary); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/components/Loader/index.js: -------------------------------------------------------------------------------- 1 | import Loader from './Loader'; 2 | 3 | export default Loader; 4 | -------------------------------------------------------------------------------- /src/components/Logo/Logo.module.scss: -------------------------------------------------------------------------------- 1 | .logo { 2 | & > * { 3 | fill: var(--logo_color); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/components/Logo/index.js: -------------------------------------------------------------------------------- 1 | import Logo from './Logo'; 2 | 3 | export default Logo; 4 | -------------------------------------------------------------------------------- /src/components/MarkdownRenderer/MarkdownRenderer.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | width: 100%; 3 | font-size: 14px; 4 | 5 | > pre { 6 | font-size: 12px; 7 | 8 | &:first-child { 9 | margin-top: 32px; 10 | } 11 | 12 | &:last-child { 13 | margin-top: 0; 14 | } 15 | } 16 | 17 | ul { 18 | li { 19 | margin-bottom: 4px; 20 | } 21 | } 22 | 23 | a { 24 | padding-bottom: 2px; 25 | border-bottom: 1px dotted var(--secondary); 26 | } 27 | 28 | > * { 29 | margin: 0 0 16px 0; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/components/MarkdownRenderer/index.js: -------------------------------------------------------------------------------- 1 | import MarkdownRenderer from './MarkdownRenderer'; 2 | 3 | export default MarkdownRenderer; 4 | -------------------------------------------------------------------------------- /src/components/MarkdownSnippetPreview/index.js: -------------------------------------------------------------------------------- 1 | import MarkdownSnippetPreview from './MarkdownSnippetPreview'; 2 | 3 | export default MarkdownSnippetPreview; 4 | -------------------------------------------------------------------------------- /src/components/MarkdownSyntaxHighlighter/MarkdownSyntaxHighlighter.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | position: relative; 3 | 4 | .codeWrapper { 5 | border-radius: 4px; 6 | padding: 16px 12px !important; 7 | // This will be a fallback in case highlighter doesn't have it's own bg color 8 | background-color: var(--fallback_code_bg); 9 | } 10 | 11 | .copy { 12 | cursor: pointer; 13 | position: absolute; 14 | top: 8px; 15 | right: 8px; 16 | font-weight: 700; 17 | mix-blend-mode: difference; 18 | filter: invert(1); 19 | opacity: 0.7; 20 | 21 | &:hover, 22 | &:active { 23 | opacity: 1; 24 | } 25 | } 26 | } 27 | 28 | .inline { 29 | background: var(--accent); 30 | color: var(--accent_text); 31 | border-radius: 2px; 32 | padding: 0 2px; 33 | } 34 | -------------------------------------------------------------------------------- /src/components/MarkdownSyntaxHighlighter/index.js: -------------------------------------------------------------------------------- 1 | import MarkdownSyntaxHighlighter from './MarkdownSyntaxHighlighter'; 2 | 3 | export default MarkdownSyntaxHighlighter; 4 | -------------------------------------------------------------------------------- /src/components/PageProvider/PageProvider.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | width: calc(100vw - 64px); 3 | max-width: 1280px; 4 | margin: 0 auto; 5 | 6 | &.isPopup { 7 | width: max-content; 8 | 9 | .content { 10 | min-height: unset; 11 | } 12 | } 13 | 14 | .content { 15 | padding: 32px 0; 16 | min-height: calc(100vh - 192px); 17 | max-width: 1024px; 18 | margin: 0 auto; 19 | 20 | &.onlyContent { 21 | padding: 0; 22 | min-height: 100vh; 23 | } 24 | 25 | &.twoSections { 26 | min-height: calc(100vh - 96px); 27 | } 28 | } 29 | } 30 | 31 | .tooltip { 32 | background: var(--accent) !important; 33 | padding: 8px !important; 34 | color: var(--accent_text) !important; 35 | opacity: 1 !important; 36 | text-align: center; 37 | 38 | &::after, 39 | &::before { 40 | border-top-color: var(--accent) !important; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/components/PageProvider/index.js: -------------------------------------------------------------------------------- 1 | import PageProvider from './PageProvider'; 2 | 3 | export default PageProvider; 4 | -------------------------------------------------------------------------------- /src/components/PlainToast/PlainToast.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import cx from 'classnames'; 4 | 5 | import IconButton from '../IconButton'; 6 | 7 | import Close from '../../icons/Close'; 8 | 9 | import styles from './PlainToast.module.scss'; 10 | 11 | const PlainToast = ({ className, message, onClose }) => { 12 | return ( 13 |
14 |
{message}
15 | {onClose && ( 16 | 17 | )} 18 |
19 | ); 20 | }; 21 | 22 | PlainToast.propTypes = { 23 | className: PropTypes.string, 24 | message: PropTypes.node, 25 | onClose: PropTypes.func, 26 | }; 27 | 28 | export default PlainToast; 29 | -------------------------------------------------------------------------------- /src/components/PlainToast/PlainToast.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | display: flex; 3 | align-items: center; 4 | justify-content: flex-start; 5 | overflow: hidden; 6 | border-radius: 4px; 7 | border-left-style: solid; 8 | border-left-width: 8px; 9 | border-left-color: var(--accent); 10 | box-sizing: border-box; 11 | font-size: 14px; 12 | font-weight: 500; 13 | background: var(--secondary); 14 | padding: 12px; 15 | color: var(--primary); 16 | width: 100%; 17 | 18 | .message { 19 | flex: 1; 20 | } 21 | 22 | .close { 23 | margin: 0 0 0 12px; 24 | 25 | & > svg { 26 | fill: var(--primary); 27 | width: 12px; 28 | height: 12px; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/components/PlainToast/index.js: -------------------------------------------------------------------------------- 1 | import PlainToast from './PlainToast'; 2 | 3 | export default PlainToast; 4 | -------------------------------------------------------------------------------- /src/components/RadioButton/index.js: -------------------------------------------------------------------------------- 1 | import RadioButton from './RadioButton'; 2 | 3 | export default RadioButton; 4 | -------------------------------------------------------------------------------- /src/components/RadioButtonGroup/RadioButtonGroup.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | .wrap { 3 | margin-bottom: 4px; 4 | display: flex; 5 | flex-wrap: wrap; 6 | flex-direction: column; 7 | 8 | &.horizontal { 9 | flex-direction: row; 10 | 11 | .radioContainer { 12 | margin-right: 24px; 13 | } 14 | } 15 | 16 | .radioContainer { 17 | display: flex; 18 | margin-bottom: 8px; 19 | cursor: pointer; 20 | align-items: center; 21 | 22 | &:hover, 23 | &:active { 24 | border-color: var(--secondary); 25 | .radio svg { 26 | fill: var(--secondary); 27 | } 28 | } 29 | } 30 | 31 | .radioLabel { 32 | color: var(--secondary); 33 | margin-left: 4px; 34 | font-size: 14px; 35 | } 36 | 37 | .disabled { 38 | opacity: 0.7; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/components/RadioButtonGroup/index.js: -------------------------------------------------------------------------------- 1 | import RadioButtonGroup from './RadioButtonGroup'; 2 | 3 | export default RadioButtonGroup; 4 | -------------------------------------------------------------------------------- /src/components/ScrollTopButton/ScrollTopButton.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | display: flex; 3 | position: fixed; 4 | right: 32px; 5 | bottom: 72px; 6 | border-radius: 100%; 7 | width: 48px; 8 | height: 48px; 9 | background: var(--accent); 10 | color: var(--accent_text); 11 | opacity: 1; 12 | transition: all 0.2s linear; 13 | 14 | &.hidden { 15 | visibility: hidden; 16 | opacity: 0; 17 | } 18 | 19 | svg { 20 | fill: var(--accent_text); 21 | width: 16px; 22 | height: 16px; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/components/ScrollTopButton/index.js: -------------------------------------------------------------------------------- 1 | import ScrollTopButton from './ScrollTopButton'; 2 | 3 | export default ScrollTopButton; 4 | -------------------------------------------------------------------------------- /src/components/SelectField/Icon.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Chevron = ({ className }) => ( 5 | 12 | 16 | 17 | ); 18 | 19 | Chevron.propTypes = { 20 | className: PropTypes.string, 21 | }; 22 | 23 | export default memo(Chevron); 24 | -------------------------------------------------------------------------------- /src/components/SelectField/SelectField.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | .wrap { 3 | position: relative; 4 | } 5 | .icon { 6 | position: absolute; 7 | right: 12px; 8 | top: 13px; 9 | fill: var(--primary); 10 | } 11 | } 12 | .select { 13 | box-sizing: border-box; 14 | width: 100%; 15 | height: 32px; 16 | color: var(--primary); 17 | background-color: var(--secondary); 18 | border-radius: 4px; 19 | padding: 4px 34px 4px 12px; 20 | font-size: 14px; 21 | appearance: none; 22 | outline: none; 23 | cursor: pointer; 24 | 25 | &:active, 26 | &:focus { 27 | outline: 0; 28 | } 29 | &.disabled { 30 | opacity: 0.7; 31 | background-color: var(--secondary); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/components/SelectField/index.js: -------------------------------------------------------------------------------- 1 | import SelectField from './SelectField'; 2 | 3 | export default SelectField; 4 | -------------------------------------------------------------------------------- /src/components/SettingsForm/index.js: -------------------------------------------------------------------------------- 1 | import SettingsForm from './SettingsForm'; 2 | 3 | export default SettingsForm; 4 | -------------------------------------------------------------------------------- /src/components/SettingsProvider/SettingsProvider.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | width: 100%; 3 | min-height: 100vh; 4 | background: var(--primary); 5 | color: var(--secondary); 6 | transition: background 0.1s linear; 7 | } 8 | -------------------------------------------------------------------------------- /src/components/SettingsProvider/index.js: -------------------------------------------------------------------------------- 1 | export { 2 | useGlobalSettings, 3 | useSetGlobalSettings, 4 | usePreviewTheme, 5 | SettingsProvider, 6 | } from './SettingsProvider'; 7 | -------------------------------------------------------------------------------- /src/components/SnippetTitle/index.js: -------------------------------------------------------------------------------- 1 | import SnippetTitle from './SnippetTitle'; 2 | 3 | export default SnippetTitle; 4 | -------------------------------------------------------------------------------- /src/components/Toast/Toast.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable react-hooks/exhaustive-deps */ 2 | import React, { useEffect } from 'react'; 3 | import PropTypes from 'prop-types'; 4 | 5 | import PlainToast from '../PlainToast'; 6 | 7 | import { useHideToast } from './ToastController'; 8 | 9 | const Toast = ({ className, id, message, timeout }) => { 10 | const hide = useHideToast(id); 11 | 12 | useEffect(() => { 13 | if (!timeout) { 14 | return null; 15 | } 16 | const timer = setTimeout(hide, timeout); 17 | return () => { 18 | clearTimeout(timer); 19 | }; 20 | }, []); 21 | 22 | return ; 23 | }; 24 | 25 | Toast.propTypes = { 26 | className: PropTypes.string, 27 | id: PropTypes.number, 28 | message: PropTypes.string, 29 | timeout: PropTypes.number, 30 | }; 31 | 32 | export default Toast; 33 | -------------------------------------------------------------------------------- /src/components/Toast/ToastList.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | import Toast from './Toast'; 5 | 6 | import styles from './ToastList.module.scss'; 7 | 8 | const ToastList = ({ toasts }) => ( 9 |
10 | {toasts.map(({ message, timeout, id }) => ( 11 | 18 | ))} 19 |
20 | ); 21 | 22 | ToastList.propTypes = { 23 | toasts: PropTypes.array, 24 | }; 25 | 26 | export default ToastList; 27 | -------------------------------------------------------------------------------- /src/components/Toast/ToastList.module.scss: -------------------------------------------------------------------------------- 1 | .list { 2 | position: fixed; 3 | bottom: 48px; 4 | left: 50%; 5 | transform: translateX(-50%); 6 | z-index: 99999; 7 | display: flex; 8 | align-items: center; 9 | justify-content: center; 10 | flex-direction: column; 11 | 12 | .toast { 13 | width: auto; 14 | 15 | &:not(:last-child) { 16 | margin: 0 0 16px 0; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/components/Toast/index.js: -------------------------------------------------------------------------------- 1 | export { 2 | useShowToast, 3 | useToast, 4 | useHideToast, 5 | ToastProvider, 6 | } from './ToastController'; 7 | -------------------------------------------------------------------------------- /src/icons/Chevron.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const ROTATION = { 5 | top: 0, 6 | right: 90, 7 | bottom: 180, 8 | left: 270, 9 | }; 10 | 11 | const Chevron = (props) => ( 12 | 18 | 19 | 20 | ); 21 | 22 | Chevron.defaultProps = { 23 | width: 24, 24 | height: 24, 25 | color: 'currentColor', 26 | direction: 'top', 27 | }; 28 | 29 | Chevron.propTypes = { 30 | width: PropTypes.number, 31 | height: PropTypes.number, 32 | color: PropTypes.string, 33 | direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left']), 34 | }; 35 | 36 | export default memo(Chevron); 37 | -------------------------------------------------------------------------------- /src/icons/Close.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Close = (props) => ( 5 | 6 | 7 | 8 | ); 9 | 10 | Close.defaultProps = { 11 | width: 14, 12 | height: 14, 13 | color: '#000', 14 | }; 15 | 16 | Close.propTypes = { 17 | width: PropTypes.number, 18 | height: PropTypes.number, 19 | color: PropTypes.string, 20 | }; 21 | 22 | export default memo(Close); 23 | -------------------------------------------------------------------------------- /src/icons/Copy.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Copy = (props) => ( 5 | 6 | 18 | 26 | 27 | ); 28 | 29 | Copy.defaultProps = { 30 | width: 24, 31 | height: 24, 32 | color: 'currentColor', 33 | }; 34 | 35 | Copy.propTypes = { 36 | width: PropTypes.number, 37 | height: PropTypes.number, 38 | color: PropTypes.string, 39 | }; 40 | 41 | export default memo(Copy); 42 | -------------------------------------------------------------------------------- /src/icons/Cpp.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Cpp = (props) => ( 5 | 6 | 7 | 8 | ); 9 | 10 | Cpp.defaultProps = { 11 | width: 128, 12 | height: 128, 13 | color: '#9C033A', 14 | }; 15 | 16 | Cpp.propTypes = { 17 | width: PropTypes.number, 18 | height: PropTypes.number, 19 | color: PropTypes.string, 20 | }; 21 | 22 | export default memo(Cpp); 23 | -------------------------------------------------------------------------------- /src/icons/Csharp.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Csharp = (props) => ( 5 | 6 | 7 | 8 | ); 9 | 10 | Csharp.defaultProps = { 11 | width: 128, 12 | height: 128, 13 | color: '#68217A', 14 | }; 15 | 16 | Csharp.propTypes = { 17 | width: PropTypes.number, 18 | height: PropTypes.number, 19 | color: PropTypes.string, 20 | }; 21 | 22 | export default memo(Csharp); 23 | -------------------------------------------------------------------------------- /src/icons/Css.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Css = (props) => ( 5 | 6 | 7 | 8 | ); 9 | 10 | Css.defaultProps = { 11 | width: 128, 12 | height: 128, 13 | color: '#1572B6', 14 | }; 15 | 16 | Css.propTypes = { 17 | width: PropTypes.number, 18 | height: PropTypes.number, 19 | color: PropTypes.string, 20 | }; 21 | 22 | export default memo(Css); 23 | -------------------------------------------------------------------------------- /src/icons/Dart.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Dart = (props) => ( 5 | 6 | 7 | 8 | 9 | 10 | 11 | ); 12 | 13 | Dart.defaultProps = { 14 | width: 128, 15 | height: 128, 16 | color: '#00A8E1', 17 | }; 18 | 19 | Dart.propTypes = { 20 | width: PropTypes.number, 21 | height: PropTypes.number, 22 | color: PropTypes.string, 23 | }; 24 | 25 | export default memo(Dart); 26 | -------------------------------------------------------------------------------- /src/icons/Git.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Git = (props) => ( 5 | 6 | 7 | 8 | ); 9 | 10 | Git.defaultProps = { 11 | width: 128, 12 | height: 128, 13 | color: '#F34F29', 14 | }; 15 | 16 | Git.propTypes = { 17 | width: PropTypes.number, 18 | height: PropTypes.number, 19 | color: PropTypes.string, 20 | }; 21 | 22 | export default memo(Git); 23 | -------------------------------------------------------------------------------- /src/icons/Html.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const ReactIcon = (props) => ( 5 | 6 | 7 | 8 | ); 9 | 10 | ReactIcon.defaultProps = { 11 | width: 100, 12 | height: 100, 13 | color: '#FF6D00', 14 | }; 15 | 16 | ReactIcon.propTypes = { 17 | width: PropTypes.number, 18 | height: PropTypes.number, 19 | color: PropTypes.string, 20 | }; 21 | 22 | export default memo(ReactIcon); 23 | -------------------------------------------------------------------------------- /src/icons/Info.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Info = (props) => ( 5 | 6 | 7 | 8 | ); 9 | 10 | Info.defaultProps = { 11 | width: 24, 12 | height: 24, 13 | color: 'currentColor', 14 | }; 15 | 16 | Info.propTypes = { 17 | width: PropTypes.number, 18 | height: PropTypes.number, 19 | color: PropTypes.string, 20 | }; 21 | 22 | export default memo(Info); 23 | -------------------------------------------------------------------------------- /src/icons/Save.js: -------------------------------------------------------------------------------- 1 | import React, { memo } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Copy = (props) => ( 5 | 6 | 14 | 15 | ); 16 | 17 | Copy.defaultProps = { 18 | width: 24, 19 | height: 24, 20 | color: 'currentColor', 21 | }; 22 | 23 | Copy.propTypes = { 24 | width: PropTypes.number, 25 | height: PropTypes.number, 26 | color: PropTypes.string, 27 | }; 28 | 29 | export default memo(Copy); 30 | -------------------------------------------------------------------------------- /src/pages/AllSnippetsTab/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 30 Seconds of Knowledge - All Snippets 12 | 13 | 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /src/pages/AllSnippetsTab/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from 'react-dom'; 3 | 4 | import AllSnippetsTab from './AllSnippetsTab'; 5 | import PageProvider from '../../components/PageProvider/PageProvider'; 6 | 7 | import Analytics from '../../api/google-analytics'; 8 | 9 | import '../index.scss'; 10 | 11 | window.addEventListener('load', () => { 12 | Analytics.firePageViewEvent('All Snippets'); 13 | }); 14 | 15 | render( 16 | 17 | 18 | , 19 | window.document.querySelector('#all-snippets-container') 20 | ); 21 | 22 | if (module.hot) module.hot.accept(); 23 | -------------------------------------------------------------------------------- /src/pages/Favourites/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 30 Seconds of Knowledge - Favourites 12 | 13 | 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /src/pages/Favourites/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from 'react-dom'; 3 | 4 | import Favourites from './Favourites'; 5 | import PageProvider from '../../components/PageProvider/PageProvider'; 6 | 7 | import Analytics from '../../api/google-analytics'; 8 | 9 | import '../index.scss'; 10 | 11 | window.addEventListener('load', () => { 12 | Analytics.firePageViewEvent('Favorites'); 13 | }); 14 | 15 | render( 16 | 17 | 18 | , 19 | window.document.querySelector('#favourites-container') 20 | ); 21 | 22 | if (module.hot) module.hot.accept(); 23 | -------------------------------------------------------------------------------- /src/pages/NewTab/Newtab.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | display: flex; 3 | width: 100%; 4 | height: 100%; 5 | flex-direction: column; 6 | justify-content: flex-start; 7 | 8 | .content { 9 | width: 100%; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/pages/NewTab/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 30 Seconds of Knowledge 12 | 13 | 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /src/pages/NewTab/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from 'react-dom'; 3 | 4 | import Newtab from './Newtab'; 5 | import PageProvider from '../../components/PageProvider/PageProvider'; 6 | 7 | import Analytics from '../../api/google-analytics'; 8 | 9 | import '../index.scss'; 10 | 11 | window.addEventListener('load', () => { 12 | Analytics.firePageViewEvent('Random Snippet'); 13 | }); 14 | 15 | render( 16 | 17 | 18 | , 19 | window.document.querySelector('#app-container') 20 | ); 21 | 22 | if (module.hot) module.hot.accept(); 23 | -------------------------------------------------------------------------------- /src/pages/Popup/Popup.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | display: flex; 3 | width: 100%; 4 | min-width: 256px; 5 | height: 100%; 6 | flex-direction: column; 7 | justify-content: flex-start; 8 | padding: 16px; 9 | 10 | .heading { 11 | border-bottom: 1px dotted var(--secondary_translucent); 12 | padding-bottom: 8px; 13 | margin-bottom: 8px; 14 | display: flex; 15 | align-items: center; 16 | justify-content: space-between; 17 | 18 | .header { 19 | margin: 0; 20 | font-size: 32px; 21 | } 22 | 23 | .open { 24 | border: none; 25 | width: unset; 26 | } 27 | } 28 | 29 | .content { 30 | width: 100%; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/pages/Popup/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 30 Seconds of Knowledge - Popup 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/pages/Popup/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from 'react-dom'; 3 | 4 | import Popup from './Popup'; 5 | import PageProvider from '../../components/PageProvider/PageProvider'; 6 | 7 | import Analytics from '../../api/google-analytics'; 8 | 9 | import '../index.scss'; 10 | 11 | window.addEventListener('load', () => { 12 | Analytics.firePageViewEvent('Popup'); 13 | }); 14 | 15 | render( 16 | 17 | 18 | , 19 | window.document.querySelector('#popup-container') 20 | ); 21 | 22 | if (module.hot) module.hot.accept(); 23 | -------------------------------------------------------------------------------- /src/pages/Settings/Settings.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import cx from 'classnames'; 4 | import isEmpty from 'lodash.isempty'; 5 | 6 | import Loader from '../../components/Loader'; 7 | import SettingsForm from '../../components/SettingsForm'; 8 | import { useGlobalSettings } from '../../components/SettingsProvider'; 9 | 10 | import styles from './Settings.module.scss'; 11 | 12 | const Settings = ({ className }) => { 13 | const settings = useGlobalSettings(); 14 | 15 | if (isEmpty(settings)) { 16 | return ( 17 |
18 | 19 |
20 | ); 21 | } 22 | 23 | return ( 24 |
25 | 26 |
27 | ); 28 | }; 29 | 30 | Settings.propTypes = { 31 | className: PropTypes.string, 32 | }; 33 | 34 | export default Settings; 35 | -------------------------------------------------------------------------------- /src/pages/Settings/Settings.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | display: flex; 3 | width: 100%; 4 | height: 100%; 5 | flex-direction: column; 6 | justify-content: flex-start; 7 | 8 | .content { 9 | width: 100%; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/pages/Settings/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 30 Seconds of Knowledge - Settings 12 | 13 | 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /src/pages/Settings/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from 'react-dom'; 3 | 4 | import Settings from './Settings'; 5 | import PageProvider from '../../components/PageProvider/PageProvider'; 6 | 7 | import Analytics from '../../api/google-analytics'; 8 | 9 | import '../index.scss'; 10 | 11 | window.addEventListener('load', () => { 12 | Analytics.firePageViewEvent('Settings'); 13 | }); 14 | 15 | render( 16 | 17 | 18 | , 19 | window.document.querySelector('#settings-container') 20 | ); 21 | 22 | if (module.hot) module.hot.accept(); 23 | -------------------------------------------------------------------------------- /src/pages/ViewTab/ViewTab.module.scss: -------------------------------------------------------------------------------- 1 | .container { 2 | display: flex; 3 | width: 100%; 4 | height: 100%; 5 | flex-direction: column; 6 | justify-content: flex-start; 7 | 8 | .content { 9 | width: 100%; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/pages/ViewTab/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 30 Seconds of Knowledge - View Snippet 12 | 13 | 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /src/pages/ViewTab/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from 'react-dom'; 3 | 4 | import ViewTab from './ViewTab'; 5 | import PageProvider from '../../components/PageProvider/PageProvider'; 6 | 7 | import Analytics from '../../api/google-analytics'; 8 | 9 | import '../index.scss'; 10 | 11 | window.addEventListener('load', () => { 12 | Analytics.firePageViewEvent('Specific Snippet'); 13 | }); 14 | 15 | render( 16 | 17 | 18 | , 19 | window.document.querySelector('#view-tab-container') 20 | ); 21 | 22 | if (module.hot) module.hot.accept(); 23 | -------------------------------------------------------------------------------- /src/pages/index.scss: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;500;700&family=Roboto:wght@400;500;900&display=swap'); 2 | 3 | * { 4 | box-sizing: border-box; 5 | } 6 | 7 | body { 8 | margin: 0; 9 | min-height: 100vh; 10 | padding: 0; 11 | font-family: 'Roboto', sans-serif; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | background: var(--primary); 15 | font-weight: 400; 16 | font-size: 12px; 17 | color: var(--secondary); 18 | } 19 | 20 | code, 21 | pre { 22 | font-family: 'Roboto Mono', monospace; 23 | } 24 | 25 | input { 26 | font-family: 'Roboto', sans-serif; 27 | } 28 | 29 | a { 30 | text-decoration: none; 31 | color: var(--secondary); 32 | } 33 | 34 | summary { 35 | &::-webkit-details-marker { 36 | display: none; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/themes/_dark.scss: -------------------------------------------------------------------------------- 1 | /* Dark Theme */ 2 | 3 | .dark { 4 | --primary: #0e1217; 5 | --primary_highlight: #26282d; 6 | --primary_translucent: #0e121780; 7 | --secondary: #f1ede8; 8 | --secondary_highlight: #d9d7d2; 9 | --secondary_translucent: #f1ede880; 10 | --accent: #ffc800; 11 | --accent_text: var(--primary); 12 | --fallback_code_bg: #282a36; 13 | --logo_color: var(--accent); 14 | } 15 | -------------------------------------------------------------------------------- /src/themes/_gruvbox_light.scss: -------------------------------------------------------------------------------- 1 | /* Gruvbox Light Theme */ 2 | 3 | .gruvbox_light { 4 | --primary: #f2e5bc; 5 | --primary_highlight: #d5c4a1; 6 | --primary_translucent: #f2e5bc80; 7 | --secondary: #4e4942; 8 | --secondary_highlight: #837d6c; 9 | --secondary_translucent: #4e494280; 10 | --accent: #837d6c; 11 | --accent_text: #ebdbb2; 12 | --fallback_code_bg: #fbf1c7; 13 | --logo_color: var(--secondary); 14 | } 15 | -------------------------------------------------------------------------------- /src/themes/_hackpot.scss: -------------------------------------------------------------------------------- 1 | /* Hackpot (Under The Sea) Theme */ 2 | 3 | .hackpot { 4 | --primary: #013030; 5 | --primary_highlight: #003838; 6 | --primary_translucent: #01303080; 7 | --secondary: #b1e7b1; 8 | --secondary_highlight: #40715e; 9 | --secondary_translucent: #b1e7b180; 10 | --accent: #32cd32; 11 | --accent_text: #003838; 12 | --fallback_code_bg: #147433; 13 | --logo_color: var(--accent); 14 | } 15 | -------------------------------------------------------------------------------- /src/themes/_laser_wave.scss: -------------------------------------------------------------------------------- 1 | /* Laser Wave Theme */ 2 | 3 | .laser_wave { 4 | --primary: #27212e; 5 | --primary_highlight: #1f1b24; 6 | --primary_translucent: #27212e80; 7 | --secondary: #f7f7f7; 8 | --secondary_highlight: #6b676f; 9 | --secondary_translucent: #f7f7f780; 10 | --accent: #eb64b9; 11 | --accent_text: var(--primary); 12 | --fallback_code_bg: #2d2b55; 13 | --logo_color: var(--accent); 14 | } 15 | -------------------------------------------------------------------------------- /src/themes/_light.scss: -------------------------------------------------------------------------------- 1 | /* Light Theme 2 | * Names will be deceptive because the colors are inverted 3 | */ 4 | 5 | .light { 6 | --primary: #f1ede8; 7 | --primary_highlight: #d9d7d2; 8 | --primary_translucent: #f1ede880; 9 | --secondary: #0e1217; 10 | --secondary_highlight: #26282d; 11 | --secondary_translucent: #0e121780; 12 | --accent: #6926eb; 13 | --accent_text: var(--primary); 14 | --fallback_code_bg: #282a36; 15 | --logo_color: var(--accent); 16 | } 17 | -------------------------------------------------------------------------------- /src/themes/_shades_of_purple.scss: -------------------------------------------------------------------------------- 1 | /* Shades Of Purple Theme */ 2 | 3 | .shades_of_purple { 4 | --primary: #1e1e3f; 5 | --primary_highlight: #2d2b55; 6 | --primary_translucent: #1e1e3f80; 7 | --secondary: #f2f2f4; 8 | --secondary_highlight: #c9cad2; 9 | --secondary_translucent: #f2f2f480; 10 | --accent: #a1f98e; 11 | --accent_text: var(--primary); 12 | --fallback_code_bg: #2d2b55; 13 | --logo_color: var(--accent); 14 | } 15 | -------------------------------------------------------------------------------- /src/themes/index.module.scss: -------------------------------------------------------------------------------- 1 | @import 'light'; 2 | @import 'dark'; 3 | @import 'shades_of_purple'; 4 | @import 'laser_wave'; 5 | @import 'hackpot'; 6 | @import 'gruvbox_light'; 7 | -------------------------------------------------------------------------------- /utils/build.js: -------------------------------------------------------------------------------- 1 | // Do this as the first thing so that any code reading it knows the right env. 2 | process.env.BABEL_ENV = 'production'; 3 | process.env.NODE_ENV = 'production'; 4 | process.env.ASSET_PATH = '/'; 5 | 6 | var webpack = require('webpack'), 7 | config = require('../webpack.config'); 8 | 9 | delete config.chromeExtensionBoilerplate; 10 | 11 | config.mode = 'production'; 12 | 13 | webpack(config, function (err) { 14 | if (err) throw err; 15 | }); 16 | -------------------------------------------------------------------------------- /utils/env.js: -------------------------------------------------------------------------------- 1 | // tiny wrapper with default env vars 2 | module.exports = { 3 | NODE_ENV: process.env.NODE_ENV || 'development', 4 | PORT: process.env.PORT || 3001, 5 | TARGET: process.env.TARGET || 'chromium', 6 | }; 7 | --------------------------------------------------------------------------------