├── .gitignore ├── .idea ├── misc.xml ├── modules.xml └── vcs.xml ├── 01-Inquirerjs ├── .gitignore ├── README.md ├── examples │ ├── 01_input.js │ ├── 02_confirm.js │ ├── 03_list.js │ ├── 04_rawlist.js │ ├── 05_expand.js │ ├── 06_long-list.js │ ├── 07_checkbox.js │ ├── 08_password.js │ ├── 09_editor.js │ ├── 10_bottom-bar.js │ ├── 11_hierarchical.js │ ├── 12_nested-call.js │ ├── 13_recursive.js │ ├── 14_spawn.js │ ├── 15_when.js │ ├── 16_rx-observable-array.js │ └── 17_rx-observable-create.js ├── images │ ├── bottom-bar.png │ ├── checkbox.png │ ├── confirm.png │ ├── editor.png │ ├── expand.png │ ├── input.png │ ├── list.png │ ├── password.png │ └── rawlist.png └── package.json ├── 02-Lodash ├── .gitignore ├── README.md ├── examples │ ├── array │ │ ├── 01_chunk.js │ │ ├── 02_compact.js │ │ ├── 03_concat.js │ │ ├── 04_difference.js │ │ ├── 05_differenceby.js │ │ ├── 06_differencewith.js │ │ ├── 07_drop.js │ │ ├── 08_dropright.js │ │ ├── 09_droprightwhile.js │ │ ├── 10_dropwhile.js │ │ ├── 11_fill.js │ │ ├── 12_findindex.js │ │ ├── 13_findlastindex.js │ │ ├── 14_first.js │ │ ├── 15_flatten.js │ │ ├── 16_flattendeep.js │ │ ├── 17_flattendepth.js │ │ ├── 18_fromparis.js │ │ ├── 19_head.js │ │ ├── 20_indexof.js │ │ ├── 21_initial.js │ │ ├── 22_intersection.js │ │ ├── 23_intersectionby.js │ │ ├── 24_intersectionwith.js │ │ ├── 25_join.js │ │ ├── 26_last.js │ │ ├── 27_lastindexof.js │ │ ├── 28_nth.js │ │ ├── 29_pull.js │ │ ├── 30_pullall.js │ │ ├── 31_pullallby.js │ │ ├── 32_pullallwith.js │ │ ├── 33_pullat.js │ │ ├── 34_remove.js │ │ ├── 35_reverse.js │ │ ├── 36_slice.js │ │ ├── 37_sortedindex.js │ │ ├── 38_sortedindexby.js │ │ ├── 39_sortedindexof.js │ │ ├── 40_sortedlastindex.js │ │ ├── 41_sortedlastindexby.js │ │ ├── 42_sortedlastindexof.js │ │ ├── 43_sorteduniq.js │ │ ├── 44_sorteduniqby.js │ │ ├── 45_tail.js │ │ ├── 46_take.js │ │ ├── 47_takeright.js │ │ ├── 48_takerightwhile.js │ │ ├── 49_takewhile.js │ │ ├── 50_union.js │ │ ├── 51_unionby.js │ │ ├── 52_unionwith.js │ │ ├── 53_uniq.js │ │ ├── 54_uniqby.js │ │ ├── 55_uniqwith.js │ │ ├── 56_unzip.js │ │ ├── 57_unzipwith.js │ │ ├── 58_without.js │ │ ├── 59_xor.js │ │ ├── 60_xorby.js │ │ ├── 61_xorwith.js │ │ ├── 62_zip.js │ │ ├── 63_zipobject.js │ │ ├── 64_zipobjectdeep.js │ │ └── 65_zipwith.js │ ├── collection │ │ ├── 01_countby.js │ │ ├── 02_each.js │ │ ├── 03_eachright.js │ │ ├── 04_every.js │ │ ├── 05_filter.js │ │ ├── 06_find.js │ │ ├── 07_findlast.js │ │ ├── 08_flatmap.js │ │ ├── 09_flatmapdeep.js │ │ ├── 10_flatmapdepth.js │ │ ├── 11_foreach.js │ │ ├── 12_foreachright.js │ │ ├── 13_groupby.js │ │ ├── 14_includes.js │ │ ├── 15_invokemap.js │ │ ├── 16_keyby.js │ │ ├── 17_map.js │ │ ├── 18_orderby.js │ │ ├── 19_partition.js │ │ ├── 20_reduce.js │ │ ├── 21_reduceright.js │ │ ├── 22_reject.js │ │ ├── 23_sample.js │ │ ├── 24_samplesize.js │ │ ├── 25_shuffle.js │ │ ├── 26_size.js │ │ ├── 27_some.js │ │ └── 28_sortby.js │ ├── date │ │ └── 01_now.js │ ├── function │ │ ├── 01_after.js │ │ ├── 02_ary.js │ │ ├── 03_before.js │ │ ├── 04_bind.js │ │ ├── 05_bindkey.js │ │ ├── 06_curry.js │ │ ├── 07_curryright.js │ │ ├── 08_debounce.js │ │ ├── 09_defer.js │ │ ├── 10_delay.js │ │ ├── 11_flip.js │ │ ├── 12_memoize.js │ │ ├── 13_negate.js │ │ ├── 14_once.js │ │ ├── 15_overargs.js │ │ ├── 16_partial.js │ │ ├── 17_partialright.js │ │ ├── 18_rearg.js │ │ ├── 19_rest.js │ │ ├── 20_spread.js │ │ ├── 21_throttle.js │ │ ├── 22_unary.js │ │ └── 23_wrap.js │ ├── lang │ │ ├── 01_castarray.js │ │ ├── 02_clone.js │ │ ├── 03_clonedeep.js │ │ ├── 04_clonedeepwith.js │ │ ├── 05_clonewith.js │ │ ├── 06_confirmsto.js │ │ ├── 07_eq.js │ │ ├── 08_gt.js │ │ ├── 09_gte.js │ │ ├── 10_isarguments.js │ │ ├── 11_isarray.js │ │ ├── 12_isarraybuffer.js │ │ ├── 13_isarraylike.js │ │ ├── 14_isarraylikeobject.js │ │ ├── 15_isboolean.js │ │ ├── 16_isbuffer.js │ │ ├── 17_isdate.js │ │ ├── 18_iselement.js │ │ ├── 19_isempty.js │ │ ├── 20_isequal.js │ │ ├── 21_isequalwith.js │ │ ├── 22_iserror.js │ │ ├── 23_isfinite.js │ │ ├── 24_isfunction.js │ │ ├── 25_islength.js │ │ ├── 26_isinteger.js │ │ ├── 27_ismap.js │ │ ├── 28_ismatch.js │ │ ├── 29_ismatchwith.js │ │ ├── 30_isnan.js │ │ ├── 31_isnative.js │ │ ├── 32_isnil.js │ │ ├── 33_isnull.js │ │ ├── 34_isnumber.js │ │ ├── 35_isobject.js │ │ ├── 36_isobjectlike.js │ │ ├── 37_isplainobject.js │ │ ├── 38_isregexp.js │ │ ├── 39_issafeinteger.js │ │ ├── 40_isset.js │ │ ├── 41_isstring.js │ │ ├── 42_issymbol.js │ │ ├── 43_istypedarray.js │ │ ├── 44_isundefined.js │ │ ├── 45_isweakmap.js │ │ ├── 46_isweakset.js │ │ ├── 47_lt.js │ │ ├── 48_lte.js │ │ ├── 49_toarray.js │ │ ├── 50_tofinite.js │ │ ├── 51_tointeger.js │ │ ├── 52_tolength.js │ │ ├── 53_tonumber.js │ │ ├── 54_toplainobject.js │ │ ├── 55_tosafeinteger.js │ │ └── 56_tostring.js │ ├── math │ │ ├── 01_add.js │ │ ├── 02_ceil.js │ │ ├── 03_divide.js │ │ ├── 04_floor.js │ │ ├── 05_max.js │ │ ├── 06_maxby.js │ │ ├── 07_mean.js │ │ ├── 08_meanby.js │ │ ├── 09_min.js │ │ ├── 10_minby.js │ │ ├── 11_multiply.js │ │ ├── 12_round.js │ │ ├── 13_subtract.js │ │ ├── 14_sum.js │ │ └── 15_sumby.js │ ├── methods │ │ └── 01_ref-lodash-func.js │ ├── number │ │ ├── 01_clamp.js │ │ ├── 02_inrange.js │ │ └── 03_random.js │ ├── object │ │ ├── 01_assign.js │ │ ├── 02_assignin.js │ │ ├── 03_assigninwith.js │ │ ├── 04_assignwith.js │ │ ├── 05_at.js │ │ ├── 06_create.js │ │ ├── 07_defaults.js │ │ ├── 08_defaultsdeep.js │ │ ├── 09_entries.js │ │ ├── 10_entriesin.js │ │ ├── 11_extend.js │ │ ├── 12_extendwith.js │ │ ├── 13_findkey.js │ │ ├── 14_findlastkey.js │ │ ├── 15_forin.js │ │ ├── 16_forinright.js │ │ ├── 17_forown.js │ │ ├── 18_forownright.js │ │ ├── 19_functions.js │ │ ├── 20_functionsin.js │ │ ├── 21_get.js │ │ ├── 22_has.js │ │ ├── 23_hasin.js │ │ ├── 24_invert.js │ │ ├── 25_invertby.js │ │ ├── 26_invoke.js │ │ ├── 27_keys.js │ │ ├── 28_keysin.js │ │ ├── 29_mapkeys.js │ │ ├── 30_mapvalues.js │ │ ├── 31_merge.js │ │ ├── 32_mergewith.js │ │ ├── 33_omit.js │ │ ├── 34_omitby.js │ │ ├── 35_pick.js │ │ ├── 36_pickby.js │ │ ├── 37_result.js │ │ ├── 38_set.js │ │ ├── 39_setwith.js │ │ ├── 40_topairs.js │ │ ├── 41_topairsin.js │ │ ├── 42_transform.js │ │ ├── 43_unset.js │ │ ├── 44_update.js │ │ ├── 45_updatewith.js │ │ ├── 46_values.js │ │ └── 47_valuesin.js │ ├── properties │ │ ├── 01_version.js │ │ ├── 02_templatesettings.js │ │ ├── 03_templatesettings-escape.js │ │ ├── 04_templatesettings-evaluate.js │ │ ├── 05_templatesettings-imports.js │ │ ├── 06_templatesettings-interpolate.js │ │ └── 07_templatesettings-variable.js │ ├── seq │ │ ├── 01_lodash.js │ │ ├── 02_chain.js │ │ ├── 03_tap.js │ │ ├── 04_thru.js │ │ ├── 05_prototype-symbol.js │ │ ├── 06_prototype-at.js │ │ ├── 07_prototype-chain.js │ │ ├── 08_prototype-commit.js │ │ ├── 09_prototype-next.js │ │ ├── 10_prototype-plant.js │ │ ├── 11_prototype-reverse.js │ │ ├── 12_prototype-json.js │ │ ├── 13_prototype-value.js │ │ └── 14_prototype-valueof.js │ ├── string │ │ ├── 01_camelcase.js │ │ ├── 02_capitalize.js │ │ ├── 03_deburr.js │ │ ├── 04_endswith.js │ │ ├── 05_escape.js │ │ ├── 06_escaperegexp.js │ │ ├── 07_kebabcase.js │ │ ├── 08_lowercase.js │ │ ├── 09_lowerfirst.js │ │ ├── 10_pad.js │ │ ├── 11_padend.js │ │ ├── 12_padstart.js │ │ ├── 13_parseint.js │ │ ├── 14_repeat.js │ │ ├── 15_replace.js │ │ ├── 16_snakecase.js │ │ ├── 17_split.js │ │ ├── 18_startcase.js │ │ ├── 19_startswith.js │ │ ├── 20_template.js │ │ ├── 21_tolower.js │ │ ├── 22_toupper.js │ │ ├── 23_trim.js │ │ ├── 24_trimend.js │ │ ├── 25_trimstart.js │ │ ├── 26_truncate.js │ │ ├── 27_unescape.js │ │ ├── 28_uppercase.js │ │ ├── 29_upperfirst.js │ │ └── 30_words.js │ └── util │ │ ├── 01_attempt.js │ │ ├── 02_bindall.js │ │ ├── 03_cond.js │ │ ├── 04_conforms.js │ │ ├── 05_constant.js │ │ ├── 06_defaultto.js │ │ ├── 07_flow.js │ │ ├── 08_flowright.js │ │ ├── 09_identity.js │ │ ├── 10_iteratee.js │ │ ├── 11_matches.js │ │ ├── 12_matchesproperty.js │ │ ├── 13_method.js │ │ ├── 14_methodof.js │ │ ├── 15_mixin.js │ │ ├── 16_noconflict.js │ │ ├── 17_noop.js │ │ ├── 18_ntharg.js │ │ ├── 19_over.js │ │ ├── 20_overevery.js │ │ ├── 21_oversome.js │ │ ├── 22_property.js │ │ ├── 23_propertyof.js │ │ ├── 24_range.js │ │ ├── 25_rangeright.js │ │ ├── 26_runincontext.js │ │ ├── 27_stubarray.js │ │ ├── 28_stubfalse.js │ │ ├── 29_stubobject.js │ │ ├── 30_stubstring.js │ │ ├── 31_stubtrue.js │ │ ├── 32_times.js │ │ ├── 33_topath.js │ │ └── 34_uniqueid.js └── package.json ├── 03-Webpack ├── 01-basic │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── index.html │ ├── package.json │ ├── src │ │ ├── one.js │ │ └── two.js │ └── webpack.config.js ├── 02-babel-loader │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── index.html │ ├── package.json │ ├── src │ │ ├── one.js │ │ └── two.js │ └── webpack.config.js ├── 03-css-loader │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── index.html │ ├── package.json │ ├── src │ │ ├── css │ │ │ └── introComponent.css │ │ ├── one.js │ │ └── two.js │ └── webpack.config.js ├── 04-sass-loader │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── index.html │ ├── package.json │ ├── src │ │ ├── css │ │ │ └── introComponent.scss │ │ ├── one.js │ │ └── two.js │ └── webpack.config.js ├── README.md └── images │ ├── one.png │ └── two.png ├── 04-RxJS └── README.md ├── 05-TypeScript ├── 01-basicTypes │ ├── 01_boolean.ts │ ├── 02_number.ts │ ├── 03_string.ts │ ├── 04_array.ts │ ├── 05_tuple.ts │ ├── 06_enum.ts │ ├── 07_any.ts │ ├── 08_void.ts │ ├── 09_unused.ts │ └── 10_never.ts ├── 02-interfaces │ ├── 01_firstinterface.ts │ ├── 02_optionalparams.ts │ └── 03_readonlyparams.ts ├── 03-classes │ └── 01_inheritance.ts ├── 04-functions │ ├── 01_functiontypes.ts │ ├── 02_inferringtypes.ts │ ├── 03_optionals&defaults.ts │ └── 04_restparameters.ts ├── 05-generics │ └── 01_basic.ts ├── 06-enums │ └── 01_basic.ts └── README.md ├── README.md └── javascript-frameworks.iml /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .idea 4 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /01-Inquirerjs/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .idea 4 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/01_input.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Input prompt example 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | var questions = [ 9 | { 10 | type: 'input', 11 | name: 'name', 12 | message: 'What\'s your name' 13 | }, 14 | { 15 | type: 'input', 16 | name: 'language', 17 | message: 'What\'s your mother tongue', 18 | default: function () { 19 | return 'English'; 20 | } 21 | }, 22 | { 23 | type: 'input', 24 | name: 'age', 25 | message: 'What\'s your age', 26 | validate: function (value) { 27 | var age = value.match(/^[1-9][0-9]?$|^100$/i); 28 | if (age) { 29 | return true; 30 | } 31 | 32 | return 'Please enter a valid age'; 33 | } 34 | }, 35 | 36 | { 37 | type: 'input', 38 | name: 'phone', 39 | message: 'What\'s your phone number', 40 | validate: function (value) { 41 | var pass = value.match(/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im); 42 | if (pass) { 43 | return true; 44 | } 45 | 46 | return 'Please enter a valid phone number'; 47 | } 48 | } 49 | ]; 50 | 51 | inquirer.prompt(questions).then(function (answers) { 52 | console.log(JSON.stringify(answers, null, ' ')); 53 | }); 54 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/02_confirm.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Confirm example 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | var questions = [ 9 | { 10 | type: 'confirm', 11 | name: 'toBeLiked', 12 | message: 'Do you like InquirerJS?', 13 | default: true 14 | } 15 | ]; 16 | 17 | inquirer.prompt(questions).then(function (answers) { 18 | console.log(JSON.stringify(answers, null, ' ')); 19 | }); 20 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/03_list.js: -------------------------------------------------------------------------------- 1 | /** 2 | * List example 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | var questions = [ 9 | { 10 | type: 'list', 11 | name: 'product', 12 | message: 'Which Apple product you like more?', 13 | choices: ['iPhone8', 'AppleWatch', 'MacBookPro', 'iPhoneX', 'iPad', 'iPhone7'], 14 | filter: function (val) { 15 | return val.toLowerCase(); 16 | } 17 | } 18 | ]; 19 | 20 | inquirer.prompt(questions).then(function (answers) { 21 | console.log(JSON.stringify(answers, null, ' ')); 22 | }); 23 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/04_rawlist.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RawList example 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | var questions = [ 9 | { 10 | type: 'rawlist', 11 | name: 'product', 12 | message: 'Which Apple product you like more?', 13 | choices: ['iPhone8', 'AppleWatch', 'MacBookPro', 'iPhoneX', 'iPad', 'iPhone7'], 14 | filter: function (val) { 15 | return val.toLowerCase(); 16 | } 17 | } 18 | ]; 19 | 20 | inquirer.prompt(questions).then(function (answers) { 21 | console.log(JSON.stringify(answers, null, ' ')); 22 | }); 23 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/05_expand.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Expand list examples 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | inquirer.prompt([ 9 | { 10 | type: 'expand', 11 | message: 'Conflict on `index.js`: ', 12 | name: 'overwrite', 13 | choices: [ 14 | { 15 | key: 'y', 16 | name: 'Overwrite', 17 | value: 'overwrite' 18 | }, 19 | { 20 | key: 'a', 21 | name: 'Overwrite this one and all next', 22 | value: 'overwrite_all' 23 | }, 24 | { 25 | key: 'd', 26 | name: 'Show diff', 27 | value: 'diff' 28 | }, 29 | { 30 | key: 'x', 31 | name: 'Abort', 32 | value: 'abort' 33 | } 34 | ] 35 | } 36 | ]).then(function (answers) { 37 | console.log(JSON.stringify(answers, null, ' ')); 38 | }); 39 | 40 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/06_long-list.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Paginated list 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | var choices = Array.apply(0, new Array(26)).map(function (x, y) { 9 | return String.fromCharCode(y + 65); 10 | }); 11 | choices.push('Multiline option \n super cool feature'); 12 | choices.push({ 13 | name: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.', 14 | value: 'foo', 15 | short: 'The long option' 16 | }); 17 | 18 | inquirer.prompt([ 19 | { 20 | type: 'list', 21 | name: 'letter', 22 | message: 'What\'s your favorite letter?', 23 | paginated: true, 24 | pageSize: 10, 25 | choices: choices 26 | }, 27 | { 28 | type: 'checkbox', 29 | name: 'name', 30 | message: 'Select the letter contained in your name:', 31 | paginated: true, 32 | choices: choices 33 | } 34 | ]).then(function (answers) { 35 | console.log(JSON.stringify(answers, null, ' ')); 36 | }); 37 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/07_checkbox.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checkbox prompt example 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | inquirer.prompt([ 9 | { 10 | type: 'checkbox', 11 | message: 'Select toppings', 12 | name: 'toppings', 13 | choices: [ 14 | new inquirer.Separator(' = The Meats = '), 15 | { 16 | name: 'Pepperoni' 17 | }, 18 | { 19 | name: 'Ham' 20 | }, 21 | { 22 | name: 'Ground Meat' 23 | }, 24 | { 25 | name: 'Bacon' 26 | }, 27 | new inquirer.Separator(' = The Cheeses = '), 28 | { 29 | name: 'Mozzarella', 30 | checked: true 31 | }, 32 | { 33 | name: 'Cheddar' 34 | }, 35 | { 36 | name: 'Parmesan' 37 | }, 38 | new inquirer.Separator(' = The usual ='), 39 | { 40 | name: 'Mushroom' 41 | }, 42 | { 43 | name: 'Tomato' 44 | }, 45 | new inquirer.Separator(' = The extras = '), 46 | { 47 | name: 'Pineapple' 48 | }, 49 | { 50 | name: 'Olives', 51 | disabled: 'out of stock' 52 | }, 53 | { 54 | name: 'Extra cheese' 55 | } 56 | ], 57 | validate: function (answer) { 58 | if (answer.length < 1) { 59 | return 'You must choose at least one topping.'; 60 | } 61 | return true; 62 | } 63 | } 64 | ]).then(function (answers) { 65 | console.log(JSON.stringify(answers, null, ' ')); 66 | }); 67 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/08_password.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Password prompt example 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | const requireLetterAndNumber = value => { 9 | if (/\w/.test(value) && /\d/.test(value)) { 10 | return true; 11 | } 12 | return 'Password need to have at least a letter and a number'; 13 | }; 14 | 15 | inquirer.prompt([ 16 | { 17 | type: 'password', 18 | message: 'Enter a password', 19 | name: 'password1', 20 | validate: requireLetterAndNumber 21 | }, 22 | { 23 | type: 'password', 24 | message: 'Enter a masked password', 25 | name: 'password2', 26 | mask: '*', 27 | validate: requireLetterAndNumber 28 | } 29 | ]).then(answers => console.log(JSON.stringify(answers, null, ' '))); -------------------------------------------------------------------------------- /01-Inquirerjs/examples/09_editor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Editor example 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | var questions = [ 9 | { 10 | type: 'editor', 11 | name: 'biography', 12 | message: 'Please write a short biography of at least 3 lines.', 13 | validate: function (text) { 14 | if (text.split('\n').length < 3) { 15 | return 'Must be at least 3 lines.'; 16 | } 17 | 18 | return true; 19 | } 20 | } 21 | ]; 22 | 23 | inquirer.prompt(questions).then(function (answers) { 24 | console.log(JSON.stringify(answers, null, ' ')); 25 | }); -------------------------------------------------------------------------------- /01-Inquirerjs/examples/10_bottom-bar.js: -------------------------------------------------------------------------------- 1 | var BottomBar = require('inquirer/lib/ui/bottom-bar'); 2 | var cmdify = require('cmdify'); 3 | 4 | var loader = [ 5 | '/ Installing', 6 | '| Installing', 7 | '\\ Installing', 8 | '- Installing' 9 | ]; 10 | var i = 4; 11 | var ui = new BottomBar({bottomBar: loader[i % 4]}); 12 | 13 | setInterval(function () { 14 | ui.updateBottomBar(loader[i++ % 4]); 15 | }, 300); 16 | 17 | var spawn = require('child_process').spawn; 18 | 19 | var cmd = spawn(cmdify('npm'), ['-g', 'install', 'inquirer'], {stdio: 'pipe'}); 20 | cmd.stdout.pipe(ui.log); 21 | cmd.on('close', function () { 22 | ui.updateBottomBar('Installation done!\n'); 23 | process.exit(); 24 | }); 25 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/11_hierarchical.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Hierarchical conversation example 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | var directionsPrompt = { 9 | type: 'list', 10 | name: 'direction', 11 | message: 'Which direction would you like to go?', 12 | choices: ['Forward', 'Right', 'Left', 'Back'] 13 | }; 14 | 15 | function main() { 16 | console.log('You find youself in a small room, there is a door in front of you.'); 17 | exitHouse(); 18 | } 19 | 20 | function exitHouse() { 21 | inquirer.prompt(directionsPrompt).then(function (answers) { 22 | if (answers.direction === 'Forward') { 23 | console.log('You find yourself in a forest'); 24 | console.log('There is a wolf in front of you; a friendly looking dwarf to the right and an impasse to the left.'); 25 | encounter1(); 26 | } else { 27 | console.log('You cannot go that way. Try again'); 28 | exitHouse(); 29 | } 30 | }); 31 | } 32 | 33 | function encounter1() { 34 | inquirer.prompt(directionsPrompt).then(function (answers) { 35 | var direction = answers.direction; 36 | if (direction === 'Forward') { 37 | console.log('You attempt to fight the wolf'); 38 | console.log('Theres a stick and some stones lying around you could use as a weapon'); 39 | encounter2b(); 40 | } else if (direction === 'Right') { 41 | console.log('You befriend the dwarf'); 42 | console.log('He helps you kill the wolf. You can now move forward'); 43 | encounter2a(); 44 | } else { 45 | console.log('You cannot go that way'); 46 | encounter1(); 47 | } 48 | }); 49 | } 50 | 51 | function encounter2a() { 52 | inquirer.prompt(directionsPrompt).then(function (answers) { 53 | var direction = answers.direction; 54 | if (direction === 'Forward') { 55 | var output = 'You find a painted wooden sign that says:'; 56 | output += ' \n'; 57 | output += ' ____ _____ ____ _____ \n'; 58 | output += '(_ _)( _ )( _ \\( _ ) \n'; 59 | output += ' )( )(_)( )(_) ))(_)( \n'; 60 | output += ' (__) (_____)(____/(_____) \n'; 61 | console.log(output); 62 | } else { 63 | console.log('You cannot go that way'); 64 | encounter2a(); 65 | } 66 | }); 67 | } 68 | 69 | function encounter2b() { 70 | inquirer.prompt({ 71 | type: 'list', 72 | name: 'weapon', 73 | message: 'Pick one', 74 | choices: [ 75 | 'Use the stick', 76 | 'Grab a large rock', 77 | 'Try and make a run for it', 78 | 'Attack the wolf unarmed' 79 | ] 80 | }).then(function () { 81 | console.log('The wolf mauls you. You die. The end.'); 82 | }); 83 | } 84 | 85 | main(); 86 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/12_nested-call.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Nested Inquirer call 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | inquirer.prompt({ 9 | type: 'list', 10 | name: 'chocolate', 11 | message: 'What\'s your favorite chocolate?', 12 | choices: ['Mars', 'Oh Henry', 'Hershey'] 13 | }).then(function () { 14 | inquirer.prompt({ 15 | type: 'list', 16 | name: 'beverage', 17 | message: 'And your favorite beverage?', 18 | choices: ['Pepsi', 'Coke', '7up', 'Mountain Dew', 'Red Bull'] 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/13_recursive.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Recursive prompt example 3 | * Allows user to choose when to exit prompt 4 | */ 5 | 6 | 'use strict'; 7 | var inquirer = require('../node_modules/inquirer'); 8 | var output = []; 9 | 10 | var questions = [ 11 | { 12 | type: 'input', 13 | name: 'tvShow', 14 | message: 'What\'s your favorite TV show?' 15 | }, 16 | { 17 | type: 'confirm', 18 | name: 'askAgain', 19 | message: 'Want to enter another TV show favorite (just hit enter for YES)?', 20 | default: true 21 | } 22 | ]; 23 | 24 | function ask() { 25 | inquirer.prompt(questions).then(function (answers) { 26 | output.push(answers.tvShow); 27 | if (answers.askAgain) { 28 | ask(); 29 | } else { 30 | console.log('Your favorite TV Shows:', output.join(', ')); 31 | } 32 | }); 33 | } 34 | 35 | ask(); 36 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/14_spawn.js: -------------------------------------------------------------------------------- 1 | var spawn = require('child_process').spawn; 2 | 3 | spawn('node', ['01_input.js'], { 4 | cwd: __dirname, 5 | stdio: 'inherit' 6 | }); 7 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/15_when.js: -------------------------------------------------------------------------------- 1 | /** 2 | * When example 3 | */ 4 | 5 | 'use strict'; 6 | var inquirer = require('../node_modules/inquirer'); 7 | 8 | var questions = [ 9 | { 10 | type: 'confirm', 11 | name: 'bacon', 12 | message: 'Do you like bacon?' 13 | }, 14 | { 15 | type: 'input', 16 | name: 'favorite', 17 | message: 'Bacon lover, what is your favorite type of bacon?', 18 | when: function (answers) { 19 | return answers.bacon; 20 | } 21 | }, 22 | { 23 | type: 'confirm', 24 | name: 'pizza', 25 | message: 'Ok... Do you like pizza?', 26 | when: function (answers) { 27 | return !likesFood('bacon')(answers); 28 | } 29 | }, 30 | { 31 | type: 'input', 32 | name: 'favorite', 33 | message: 'Whew! What is your favorite type of pizza?', 34 | when: likesFood('pizza') 35 | } 36 | ]; 37 | 38 | function likesFood(aFood) { 39 | return function (answers) { 40 | return answers[aFood]; 41 | }; 42 | } 43 | 44 | inquirer.prompt(questions).then(function (answers) { 45 | console.log(JSON.stringify(answers, null, ' ')); 46 | }); 47 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/16_rx-observable-array.js: -------------------------------------------------------------------------------- 1 | var inquirer = require('../node_modules/inquirer'); 2 | var Rx = require('rx-lite-aggregates'); 3 | 4 | var questions = [ 5 | { 6 | type: 'input', 7 | name: 'first_name', 8 | message: 'What\'s your first name' 9 | }, 10 | { 11 | type: 'input', 12 | name: 'last_name', 13 | message: 'What\'s your last name', 14 | default: function () { 15 | return 'Doe'; 16 | } 17 | }, 18 | { 19 | type: 'input', 20 | name: 'phone', 21 | message: 'What\'s your phone number', 22 | validate: function (value) { 23 | var pass = value.match(/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im); 24 | if (pass) { 25 | return true; 26 | } 27 | 28 | return 'Please enter a valid phone number'; 29 | } 30 | } 31 | ]; 32 | 33 | var observable = Rx.Observable.fromArray(questions); 34 | 35 | inquirer.prompt(observable).ui.process.subscribe( 36 | function (ans) { 37 | console.log('Answer is: ', ans); 38 | }, 39 | function (err) { 40 | console.log('Error: ', err); 41 | }, 42 | function () { 43 | console.log('Completed'); 44 | } 45 | ); 46 | -------------------------------------------------------------------------------- /01-Inquirerjs/examples/17_rx-observable-create.js: -------------------------------------------------------------------------------- 1 | var inquirer = require('../node_modules/inquirer'); 2 | var Rx = require('rx-lite-aggregates'); 3 | 4 | var observe = Rx.Observable.create(function (obs) { 5 | obs.onNext({ 6 | type: 'input', 7 | name: 'first_name', 8 | message: 'What\'s your first name' 9 | }); 10 | 11 | obs.onNext({ 12 | type: 'input', 13 | name: 'last_name', 14 | message: 'What\'s your last name', 15 | default: function () { 16 | return 'Doe'; 17 | } 18 | }); 19 | 20 | obs.onNext({ 21 | type: 'input', 22 | name: 'phone', 23 | message: 'What\'s your phone number', 24 | validate: function (value) { 25 | var pass = value.match(/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im); 26 | if (pass) { 27 | return true; 28 | } 29 | 30 | return 'Please enter a valid phone number'; 31 | } 32 | }); 33 | obs.onCompleted(); 34 | }); 35 | 36 | inquirer.prompt(observe).then(function (answers) { 37 | console.log(JSON.stringify(answers, null, ' ')); 38 | }); 39 | -------------------------------------------------------------------------------- /01-Inquirerjs/images/bottom-bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/01-Inquirerjs/images/bottom-bar.png -------------------------------------------------------------------------------- /01-Inquirerjs/images/checkbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/01-Inquirerjs/images/checkbox.png -------------------------------------------------------------------------------- /01-Inquirerjs/images/confirm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/01-Inquirerjs/images/confirm.png -------------------------------------------------------------------------------- /01-Inquirerjs/images/editor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/01-Inquirerjs/images/editor.png -------------------------------------------------------------------------------- /01-Inquirerjs/images/expand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/01-Inquirerjs/images/expand.png -------------------------------------------------------------------------------- /01-Inquirerjs/images/input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/01-Inquirerjs/images/input.png -------------------------------------------------------------------------------- /01-Inquirerjs/images/list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/01-Inquirerjs/images/list.png -------------------------------------------------------------------------------- /01-Inquirerjs/images/password.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/01-Inquirerjs/images/password.png -------------------------------------------------------------------------------- /01-Inquirerjs/images/rawlist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/01-Inquirerjs/images/rawlist.png -------------------------------------------------------------------------------- /01-Inquirerjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "01-Inquirerjs", 3 | "version": "0.0.1", 4 | "devDependencies": { 5 | "child_process": "^1.0.2", 6 | "cmdify": "^0.0.4", 7 | "inquirer": "^3.3.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /02-Lodash/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .idea 4 | -------------------------------------------------------------------------------- /02-Lodash/examples/array/01_chunk.js: -------------------------------------------------------------------------------- 1 | /** 2 | * chunk example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.chunk(['a', 'b', 'c', 'd', 'e', 'f'], 2)); 9 | // => [['a', 'b'], ['c', 'd'], ['e', 'f']] 10 | 11 | console.log(_.chunk(['a', 'b', 'c', 'd', 'e', 'f'], 3)); 12 | // => [['a', 'b', 'c'], ['d', 'e', 'f']] -------------------------------------------------------------------------------- /02-Lodash/examples/array/02_compact.js: -------------------------------------------------------------------------------- 1 | /** 2 | * compact example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.compact([0, 1, false, 2, '', 3, 4])); 9 | // => [1, 2, 3, 4] -------------------------------------------------------------------------------- /02-Lodash/examples/array/03_concat.js: -------------------------------------------------------------------------------- 1 | /** 2 | * concat example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [1]; 9 | var other = _.concat(array, 2, [3], [[4]]); 10 | 11 | console.log(other); 12 | // => [1, 2, 3, [4]] 13 | 14 | console.log(array); 15 | // => [1] -------------------------------------------------------------------------------- /02-Lodash/examples/array/04_difference.js: -------------------------------------------------------------------------------- 1 | /** 2 | * difference example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.difference([2, 1, 3], [2, 3, 3])); 9 | // => [1] -------------------------------------------------------------------------------- /02-Lodash/examples/array/05_differenceby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * differenceBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor)); 9 | // => [1.2] 10 | 11 | // The `_.property` iteratee shorthand. 12 | console.log(_.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x')); 13 | // => [{ 'x': 2 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/06_differencewith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * differenceWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 9 | 10 | console.log(_.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual)); 11 | // => [{ 'x': 2, 'y': 1 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/07_drop.js: -------------------------------------------------------------------------------- 1 | /** 2 | * drop example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.drop([1, 2, 3])); 9 | // => [2, 3] 10 | 11 | console.log(_.drop([1, 2, 3], 2)); 12 | // => [3] 13 | 14 | console.log(_.drop([1, 2, 3], 5)); 15 | // => [] 16 | 17 | console.log(_.drop([1, 2, 3], 0)); 18 | // => [1, 2, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/array/08_dropright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * dropRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.dropRight([1, 2, 3])); 9 | // => [1, 2] 10 | 11 | console.log(_.dropRight([1, 2, 3], 2)); 12 | // => [1] 13 | 14 | console.log(_.dropRight([1, 2, 3], 5)); 15 | // => [] 16 | 17 | console.log(_.dropRight([1, 2, 3], 0)); 18 | // => [1, 2, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/array/09_droprightwhile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * dropRightWhile example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'active': true }, 10 | { 'user': 'fred', 'active': false }, 11 | { 'user': 'pebbles', 'active': false } 12 | ]; 13 | 14 | console.log(_.dropRightWhile(users, function(o) { return !o.active; })); 15 | // => objects for ['barney'] 16 | 17 | // The `_.matches` iteratee shorthand. 18 | console.log(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false })); 19 | // => objects for ['barney', 'fred'] 20 | 21 | // The `_.matchesProperty` iteratee shorthand. 22 | console.log(_.dropRightWhile(users, ['active', false])); 23 | // => objects for ['barney'] 24 | 25 | // The `_.property` iteratee shorthand. 26 | console.log(_.dropRightWhile(users, 'active')); 27 | // => objects for ['barney', 'fred', 'pebbles'] -------------------------------------------------------------------------------- /02-Lodash/examples/array/10_dropwhile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * dropWhile example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'active': false }, 10 | { 'user': 'fred', 'active': false }, 11 | { 'user': 'pebbles', 'active': true } 12 | ]; 13 | 14 | console.log(_.dropWhile(users, function(o) { return !o.active; })); 15 | // => objects for ['pebbles'] 16 | 17 | // The `_.matches` iteratee shorthand. 18 | console.log(_.dropWhile(users, { 'user': 'barney', 'active': false })); 19 | // => objects for ['fred', 'pebbles'] 20 | 21 | // The `_.matchesProperty` iteratee shorthand. 22 | console.log(_.dropWhile(users, ['active', false])); 23 | // => objects for ['pebbles'] 24 | 25 | // The `_.property` iteratee shorthand. 26 | console.log(_.dropWhile(users, 'active')); 27 | // => objects for ['barney', 'fred', 'pebbles'] -------------------------------------------------------------------------------- /02-Lodash/examples/array/11_fill.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fill example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [1, 2, 3]; 9 | 10 | console.log(_.fill(array, 'a')); 11 | console.log(array); 12 | // => ['a', 'a', 'a'] 13 | 14 | console.log(_.fill(Array(3), 2)); 15 | // => [2, 2, 2] 16 | 17 | console.log(_.fill([4, 6, 8, 10], '*', 1, 3)); 18 | // => [4, '*', '*', 10] -------------------------------------------------------------------------------- /02-Lodash/examples/array/12_findindex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * findIndex example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'active': false }, 10 | { 'user': 'fred', 'active': false }, 11 | { 'user': 'pebbles', 'active': true } 12 | ]; 13 | 14 | console.log(_.findIndex(users, function(o) { return o.user == 'barney'; })); 15 | // => 0 16 | 17 | // The `_.matches` iteratee shorthand. 18 | console.log(_.findIndex(users, { 'user': 'fred', 'active': false })); 19 | // => 1 20 | 21 | // The `_.matchesProperty` iteratee shorthand. 22 | console.log(_.findIndex(users, ['active', false])); 23 | // => 0 24 | 25 | // The `_.property` iteratee shorthand. 26 | console.log(_.findIndex(users, 'active')); 27 | // => 2 -------------------------------------------------------------------------------- /02-Lodash/examples/array/13_findlastindex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * findLastIndex example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'active': false }, 10 | { 'user': 'fred', 'active': false }, 11 | { 'user': 'pebbles', 'active': true } 12 | ]; 13 | 14 | console.log(_.findLastIndex(users, function(o) { return o.user == 'barney'; })); 15 | // => 2 16 | 17 | // The `_.matches` iteratee shorthand. 18 | console.log(_.findLastIndex(users, { 'user': 'fred', 'active': false })); 19 | // => 0 20 | 21 | // The `_.matchesProperty` iteratee shorthand. 22 | console.log(_.findLastIndex(users, ['active', false])); 23 | // => 2 24 | 25 | // The `_.property` iteratee shorthand. 26 | console.log(_.findLastIndex(users, 'active')); 27 | // => 0 -------------------------------------------------------------------------------- /02-Lodash/examples/array/14_first.js: -------------------------------------------------------------------------------- 1 | /** 2 | * head example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.head([1, 2, 3])); 9 | // => 1 10 | 11 | console.log(_.head([])); 12 | // => undefined -------------------------------------------------------------------------------- /02-Lodash/examples/array/15_flatten.js: -------------------------------------------------------------------------------- 1 | /** 2 | * flatten example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.flatten([1, [2, [3, [4]], 5]])); 9 | // => [1, 2, [3, [4]], 5] -------------------------------------------------------------------------------- /02-Lodash/examples/array/16_flattendeep.js: -------------------------------------------------------------------------------- 1 | /** 2 | * flattenDeep example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.flattenDeep([1, [2, [3, [4]], 5]])); 9 | // => [1, 2, 3, 4, 5] -------------------------------------------------------------------------------- /02-Lodash/examples/array/17_flattendepth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * flattenDepth example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [1, [2, [3, [4]], 5]]; 9 | 10 | console.log(_.flattenDepth(array, 1)); 11 | // => [1, 2, [3, [4]], 5] 12 | 13 | console.log(_.flattenDepth(array, 2)); 14 | // => [1, 2, 3, [4], 5] -------------------------------------------------------------------------------- /02-Lodash/examples/array/18_fromparis.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fromPairs example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.fromPairs([['a', 1], ['b', 2]])); 9 | // => { 'a': 1, 'b': 2 } -------------------------------------------------------------------------------- /02-Lodash/examples/array/19_head.js: -------------------------------------------------------------------------------- 1 | /** 2 | * head example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.head([1, 2, 3])); 9 | // => 1 10 | 11 | console.log(_.head([])); 12 | // => undefined 13 | -------------------------------------------------------------------------------- /02-Lodash/examples/array/20_indexof.js: -------------------------------------------------------------------------------- 1 | /** 2 | * indexOf example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.indexOf([1, 2, 1, 2], 2)); 9 | // => 1 10 | 11 | // Search from the `fromIndex`. 12 | console.log(_.indexOf([1, 2, 1, 2], 2, 2)); 13 | // => 3 -------------------------------------------------------------------------------- /02-Lodash/examples/array/21_initial.js: -------------------------------------------------------------------------------- 1 | /** 2 | * initial example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.initial([1, 2, 3])); 9 | // => [1, 2] -------------------------------------------------------------------------------- /02-Lodash/examples/array/22_intersection.js: -------------------------------------------------------------------------------- 1 | /** 2 | * intersectionexample 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.intersection([2, 1], [2, 3])); 9 | // => [2] -------------------------------------------------------------------------------- /02-Lodash/examples/array/23_intersectionby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * intersectionBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor)); 9 | // => [2.1] 10 | 11 | // The `_.property` iteratee shorthand. 12 | console.log(_.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x')); 13 | // => [{ 'x': 1 }] 14 | // => ['lodash', 'utility'] -------------------------------------------------------------------------------- /02-Lodash/examples/array/24_intersectionwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * intersectionWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 9 | var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; 10 | 11 | console.log(_.intersectionWith(objects, others, _.isEqual)); 12 | // => [{ 'x': 1, 'y': 2 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/25_join.js: -------------------------------------------------------------------------------- 1 | /** 2 | * join example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.join(['a', 'b', 'c'], '~')); 9 | // => 'a~b~c' -------------------------------------------------------------------------------- /02-Lodash/examples/array/26_last.js: -------------------------------------------------------------------------------- 1 | /** 2 | * last example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.last([1, 2, 3])); 9 | // => 3 -------------------------------------------------------------------------------- /02-Lodash/examples/array/27_lastindexof.js: -------------------------------------------------------------------------------- 1 | /** 2 | * lastIndexOf example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(__.lastIndexOf([1, 2, 1, 2], 2)); 9 | // => 3 10 | 11 | // Search from the `fromIndex`. 12 | console.log(__.lastIndexOf([1, 2, 1, 2], 2, 2)); 13 | // => 1 -------------------------------------------------------------------------------- /02-Lodash/examples/array/28_nth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * nth example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = ['a', 'b', 'c', 'd']; 9 | 10 | console.log(_.nth(array, 1)); 11 | // => 'b' 12 | 13 | console.log(_.nth(array, -2)); 14 | // => 'c'; -------------------------------------------------------------------------------- /02-Lodash/examples/array/29_pull.js: -------------------------------------------------------------------------------- 1 | /** 2 | * pull example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = ['a', 'b', 'c', 'a', 'b', 'c']; 9 | 10 | console.log(_.pull(array, 'a', 'c')); 11 | console.log(array); 12 | // => ['b', 'b'] -------------------------------------------------------------------------------- /02-Lodash/examples/array/30_pullall.js: -------------------------------------------------------------------------------- 1 | /** 2 | * pullAll example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | _.pullAll(array, ['a', 'c']); 9 | console.log(array); 10 | // => ['b', 'b'] -------------------------------------------------------------------------------- /02-Lodash/examples/array/31_pullallby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * pullAllBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }]; 9 | 10 | _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x'); 11 | console.log(array); 12 | // => [{ 'x': 2 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/32_pullallwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * pullAllWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }]; 9 | 10 | _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual); 11 | console.log(array); 12 | // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/33_pullat.js: -------------------------------------------------------------------------------- 1 | /** 2 | * pullAt example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = ['a', 'b', 'c', 'd']; 9 | var pulled = _.pullAt(array, [1, 3]); 10 | 11 | console.log(array); 12 | // => ['a', 'c'] 13 | 14 | console.log(pulled); 15 | // => ['b', 'd'] -------------------------------------------------------------------------------- /02-Lodash/examples/array/34_remove.js: -------------------------------------------------------------------------------- 1 | /** 2 | * remove example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [1, 2, 3, 4]; 9 | var evens = _.remove(array, function(n) { 10 | return n % 2 == 0; 11 | }); 12 | 13 | console.log(array); 14 | // => [1, 3] 15 | 16 | console.log(evens); 17 | // => [2, 4] -------------------------------------------------------------------------------- /02-Lodash/examples/array/35_reverse.js: -------------------------------------------------------------------------------- 1 | /** 2 | * reverse example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [1, 2, 3]; 9 | 10 | _.reverse(array); 11 | // => [3, 2, 1] 12 | 13 | console.log(array); 14 | // => [3, 2, 1] -------------------------------------------------------------------------------- /02-Lodash/examples/array/36_slice.js: -------------------------------------------------------------------------------- 1 | /** 2 | * slice example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array= ['a', 'c' , 'd', 'm', 'e']; 9 | 10 | console.log(_.slice(array, 1, 3)) -------------------------------------------------------------------------------- /02-Lodash/examples/array/37_sortedindex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sortedIndex example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.sortedIndex([30, 50], 40)); 9 | // => 1 -------------------------------------------------------------------------------- /02-Lodash/examples/array/38_sortedindexby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sortedIndexBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'x': 4 }, { 'x': 5 }]; 9 | 10 | console.log(_.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; })); 11 | // => 0 12 | 13 | // The `_.property` iteratee shorthand. 14 | console.log(_.sortedIndexBy(objects, { 'x': 4 }, 'x')); 15 | // => 0 -------------------------------------------------------------------------------- /02-Lodash/examples/array/39_sortedindexof.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sortedIndexOf example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.sortedIndexOf([4, 5, 5, 5, 6], 5)); 9 | // => 1 -------------------------------------------------------------------------------- /02-Lodash/examples/array/40_sortedlastindex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sortedLastIndex example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.sortedLastIndex([4, 5, 5, 5, 6], 5)); 9 | // => 4 -------------------------------------------------------------------------------- /02-Lodash/examples/array/41_sortedlastindexby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sortedLastIndexBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'x': 4 }, { 'x': 5 }]; 9 | 10 | console.log(_.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; })); 11 | // => 1 12 | 13 | // The `_.property` iteratee shorthand. 14 | console.log(_.sortedLastIndexBy(objects, { 'x': 4 }, 'x')); 15 | // => 1 -------------------------------------------------------------------------------- /02-Lodash/examples/array/42_sortedlastindexof.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sortedLastIndexOf example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.sortedLastIndexOf([4, 5, 5, 5, 6], 5)); 9 | // => 3 -------------------------------------------------------------------------------- /02-Lodash/examples/array/43_sorteduniq.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sortedUniq example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.sortedUniq([1, 1, 2])); 9 | // => [1, 2] -------------------------------------------------------------------------------- /02-Lodash/examples/array/44_sorteduniqby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sortedUniqBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor)); 9 | // => [1.1, 2.3] -------------------------------------------------------------------------------- /02-Lodash/examples/array/45_tail.js: -------------------------------------------------------------------------------- 1 | /** 2 | * tail example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.tail([1, 2, 3])); 9 | // => [2, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/array/46_take.js: -------------------------------------------------------------------------------- 1 | /** 2 | * take example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.take([1, 2, 3])); 9 | // => [1] 10 | 11 | console.log(_.take([1, 2, 3], 2)); 12 | // => [1, 2] 13 | 14 | console.log(_.take([1, 2, 3], 5)); 15 | // => [1, 2, 3] 16 | 17 | console.log(_.take([1, 2, 3], 0)); 18 | // => [] -------------------------------------------------------------------------------- /02-Lodash/examples/array/47_takeright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * takeRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.takeRight([1, 2, 3])); 9 | // => [3] 10 | 11 | console.log(_.takeRight([1, 2, 3], 2)); 12 | // => [2, 3] 13 | 14 | console.log(_.takeRight([1, 2, 3], 5)); 15 | // => [1, 2, 3] 16 | 17 | console.log(_.takeRight([1, 2, 3], 0)); 18 | // => [] -------------------------------------------------------------------------------- /02-Lodash/examples/array/48_takerightwhile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * takeRightWhile example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'active': true }, 10 | { 'user': 'fred', 'active': false }, 11 | { 'user': 'pebbles', 'active': false } 12 | ]; 13 | 14 | console.log(_.takeRightWhile(users, function(o) { return !o.active; })); 15 | // => objects for ['fred', 'pebbles'] 16 | 17 | // The `_.matches` iteratee shorthand. 18 | console.log(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false })); 19 | // => objects for ['pebbles'] 20 | 21 | // The `_.matchesProperty` iteratee shorthand. 22 | console.log(_.takeRightWhile(users, ['active', false])); 23 | // => objects for ['fred', 'pebbles'] 24 | 25 | // The `_.property` iteratee shorthand. 26 | console.log(_.takeRightWhile(users, 'active')); 27 | // => [] -------------------------------------------------------------------------------- /02-Lodash/examples/array/49_takewhile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * takeWhile example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'active': false }, 10 | { 'user': 'fred', 'active': false }, 11 | { 'user': 'pebbles', 'active': true } 12 | ]; 13 | 14 | console.log(_.takeWhile(users, function(o) { return !o.active; })); 15 | // => objects for ['barney', 'fred'] 16 | 17 | // The `_.matches` iteratee shorthand. 18 | console.log(_.takeWhile(users, { 'user': 'barney', 'active': false })); 19 | // => objects for ['barney'] 20 | 21 | // The `_.matchesProperty` iteratee shorthand. 22 | console.log(_.takeWhile(users, ['active', false])); 23 | // => objects for ['barney', 'fred'] 24 | 25 | // The `_.property` iteratee shorthand. 26 | console.log(_.takeWhile(users, 'active')); 27 | // => [] -------------------------------------------------------------------------------- /02-Lodash/examples/array/50_union.js: -------------------------------------------------------------------------------- 1 | /** 2 | * union example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.union([2], [1, 2])); 9 | // => [2, 1] -------------------------------------------------------------------------------- /02-Lodash/examples/array/51_unionby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * unionBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.unionBy([2.1], [1.2, 2.3], Math.floor)); 9 | // => [2.1, 1.2] 10 | 11 | // The `_.property` iteratee shorthand. 12 | console.log(_.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x')); 13 | // => [{ 'x': 1 }, { 'x': 2 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/52_unionwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * unionBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.unionBy([2.1], [1.2, 2.3], Math.floor)); 9 | // => [2.1, 1.2] 10 | 11 | // The `_.property` iteratee shorthand. 12 | console.log(_.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x')); 13 | // => [{ 'x': 1 }, { 'x': 2 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/53_uniq.js: -------------------------------------------------------------------------------- 1 | /** 2 | * unionBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.unionBy([2.1], [1.2, 2.3], Math.floor)); 9 | // => [2.1, 1.2] 10 | 11 | // The `_.property` iteratee shorthand. 12 | console.log(_.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x')); 13 | // => [{ 'x': 1 }, { 'x': 2 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/54_uniqby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * unionBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.unionBy([2.1], [1.2, 2.3], Math.floor)); 9 | // => [2.1, 1.2] 10 | 11 | // The `_.property` iteratee shorthand. 12 | console.log(_.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x')); 13 | // => [{ 'x': 1 }, { 'x': 2 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/55_uniqwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * unionWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 9 | var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; 10 | 11 | console.log(_.unionWith(objects, others, _.isEqual)); 12 | // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/56_unzip.js: -------------------------------------------------------------------------------- 1 | /** 2 | * unzip example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var zipped = _.zip(['a', 'b'], [1, 2], [true, false]); 9 | console.log(zipped); 10 | // => [['a', 1, true], ['b', 2, false]] 11 | 12 | console.log(_.unzip(zipped)); 13 | // => [['a', 'b'], [1, 2], [true, false]] -------------------------------------------------------------------------------- /02-Lodash/examples/array/57_unzipwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * unzipWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var zipped = _.zip([1, 2], [10, 20], [100, 200]); 9 | // => [[1, 10, 100], [2, 20, 200]] 10 | 11 | console.log(_.unzipWith(zipped, _.add)); 12 | // => [3, 30, 300] -------------------------------------------------------------------------------- /02-Lodash/examples/array/58_without.js: -------------------------------------------------------------------------------- 1 | /** 2 | * without example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.without([2, 1, 2, 3], 1, 2)); 9 | // => [3] -------------------------------------------------------------------------------- /02-Lodash/examples/array/59_xor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * xor example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.xor([2, 1], [2, 3])); 9 | // => [1, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/array/60_xorby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * xorBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor)); 9 | // => [1.2, 3.4] 10 | 11 | // The `_.property` iteratee shorthand. 12 | console.log(_.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x')); 13 | // => [{ 'x': 2 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/61_xorwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * xorWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 9 | var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; 10 | 11 | console.log(_.xorWith(objects, others, _.isEqual)); 12 | // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] -------------------------------------------------------------------------------- /02-Lodash/examples/array/62_zip.js: -------------------------------------------------------------------------------- 1 | /** 2 | * zip example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.zip(['a', 'b'], [1, 2], [true, false])); 9 | // => [['a', 1, true], ['b', 2, false]] -------------------------------------------------------------------------------- /02-Lodash/examples/array/63_zipobject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * zipObject example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.zipObject(['a', 'b'], [1, 2])); 9 | // => { 'a': 1, 'b': 2 } -------------------------------------------------------------------------------- /02-Lodash/examples/array/64_zipobjectdeep.js: -------------------------------------------------------------------------------- 1 | /** 2 | * zipObjectDeep example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2])); 9 | // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } } -------------------------------------------------------------------------------- /02-Lodash/examples/array/65_zipwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * zipWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) { 9 | return a + b + c; 10 | })); 11 | // => [111, 222] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/01_countby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CamelCase example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.countBy([6.1, 4.2, 6.3], Math.floor)); 9 | // => { '4': 1, '6': 2 } 10 | 11 | // The `_.property` iteratee shorthand. 12 | console.log(_.countBy(['one', 'two', 'three'], 'length')); 13 | // => { '3': 2, '5': 1 } -------------------------------------------------------------------------------- /02-Lodash/examples/collection/02_each.js: -------------------------------------------------------------------------------- 1 | /** 2 | * forEach example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | _.forEach([1, 2], function(value) { 9 | console.log(value); 10 | }); 11 | // => Logs `1` then `2`. 12 | 13 | _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { 14 | console.log(key); 15 | }); 16 | // => Logs 'a' then 'b' (iteration order is not guaranteed). -------------------------------------------------------------------------------- /02-Lodash/examples/collection/03_eachright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * forEachRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | _.forEachRight([1, 2], function(value) { 9 | console.log(value); 10 | }); 11 | // => Logs `2` then `1`. -------------------------------------------------------------------------------- /02-Lodash/examples/collection/04_every.js: -------------------------------------------------------------------------------- 1 | /** 2 | * every example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.every([true, 1, null, 'yes'], Boolean)); 9 | // => false 10 | 11 | var users = [ 12 | { 'user': 'barney', 'age': 36, 'active': false }, 13 | { 'user': 'fred', 'age': 40, 'active': false } 14 | ]; 15 | 16 | // The `_.matches` iteratee shorthand. 17 | console.log(_.every(users, { 'user': 'barney', 'active': false })); 18 | // => false 19 | 20 | // The `_.matchesProperty` iteratee shorthand. 21 | console.log(_.every(users, ['active', false])); 22 | // => true 23 | 24 | // The `_.property` iteratee shorthand. 25 | console.log(_.every(users, 'active')); 26 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/collection/05_filter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * filter example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'age': 36, 'active': true }, 10 | { 'user': 'fred', 'age': 40, 'active': false } 11 | ]; 12 | 13 | console.log(_.filter(users, function(o) { return !o.active; })); 14 | // => objects for ['fred'] 15 | 16 | // The `_.matches` iteratee shorthand. 17 | console.log(_.filter(users, { 'age': 36, 'active': true })); 18 | // => objects for ['barney'] 19 | 20 | // The `_.matchesProperty` iteratee shorthand. 21 | console.log(_.filter(users, ['active', false])); 22 | // => objects for ['fred'] 23 | 24 | // The `_.property` iteratee shorthand. 25 | console.log(_.filter(users, 'active')); 26 | // => objects for ['barney'] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/06_find.js: -------------------------------------------------------------------------------- 1 | /** 2 | * find example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'age': 36, 'active': true }, 10 | { 'user': 'fred', 'age': 40, 'active': false }, 11 | { 'user': 'pebbles', 'age': 1, 'active': true } 12 | ]; 13 | 14 | console.log(_.find(users, function(o) { return o.age < 40; })); 15 | // => object for 'barney' 16 | 17 | // The `_.matches` iteratee shorthand. 18 | console.log(_.find(users, { 'age': 1, 'active': true })); 19 | // => object for 'pebbles' 20 | 21 | // The `_.matchesProperty` iteratee shorthand. 22 | console.log(_.find(users, ['active', false])); 23 | // => object for 'fred' 24 | 25 | // The `_.property` iteratee shorthand. 26 | console.log(_.find(users, 'active')); 27 | // => object for 'barney' -------------------------------------------------------------------------------- /02-Lodash/examples/collection/07_findlast.js: -------------------------------------------------------------------------------- 1 | /** 2 | * findLast example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.findLast([1, 2, 3, 4], function(n) { 9 | return n % 2 == 1; 10 | })); 11 | // => 3 -------------------------------------------------------------------------------- /02-Lodash/examples/collection/08_flatmap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * flatMap example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function duplicate(n) { 9 | return [n, n]; 10 | } 11 | 12 | console.log(_.flatMap([1, 2], duplicate)); 13 | // => [1, 1, 2, 2] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/09_flatmapdeep.js: -------------------------------------------------------------------------------- 1 | /** 2 | * flatMapDeep example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function duplicate(n) { 9 | return [[[n, n]]]; 10 | } 11 | 12 | console.log(_.flatMapDeep([1, 2], duplicate)); 13 | // => [1, 1, 2, 2] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/10_flatmapdepth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * flatMapDepth example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function duplicate(n) { 9 | return [[[n, n]]]; 10 | } 11 | 12 | console.log(_.flatMapDepth([1, 2], duplicate, 2)); 13 | // => [[1, 1], [2, 2]] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/11_foreach.js: -------------------------------------------------------------------------------- 1 | /** 2 | * forEach example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | _.forEach([1, 2], function(value) { 9 | console.log(value); 10 | }); 11 | // => Logs `1` then `2`. 12 | 13 | _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { 14 | console.log(key); 15 | }); 16 | // => Logs 'a' then 'b' (iteration order is not guaranteed). -------------------------------------------------------------------------------- /02-Lodash/examples/collection/12_foreachright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * forEachRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | _.forEachRight([1, 2], function(value) { 9 | console.log(value); 10 | }); 11 | // => Logs `2` then `1`. -------------------------------------------------------------------------------- /02-Lodash/examples/collection/13_groupby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * groupBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.groupBy([6.1, 4.2, 6.3], Math.floor)); 9 | // => { '4': [4.2], '6': [6.1, 6.3] } 10 | 11 | // The `_.property` iteratee shorthand. 12 | console.log(_.groupBy(['one', 'two', 'three'], 'length')); 13 | // => { '3': ['one', 'two'], '5': ['three'] } -------------------------------------------------------------------------------- /02-Lodash/examples/collection/14_includes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * includes example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.includes([1, 2, 3], 1)); 9 | // => true 10 | 11 | console.log(_.includes([1, 2, 3], 1, 2)); 12 | // => false 13 | 14 | console.log(_.includes({ 'a': 1, 'b': 2 }, 1)); 15 | // => true 16 | 17 | console.log(_.includes('abcd', 'bc')); 18 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/collection/15_invokemap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * invokeMap example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort')); 9 | // => [[1, 5, 7], [1, 2, 3]] 10 | 11 | console.log(_.invokeMap([123, 456], String.prototype.split, '')); 12 | // => [['1', '2', '3'], ['4', '5', '6']] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/16_keyby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * keyBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [ 9 | { 'dir': 'left', 'code': 97 }, 10 | { 'dir': 'right', 'code': 100 } 11 | ]; 12 | 13 | console.log(_.keyBy(array, function(o) { 14 | return String.fromCharCode(o.code); 15 | })); 16 | // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } 17 | 18 | console.log(_.keyBy(array, 'dir')); 19 | // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } -------------------------------------------------------------------------------- /02-Lodash/examples/collection/17_map.js: -------------------------------------------------------------------------------- 1 | /** 2 | * map example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function square(n) { 9 | return n * n; 10 | } 11 | 12 | console.log(_.map([4, 8], square)); 13 | // => [16, 64] 14 | 15 | console.log(_.map({ 'a': 4, 'b': 8 }, square)); 16 | // => [16, 64] (iteration order is not guaranteed) 17 | 18 | var users = [ 19 | { 'user': 'barney' }, 20 | { 'user': 'fred' } 21 | ]; 22 | 23 | // The `_.property` iteratee shorthand. 24 | console.log(_.map(users, 'user')); 25 | // => ['barney', 'fred'] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/18_orderby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * orderBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'fred', 'age': 48 }, 10 | { 'user': 'barney', 'age': 34 }, 11 | { 'user': 'fred', 'age': 40 }, 12 | { 'user': 'barney', 'age': 36 } 13 | ]; 14 | 15 | // Sort by `user` in ascending order and by `age` in descending order. 16 | console.log(_.orderBy(users, ['user', 'age'], ['asc', 'desc'])); 17 | // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/19_partition.js: -------------------------------------------------------------------------------- 1 | /** 2 | * partition example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'age': 36, 'active': false }, 10 | { 'user': 'fred', 'age': 40, 'active': true }, 11 | { 'user': 'pebbles', 'age': 1, 'active': false } 12 | ]; 13 | 14 | console.log(_.partition(users, function(o) { return o.active; })); 15 | // => objects for [['fred'], ['barney', 'pebbles']] 16 | 17 | // The `_.matches` iteratee shorthand. 18 | console.log(_.partition(users, { 'age': 1, 'active': false })); 19 | // => objects for [['pebbles'], ['barney', 'fred']] 20 | 21 | // The `_.matchesProperty` iteratee shorthand. 22 | console.log(_.partition(users, ['active', false])); 23 | // => objects for [['barney', 'pebbles'], ['fred']] 24 | 25 | // The `_.property` iteratee shorthand. 26 | console.log(_.partition(users, 'active')); 27 | // => objects for [['fred'], ['barney', 'pebbles']] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/20_reduce.js: -------------------------------------------------------------------------------- 1 | /** 2 | * reduce example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.reduce([1, 2], function(sum, n) { 9 | return sum + n; 10 | }, 0)); 11 | // => 3 12 | 13 | console.log(_.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { 14 | (result[value] || (result[value] = [])).push(key); 15 | return result; 16 | }, {})); 17 | // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) -------------------------------------------------------------------------------- /02-Lodash/examples/collection/21_reduceright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * reduceRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [[0, 1], [2, 3], [4, 5]]; 9 | 10 | console.log(_.reduceRight(array, function(flattened, other) { 11 | return flattened.concat(other); 12 | }, [])); 13 | // => [4, 5, 2, 3, 0, 1] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/22_reject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * reject example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'age': 36, 'active': false }, 10 | { 'user': 'fred', 'age': 40, 'active': true } 11 | ]; 12 | 13 | console.log(_.reject(users, function(o) { return !o.active; })); 14 | // => objects for ['fred'] 15 | 16 | // The `_.matches` iteratee shorthand. 17 | console.log(_.reject(users, { 'age': 40, 'active': true })); 18 | // => objects for ['barney'] 19 | 20 | // The `_.matchesProperty` iteratee shorthand. 21 | console.log(_.reject(users, ['active', false])); 22 | // => objects for ['fred'] 23 | 24 | // The `_.property` iteratee shorthand. 25 | console.log(_.reject(users, 'active')); 26 | // => objects for ['barney'] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/23_sample.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sample example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.sample([1, 2, 3, 4])); 9 | // => 2 -------------------------------------------------------------------------------- /02-Lodash/examples/collection/24_samplesize.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sampleSize example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.sampleSize([1, 2, 3], 2)); 9 | // => [3, 1] 10 | 11 | console.log(_.sampleSize([1, 2, 3], 4)); 12 | // => [2, 3, 1] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/25_shuffle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * shuffle example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.shuffle([1, 2, 3, 4])); 9 | // => [4, 1, 3, 2] -------------------------------------------------------------------------------- /02-Lodash/examples/collection/26_size.js: -------------------------------------------------------------------------------- 1 | /** 2 | * size example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.size([1, 2, 3])); 9 | // => 3 10 | 11 | console.log(_.size({ 'a': 1, 'b': 2 })); 12 | // => 2 13 | 14 | console.log(_.size('pebbles')); 15 | // => 7 16 | -------------------------------------------------------------------------------- /02-Lodash/examples/collection/27_some.js: -------------------------------------------------------------------------------- 1 | /** 2 | * some example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.some([null, 0, 'yes', false], Boolean)); 9 | // => true 10 | 11 | var users = [ 12 | { 'user': 'barney', 'active': true }, 13 | { 'user': 'fred', 'active': false } 14 | ]; 15 | 16 | // The `_.matches` iteratee shorthand. 17 | console.log(_.some(users, { 'user': 'barney', 'active': false })); 18 | // => false 19 | 20 | // The `_.matchesProperty` iteratee shorthand. 21 | console.log(_.some(users, ['active', false])); 22 | // => true 23 | 24 | // The `_.property` iteratee shorthand. 25 | console.log(_.some(users, 'active')); 26 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/collection/28_sortby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sortBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'fred', 'age': 48 }, 10 | { 'user': 'barney', 'age': 36 }, 11 | { 'user': 'fred', 'age': 40 }, 12 | { 'user': 'barney', 'age': 34 } 13 | ]; 14 | 15 | console.log(_.sortBy(users, [function(o) { return o.user; }])); 16 | // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] 17 | 18 | console.log(_.sortBy(users, ['user', 'age'])); 19 | // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]] -------------------------------------------------------------------------------- /02-Lodash/examples/date/01_now.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Now example 4 | */ 5 | 6 | 'use strict'; 7 | var _ = require('../../node_modules/lodash'); 8 | 9 | _.defer(function(stamp) { 10 | console.log(_.now() - stamp); 11 | }, _.now()); 12 | // => Logs the number of milliseconds it took for the deferred invocation. -------------------------------------------------------------------------------- /02-Lodash/examples/function/01_after.js: -------------------------------------------------------------------------------- 1 | /** 2 | * after example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var saves = ['profile', 'settings']; 9 | 10 | var done = _.after(saves.length, function() { 11 | console.log('done saving!'); 12 | }); 13 | 14 | console.log(_.forEach(saves, function(type) { 15 | asyncSave({ 'type': type, 'complete': done }); 16 | })); 17 | // => Logs 'done saving!' after the two async saves have completed. 18 | -------------------------------------------------------------------------------- /02-Lodash/examples/function/02_ary.js: -------------------------------------------------------------------------------- 1 | /** 2 | * ary example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.map(['6', '8', '10'], _.ary(parseInt, 1))); 9 | // => [6, 8, 10] -------------------------------------------------------------------------------- /02-Lodash/examples/function/03_before.js: -------------------------------------------------------------------------------- 1 | /** 2 | * before example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | jQuery(element).on('click', _.before(5, addContactToList)); 9 | // => Allows adding up to 4 contacts to the list. -------------------------------------------------------------------------------- /02-Lodash/examples/function/04_bind.js: -------------------------------------------------------------------------------- 1 | /** 2 | * bind example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function greet(greeting, punctuation) { 9 | return greeting + ' ' + this.user + punctuation; 10 | } 11 | 12 | var object = { 'user': 'fred' }; 13 | 14 | var bound1 = _.bind(greet, object, 'hi'); 15 | console.log(bound1('!')); 16 | // => 'hi fred!' 17 | 18 | // Bound with placeholders. 19 | var bound2 = _.bind(greet, object, _, '!'); 20 | console.log(bound2('hi')); 21 | // => 'hi fred!' -------------------------------------------------------------------------------- /02-Lodash/examples/function/05_bindkey.js: -------------------------------------------------------------------------------- 1 | /** 2 | * bindKey example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 9 | 'user': 'fred', 10 | 'greet': function(greeting, punctuation) { 11 | return greeting + ' ' + this.user + punctuation; 12 | } 13 | }; 14 | 15 | var bound1 = _.bindKey(object, 'greet', 'hi'); 16 | console.log(bound1('!')); 17 | // => 'hi fred!' 18 | 19 | object.greet = function(greeting, punctuation) { 20 | return greeting + 'ya ' + this.user + punctuation; 21 | }; 22 | 23 | console.log(bound1('!')); 24 | // => 'hiya fred!' 25 | 26 | // Bound with placeholders. 27 | var bound2 = _.bindKey(object, 'greet', _, '!'); 28 | console.log(bound2('hi')); 29 | // => 'hiya fred!' -------------------------------------------------------------------------------- /02-Lodash/examples/function/06_curry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * curry example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var abc = function(a, b, c) { 9 | return [a, b, c]; 10 | }; 11 | 12 | var curried = _.curry(abc); 13 | 14 | console.log(curried(1)(2)(3)); 15 | // => [1, 2, 3] 16 | 17 | console.log(curried(1, 2)(3)); 18 | // => [1, 2, 3] 19 | 20 | console.log(curried(1, 2, 3)); 21 | // => [1, 2, 3] 22 | 23 | // Curried with placeholders. 24 | console.log(curried(1)(_, 3)(2)); 25 | // => [1, 2, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/function/07_curryright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * curryRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var abc = function(a, b, c) { 9 | return [a, b, c]; 10 | }; 11 | 12 | var curried = _.curryRight(abc); 13 | 14 | console.log(curried(3)(2)(1)); 15 | // => [1, 2, 3] 16 | 17 | console.log(curried(2, 3)(1)); 18 | // => [1, 2, 3] 19 | 20 | console.log(curried(1, 2, 3)); 21 | // => [1, 2, 3] 22 | 23 | // Curried with placeholders. 24 | console.log(curried(3)(1, _)(2)); 25 | // => [1, 2, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/function/08_debounce.js: -------------------------------------------------------------------------------- 1 | /** 2 | * debounce example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | // Avoid costly calculations while the window size is in flux. 9 | jQuery(window).on('resize', _.debounce(calculateLayout, 150)); 10 | 11 | // Invoke `sendMail` when clicked, debouncing subsequent calls. 12 | jQuery(element).on('click', _.debounce(sendMail, 300, { 13 | 'leading': true, 14 | 'trailing': false 15 | })); 16 | 17 | // Ensure `batchLog` is invoked once after 1 second of debounced calls. 18 | var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); 19 | var source = new EventSource('/stream'); 20 | jQuery(source).on('message', debounced); 21 | 22 | // Cancel the trailing debounced invocation. 23 | jQuery(window).on('popstate', debounced.cancel); -------------------------------------------------------------------------------- /02-Lodash/examples/function/09_defer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * defer example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | _.defer(function(text) { 9 | console.log(text); 10 | }, 'deferred'); 11 | // => Logs 'deferred' after one millisecond. -------------------------------------------------------------------------------- /02-Lodash/examples/function/10_delay.js: -------------------------------------------------------------------------------- 1 | /** 2 | * delay example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | _.delay(function(text) { 9 | console.log(text); 10 | }, 1000, 'later'); 11 | // => Logs 'later' after one second. -------------------------------------------------------------------------------- /02-Lodash/examples/function/11_flip.js: -------------------------------------------------------------------------------- 1 | /** 2 | * flip example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var flipped = _.flip(function() { 9 | return _.toArray(arguments); 10 | }); 11 | 12 | console.log(flipped('a', 'b', 'c', 'd')); 13 | // => ['d', 'c', 'b', 'a'] -------------------------------------------------------------------------------- /02-Lodash/examples/function/12_memoize.js: -------------------------------------------------------------------------------- 1 | /** 2 | * memoize example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1, 'b': 2 }; 9 | var other = { 'c': 3, 'd': 4 }; 10 | 11 | var values = _.memoize(_.values); 12 | console.log(values(object)); 13 | // => [1, 2] 14 | 15 | console.log(values(other)); 16 | // => [3, 4] 17 | 18 | object.a = 2; 19 | console.log(values(object)); 20 | // => [1, 2] 21 | 22 | // Modify the result cache. 23 | values.cache.set(object, ['a', 'b']); 24 | console.log(values(object)); 25 | // => ['a', 'b'] 26 | 27 | // Replace `_.memoize.Cache`. 28 | _.memoize.Cache = WeakMap; -------------------------------------------------------------------------------- /02-Lodash/examples/function/13_negate.js: -------------------------------------------------------------------------------- 1 | /** 2 | * negate example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function isEven(n) { 9 | return n % 2 == 0; 10 | } 11 | 12 | console.log(_.filter([1, 2, 3, 4, 5, 6], _.negate(isEven))); 13 | // => [1, 3, 5] -------------------------------------------------------------------------------- /02-Lodash/examples/function/14_once.js: -------------------------------------------------------------------------------- 1 | /** 2 | * once example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function createApplication() { 9 | console.log("createApplication"); 10 | } 11 | 12 | var initialize = _.once(createApplication); 13 | initialize(); 14 | initialize(); 15 | // => `createApplication` is invoked once -------------------------------------------------------------------------------- /02-Lodash/examples/function/15_overargs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * overArgs example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function doubled(n) { 9 | return n * 2; 10 | } 11 | 12 | function square(n) { 13 | return n * n; 14 | } 15 | 16 | var func = _.overArgs(function(x, y) { 17 | return [x, y]; 18 | }, [square, doubled]); 19 | 20 | console.log(func(9, 3)); 21 | // => [81, 6] 22 | 23 | console.log(func(10, 5)); 24 | // => [100, 10] -------------------------------------------------------------------------------- /02-Lodash/examples/function/16_partial.js: -------------------------------------------------------------------------------- 1 | /** 2 | * partial example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function greet(greeting, name) { 9 | return greeting + ' ' + name; 10 | } 11 | 12 | var sayHelloTo = _.partial(greet, 'hello'); 13 | console.log(sayHelloTo('fred')); 14 | // => 'hello fred' 15 | 16 | // Partially applied with placeholders. 17 | var greetFred = _.partial(greet, _, 'fred'); 18 | console.log(greetFred('hi')); 19 | // => 'hi fred' -------------------------------------------------------------------------------- /02-Lodash/examples/function/17_partialright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * partialRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function greet(greeting, name) { 9 | return greeting + ' ' + name; 10 | } 11 | 12 | var greetFred = _.partialRight(greet, 'fred'); 13 | console.log(greetFred('hi')); 14 | // => 'hi fred' 15 | 16 | // Partially applied with placeholders. 17 | var sayHelloTo = _.partialRight(greet, 'hello', _); 18 | console.log(sayHelloTo('fred')); 19 | // => 'hello fred' -------------------------------------------------------------------------------- /02-Lodash/examples/function/18_rearg.js: -------------------------------------------------------------------------------- 1 | /** 2 | * rearg example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var rearged = _.rearg(function(a, b, c) { 9 | return [a, b, c]; 10 | }, [2, 0, 1]); 11 | 12 | console.log(rearged('b', 'c', 'a')); 13 | // => ['a', 'b', 'c'] -------------------------------------------------------------------------------- /02-Lodash/examples/function/19_rest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * rest example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var say = _.rest(function(what, names) { 9 | return what + ' ' + _.initial(names).join(', ') + 10 | (_.size(names) > 1 ? ', & ' : '') + _.last(names); 11 | }); 12 | 13 | console.log(say('hello', 'fred', 'barney', 'pebbles')); 14 | // => 'hello fred, barney, & pebbles' -------------------------------------------------------------------------------- /02-Lodash/examples/function/20_spread.js: -------------------------------------------------------------------------------- 1 | /** 2 | * spread example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var say = _.spread(function(who, what) { 9 | return who + ' says ' + what; 10 | }); 11 | 12 | console.log(say(['fred', 'hello']); 13 | // => 'fred says hello' 14 | 15 | var numbers = Promise.all([ 16 | Promise.resolve(40), 17 | Promise.resolve(36) 18 | ]); 19 | 20 | console.log(numbers.then(_.spread(function(x, y) { 21 | return x + y; 22 | }))); 23 | // => a Promise of 76 -------------------------------------------------------------------------------- /02-Lodash/examples/function/21_throttle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * throttle example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | // Avoid excessively updating the position while scrolling. 9 | jQuery(window).on('scroll', _.throttle(updatePosition, 100)); 10 | 11 | // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. 12 | var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); 13 | jQuery(element).on('click', throttled); 14 | 15 | // Cancel the trailing throttled invocation. 16 | jQuery(window).on('popstate', throttled.cancel); -------------------------------------------------------------------------------- /02-Lodash/examples/function/22_unary.js: -------------------------------------------------------------------------------- 1 | /** 2 | * unary example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.map(['6', '8', '10'], _.unary(parseInt))); 9 | // => [6, 8, 10] -------------------------------------------------------------------------------- /02-Lodash/examples/function/23_wrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * wrap example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var p = _.wrap(_.escape, function(func, text) { 9 | return '

' + func(text) + '

'; 10 | }); 11 | 12 | console.log(p('fred, barney, & pebbles')); 13 | // => '

fred, barney, & pebbles

' -------------------------------------------------------------------------------- /02-Lodash/examples/lang/01_castarray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * castArray example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.castArray(1)); 9 | // => [1] 10 | 11 | console.log(_.castArray({ 'a': 1 })); 12 | // => [{ 'a': 1 }] 13 | 14 | console.log(_.castArray('abc')); 15 | // => ['abc'] 16 | 17 | console.log(_.castArray(null)); 18 | // => [null] 19 | 20 | console.log(_.castArray(undefined)); 21 | // => [undefined] 22 | 23 | console.log(_.castArray()); 24 | // => [] 25 | 26 | var array = [1, 2, 3]; 27 | console.log(_.castArray(array) === array); 28 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/lang/02_clone.js: -------------------------------------------------------------------------------- 1 | /** 2 | * clone example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'a': 1 }, { 'b': 2 }]; 9 | 10 | var shallow = _.clone(objects); 11 | console.log(shallow); 12 | console.log(shallow[0] === objects[0]); 13 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/lang/03_clonedeep.js: -------------------------------------------------------------------------------- 1 | /** 2 | * cloneDeep example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'a': 1 }, { 'b': 2 }]; 9 | 10 | var deep = _.cloneDeep(objects); 11 | console.log(deep); 12 | console.log(deep[0] === objects[0]); 13 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/04_clonedeepwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * cloneDeepWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function customizer(value) { 9 | if (_.isElement(value)) { 10 | return value.cloneNode(true); 11 | } 12 | } 13 | 14 | var el = _.cloneDeepWith(document.body, customizer); 15 | 16 | console.log(el === document.body); 17 | // => false 18 | console.log(el.nodeName); 19 | // => 'BODY' 20 | console.log(el.childNodes.length); 21 | // => 20 -------------------------------------------------------------------------------- /02-Lodash/examples/lang/05_clonewith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * cloneWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function customizer(value) { 9 | if (_.isElement(value)) { 10 | return value.cloneNode(false); 11 | } 12 | } 13 | 14 | var el = _.cloneWith(document.body, customizer); 15 | 16 | console.log(el === document.body); 17 | // => false 18 | console.log(el.nodeName); 19 | // => 'BODY' 20 | console.log(el.childNodes.length); 21 | // => 0 22 | Try in REPL 23 | -------------------------------------------------------------------------------- /02-Lodash/examples/lang/06_confirmsto.js: -------------------------------------------------------------------------------- 1 | /** 2 | * conformsTo example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1, 'b': 2 }; 9 | 10 | console.log(_.conformsTo(object, { 'b': function(n) { return n > 1; } })); 11 | // => true 12 | 13 | console.log(_.conformsTo(object, { 'b': function(n) { return n > 2; } })); 14 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/07_eq.js: -------------------------------------------------------------------------------- 1 | /** 2 | * eq example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.mean([1, 3, 5, 7])); 9 | // => 4 10 | 11 | var object = { 'a': 1 }; 12 | var other = { 'a': 1 }; 13 | 14 | console.log(_.eq(object, object)); 15 | // => true 16 | 17 | console.log(_.eq(object, other)); 18 | // => false 19 | 20 | console.log(_.eq('a', 'a')); 21 | // => true 22 | 23 | console.log(_.eq('a', Object('a'))); 24 | // => false 25 | 26 | console.log(_.eq(NaN, NaN)); 27 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/lang/08_gt.js: -------------------------------------------------------------------------------- 1 | /** 2 | * gt example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.gt(3, 1)); 9 | // => true 10 | 11 | console.log(_.gt(3, 3)); 12 | // => false 13 | 14 | console.log(_.gt(1, 3)); 15 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/09_gte.js: -------------------------------------------------------------------------------- 1 | /** 2 | * gte example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.gte(3, 1)); 9 | // => true 10 | 11 | console.log(_.gte(3, 3)); 12 | // => true 13 | 14 | console.log(_.gte(1, 3)); 15 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/10_isarguments.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isArguments example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isArguments(function() { return arguments; }())); 9 | // => true 10 | 11 | console.log(_.isArguments([1, 2, 3])); 12 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/11_isarray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isArray example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isArray([1, 2, 3])); 9 | // => true 10 | 11 | console.log(_.isArray(document.body.children)); 12 | // => false 13 | 14 | console.log(_.isArray('abc')); 15 | // => false 16 | 17 | console.log(_.isArray(_.noop)); 18 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/12_isarraybuffer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isArrayBuffer example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isArrayBuffer(new ArrayBuffer(2))); 9 | // => true 10 | 11 | console.log(_.isArrayBuffer(new Array(2))); 12 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/13_isarraylike.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isArrayLike example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | 9 | console.log(_.isArrayLike([1, 2, 3])); 10 | // => true 11 | 12 | console.log(_.isArrayLike(document.body.children)); 13 | // => true 14 | 15 | console.log(_.isArrayLike('abc')); 16 | // => true 17 | 18 | console.log(_.isArrayLike(_.noop)); 19 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/14_isarraylikeobject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isArrayLikeObject example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isArrayLikeObject([1, 2, 3])); 9 | // => true 10 | 11 | console.log(_.isArrayLikeObject(document.body.children)); 12 | // => true 13 | 14 | console.log(_.isArrayLikeObject('abc')); 15 | // => false 16 | 17 | console.log(_.isArrayLikeObject(_.noop)); 18 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/15_isboolean.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isBoolean example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isBoolean(false)); 9 | // => true 10 | 11 | console.log(_.isBoolean(null)); 12 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/16_isbuffer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isBuffer example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isBuffer(new Buffer(2))); 9 | // => true 10 | 11 | console.log(_.isBuffer(new Uint8Array(2))); 12 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/17_isdate.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isDate example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isDate(new Date)); 9 | // => true 10 | 11 | console.log(_.isDate('Mon April 23 2012')); 12 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/18_iselement.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isElement example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isElement(document.body)); 9 | // => true 10 | 11 | console.log(_.isElement('')); 12 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/19_isempty.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isEmpty example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isEmpty(null)); 9 | // => true 10 | 11 | console.log(_.isEmpty(true)); 12 | // => true 13 | 14 | console.log(_.isEmpty(1)); 15 | // => true 16 | 17 | console.log(_.isEmpty([1, 2, 3])); 18 | // => false 19 | 20 | console.log(_.isEmpty({ 'a': 1 })); 21 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/20_isequal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isEqual example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1 }; 9 | var other = { 'a': 1 }; 10 | 11 | console.log(_.isEqual(object, other)); 12 | // => true 13 | 14 | console.log(object === other); 15 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/21_isequalwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isEqualWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function isGreeting(value) { 9 | return /^h(?:i|ello)$/.test(value); 10 | } 11 | 12 | function customizer(objValue, othValue) { 13 | if (isGreeting(objValue) && isGreeting(othValue)) { 14 | return true; 15 | } 16 | } 17 | 18 | var array = ['hello', 'goodbye']; 19 | var other = ['hi', 'goodbye']; 20 | 21 | console.log(_.isEqualWith(array, other, customizer)); 22 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/lang/22_iserror.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isError example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isError(new Error)); 9 | // => true 10 | 11 | console.log(_.isError(Error)); 12 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/23_isfinite.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isFinite example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isFinite(3)); 9 | // => true 10 | 11 | console.log(_.isFinite(Number.MIN_VALUE)); 12 | // => true 13 | 14 | console.log(_.isFinite(Infinity)); 15 | // => false 16 | 17 | console.log(_.isFinite('3')); 18 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/24_isfunction.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isFunction example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isFunction(_)); 9 | // => true 10 | 11 | console.log(_.isFunction(/abc/)); 12 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/25_islength.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isLength example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isLength(3)); 9 | // => true 10 | 11 | console.log(_.isLength(Number.MIN_VALUE)); 12 | // => false 13 | 14 | console.log(_.isLength(Infinity)); 15 | // => false 16 | 17 | console.log(_.isLength('3')); 18 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/26_isinteger.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isInteger example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isInteger(3)); 9 | // => true 10 | 11 | console.log(_.isInteger(Number.MIN_VALUE)); 12 | // => false 13 | 14 | console.log(_.isInteger(Infinity)); 15 | // => false 16 | 17 | console.log(_.isInteger('3')); 18 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/27_ismap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isMap example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isMap(new Map)); 9 | // => true 10 | 11 | console.log(_.isMap(new WeakMap)); 12 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/28_ismatch.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isMatch example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1, 'b': 2 }; 9 | 10 | console.log(_.isMatch(object, { 'b': 2 })); 11 | // => true 12 | 13 | console.log(_.isMatch(object, { 'b': 1 })); 14 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/29_ismatchwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isMatchWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function isGreeting(value) { 9 | return /^h(?:i|ello)$/.test(value); 10 | } 11 | 12 | function customizer(objValue, srcValue) { 13 | if (isGreeting(objValue) && isGreeting(srcValue)) { 14 | return true; 15 | } 16 | } 17 | 18 | var object = { 'greeting': 'hello' }; 19 | var source = { 'greeting': 'hi' }; 20 | 21 | console.log(_.isMatchWith(object, source, customizer)); 22 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/lang/30_isnan.js: -------------------------------------------------------------------------------- 1 | /** 2 | * isNaN example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.isNaN(NaN)); 9 | // => true 10 | 11 | console.log(_.isNaN(new Number(NaN))); 12 | // => true 13 | 14 | console.log(isNaN(undefined)); 15 | // => true 16 | 17 | console.log(_.isNaN(undefined)); 18 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/31_isnative.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * isNative example 4 | */ 5 | 6 | 'use strict'; 7 | var _ = require('../../node_modules/lodash'); 8 | 9 | console.log(_.isNative(Array.prototype.push)); 10 | // => true 11 | 12 | console.log(_.isNative(_)); 13 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/32_isnil.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * isNil example 4 | */ 5 | 6 | 'use strict'; 7 | var _ = require('../../node_modules/lodash'); 8 | 9 | 10 | console.log(_.isNil(null)); 11 | // => true 12 | 13 | console.log(_.isNil(void 0)); 14 | // => true 15 | 16 | console.log(_.isNil(NaN)); 17 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/33_isnull.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * isNull example 4 | */ 5 | 6 | 'use strict'; 7 | var _ = require('../../node_modules/lodash'); 8 | 9 | console.log(_.isNull(null)); 10 | // => true 11 | 12 | console.log(_.isNull(void 0)); 13 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/34_isnumber.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * isNumber example 4 | */ 5 | 6 | 'use strict'; 7 | var _ = require('../../node_modules/lodash'); 8 | 9 | console.log(_.isNumber(3)); 10 | // => true 11 | 12 | console.log(_.isNumber(Number.MIN_VALUE)); 13 | // => true 14 | 15 | console.log(_.isNumber(Infinity)); 16 | // => true 17 | 18 | console.log(_.isNumber('3')); 19 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/35_isobject.js: -------------------------------------------------------------------------------- 1 | /* isObject example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.isObject({})); 8 | // => true 9 | 10 | console.log(_.isObject([1, 2, 3])); 11 | // => true 12 | 13 | console.log(_.isObject(_.noop)); 14 | // => true 15 | 16 | console.log(_.isObject(null)); 17 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/36_isobjectlike.js: -------------------------------------------------------------------------------- 1 | /* isObjectLike example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | 8 | console.log(_.isObjectLike({})); 9 | // => true 10 | 11 | console.log(_.isObjectLike([1, 2, 3])); 12 | // => true 13 | 14 | console.log(_.isObjectLike(_.noop)); 15 | // => false 16 | 17 | console.log(_.isObjectLike(null)); 18 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/37_isplainobject.js: -------------------------------------------------------------------------------- 1 | /* isPlainObject example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | function Foo() { 8 | this.a = 1; 9 | } 10 | 11 | console.log(_.isPlainObject(new Foo)); 12 | // => false 13 | 14 | console.log(_.isPlainObject([1, 2, 3])); 15 | // => false 16 | 17 | console.log(_.isPlainObject({ 'x': 0, 'y': 0 })); 18 | // => true 19 | 20 | console.log(_.isPlainObject(Object.create(null))); 21 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/lang/38_isregexp.js: -------------------------------------------------------------------------------- 1 | /* isRegExp example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.isRegExp(/abc/)); 8 | // => true 9 | 10 | console.log(_.isRegExp('/abc/')); 11 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/39_issafeinteger.js: -------------------------------------------------------------------------------- 1 | /* isSafeInteger example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.isSafeInteger(3)); 8 | // => true 9 | 10 | console.log(_.isSafeInteger(Number.MIN_VALUE)); 11 | // => false 12 | 13 | console.log(_.isSafeInteger(Infinity)); 14 | // => false 15 | 16 | console.log(_.isSafeInteger('3')); 17 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/40_isset.js: -------------------------------------------------------------------------------- 1 | /* isSet example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.isSet(new Set)); 8 | // => true 9 | 10 | console.log(_.isSet(new WeakSet)); 11 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/41_isstring.js: -------------------------------------------------------------------------------- 1 | /* isString example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.isString('abc')); 8 | // => true 9 | 10 | console.log(_.isString(1)); 11 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/42_issymbol.js: -------------------------------------------------------------------------------- 1 | /* isSymbol example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.isSymbol(Symbol.iterator)); 8 | // => true 9 | 10 | console.log(_.isSymbol('abc')); 11 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/43_istypedarray.js: -------------------------------------------------------------------------------- 1 | /* isTypedArray example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.isTypedArray(new Uint8Array)); 8 | // => true 9 | 10 | console.log(_.isTypedArray([])); 11 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/44_isundefined.js: -------------------------------------------------------------------------------- 1 | /* isUndefined example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.isUndefined(void 0)); 8 | // => true 9 | 10 | console.log(_.isUndefined(null)); 11 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/45_isweakmap.js: -------------------------------------------------------------------------------- 1 | /* isWeakMap example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.isWeakMap(new WeakMap)); 8 | // => true 9 | 10 | console.log(_.isWeakMap(new Map)); 11 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/46_isweakset.js: -------------------------------------------------------------------------------- 1 | /* isWeakSet example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.isWeakSet(new WeakSet)); 8 | // => true 9 | 10 | console.log(_.isWeakSet(new Set)); 11 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/47_lt.js: -------------------------------------------------------------------------------- 1 | /* lt example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.lt(1, 3)); 8 | // => true 9 | 10 | console.log(_.lt(3, 3)); 11 | // => false 12 | 13 | console.log(_.lt(3, 1)); 14 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/48_lte.js: -------------------------------------------------------------------------------- 1 | /* lte example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.lte(1, 3)); 8 | // => true 9 | 10 | console.log(_.lte(3, 3)); 11 | // => true 12 | 13 | console.log(_.lte(3, 1)); 14 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/lang/49_toarray.js: -------------------------------------------------------------------------------- 1 | /* toArray example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.toArray({ 'a': 1, 'b': 2 })); 8 | // => [1, 2] 9 | 10 | console.log(_.toArray('abc')); 11 | // => ['a', 'b', 'c'] 12 | 13 | console.log(_.toArray(1)); 14 | // => [] 15 | 16 | console.log(_.toArray(null)); 17 | // => [] -------------------------------------------------------------------------------- /02-Lodash/examples/lang/50_tofinite.js: -------------------------------------------------------------------------------- 1 | /* toFinite example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.toFinite(3.2)); 8 | // => 3.2 9 | 10 | console.log(_.toFinite(Number.MIN_VALUE)); 11 | // => 5e-324 12 | 13 | console.log(_.toFinite(Infinity)); 14 | // => 1.7976931348623157e+308 15 | 16 | console.log(_.toFinite('3.2')); 17 | // => 3.2 -------------------------------------------------------------------------------- /02-Lodash/examples/lang/51_tointeger.js: -------------------------------------------------------------------------------- 1 | /* toInteger example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.toInteger(3.2)); 8 | // => 3 9 | 10 | console.log(_.toInteger(Number.MIN_VALUE)); 11 | // => 0 12 | 13 | console.log(_.toInteger(Infinity)); 14 | // => 1.7976931348623157e+308 15 | 16 | console.log(_.toInteger('3.2')); 17 | // => 3 -------------------------------------------------------------------------------- /02-Lodash/examples/lang/52_tolength.js: -------------------------------------------------------------------------------- 1 | /* toLength example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | 8 | console.log(_.toLength(3.2)); 9 | // => 3 10 | 11 | console.log(_.toLength(Number.MIN_VALUE)); 12 | // => 0 13 | 14 | console.log(_.toLength(Infinity)); 15 | // => 4294967295 16 | 17 | console.log(_.toLength('3.2')); 18 | // => 3 -------------------------------------------------------------------------------- /02-Lodash/examples/lang/53_tonumber.js: -------------------------------------------------------------------------------- 1 | /* toNumber example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.toNumber(3.2)); 8 | // => 3.2 9 | 10 | console.log(_.toNumber(Number.MIN_VALUE)); 11 | // => 5e-324 12 | 13 | console.log(_.toNumber(Infinity)); 14 | // => Infinity 15 | 16 | console.log(_.toNumber('3.2')); 17 | // => 3.2 -------------------------------------------------------------------------------- /02-Lodash/examples/lang/54_toplainobject.js: -------------------------------------------------------------------------------- 1 | /* toPlainObject example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | function Foo() { 8 | this.b = 2; 9 | } 10 | 11 | Foo.prototype.c = 3; 12 | 13 | console.log(_.assign({ 'a': 1 }, new Foo)); 14 | // => { 'a': 1, 'b': 2 } 15 | 16 | console.log(_.assign({ 'a': 1 }, _.toPlainObject(new Foo))); 17 | // => { 'a': 1, 'b': 2, 'c': 3 } -------------------------------------------------------------------------------- /02-Lodash/examples/lang/55_tosafeinteger.js: -------------------------------------------------------------------------------- 1 | /* toSafeInteger example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.toSafeInteger(3.2)); 8 | // => 3 9 | 10 | console.log(_.toSafeInteger(Number.MIN_VALUE)); 11 | // => 0 12 | 13 | console.log(_.toSafeInteger(Infinity)); 14 | // => 9007199254740991 15 | 16 | console.log(_.toSafeInteger('3.2')); 17 | // => 3 -------------------------------------------------------------------------------- /02-Lodash/examples/lang/56_tostring.js: -------------------------------------------------------------------------------- 1 | /* toString example 2 | */ 3 | 4 | 'use strict'; 5 | var _ = require('../../node_modules/lodash'); 6 | 7 | console.log(_.toString(null)); 8 | // => '' 9 | 10 | console.log(_.toString(-0)); 11 | // => '-0' 12 | 13 | console.log(_.toString([1, 2, 3])); 14 | // => '1,2,3' -------------------------------------------------------------------------------- /02-Lodash/examples/math/01_add.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Add example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.add(36, 46)); -------------------------------------------------------------------------------- /02-Lodash/examples/math/02_ceil.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Ceil example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.ceil(8.003)); 9 | // => 9 10 | 11 | console.log(_.ceil(2.00004, 3)); 12 | // => 2.001 13 | 14 | console.log(_.ceil(1235, -3)); 15 | // => 2000 -------------------------------------------------------------------------------- /02-Lodash/examples/math/03_divide.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Divide example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.divide(9, 4)); 9 | // => 2.25 -------------------------------------------------------------------------------- /02-Lodash/examples/math/04_floor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Floor example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.floor(8.003)); 9 | // => 8 10 | 11 | console.log(_.floor(2.00004, 3)); 12 | // => 2 13 | 14 | console.log(_.floor(1235, -3)); 15 | // => 1000 -------------------------------------------------------------------------------- /02-Lodash/examples/math/05_max.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Max example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.max([1, 3, 5, 7])); 9 | // => 7 10 | 11 | console.log(_.max([])); 12 | // => undefined -------------------------------------------------------------------------------- /02-Lodash/examples/math/06_maxby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MaxBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'n': 3 }, { 'n': 9 }]; 9 | 10 | console.log(_.maxBy(objects, function(o) { return o.n; })); 11 | // => { 'n': 9 } 12 | 13 | // The `_.property` iteratee shorthand. 14 | console.log(_.maxBy(objects, 'n')); 15 | // => { 'n': 9 } -------------------------------------------------------------------------------- /02-Lodash/examples/math/07_mean.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Mean example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.mean([1, 3, 5, 7])); 9 | // => 4 -------------------------------------------------------------------------------- /02-Lodash/examples/math/08_meanby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MeanBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'n': 1 }, { 'n': 3 }, { 'n': 5}, { 'n': 7 }]; 9 | 10 | console.log(_.meanBy(objects, function(o) { return o.n; })); 11 | // => 4 12 | 13 | // The `_.property` iteratee shorthand. 14 | console.log(_.meanBy(objects, 'n')); 15 | // => 4 -------------------------------------------------------------------------------- /02-Lodash/examples/math/09_min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Min example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.min([1, 3, 5, 7])); 9 | // => 1 10 | 11 | console.log(_.min([])); 12 | // => undefined -------------------------------------------------------------------------------- /02-Lodash/examples/math/10_minby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MinBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'n': 3 }, { 'n': 9 }]; 9 | 10 | console.log(_.minBy(objects, function(o) { return o.n; })); 11 | // => { 'n': 3 } 12 | 13 | // The `_.property` iteratee shorthand. 14 | console.log(_.minBy(objects, 'n')); 15 | // => { 'n': 3 }' -------------------------------------------------------------------------------- /02-Lodash/examples/math/11_multiply.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Multiply example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.multiply(4, 8)); 9 | // => 32 -------------------------------------------------------------------------------- /02-Lodash/examples/math/12_round.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Round example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.round(8.003)); 9 | // => 8 10 | 11 | console.log(_.round(2.00004, 3)); 12 | // => 2 13 | 14 | console.log(_.round(1235, -3)); 15 | // => 1000 -------------------------------------------------------------------------------- /02-Lodash/examples/math/13_subtract.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Subtract example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.subtract(9, 2)); 9 | // => 2 -------------------------------------------------------------------------------- /02-Lodash/examples/math/14_sum.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sum example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.sum([1, 2, 3, 4])); 9 | // => 10 -------------------------------------------------------------------------------- /02-Lodash/examples/math/15_sumby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * SumBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [{ 'n': 3 }, { 'n': 9 }]; 9 | 10 | console.log(_.sumBy(objects, function(o) { return o.n; })); 11 | // => { 'n': 12 } 12 | 13 | // The `_.property` iteratee shorthand. 14 | console.log(_.sumBy(objects, 'n')); 15 | // => { 'n': 12 }' -------------------------------------------------------------------------------- /02-Lodash/examples/methods/01_ref-lodash-func.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Ref lodash function example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.templateSettings.imports._); -------------------------------------------------------------------------------- /02-Lodash/examples/number/01_clamp.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Clamp example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.clamp(-100, -500, 500)); 9 | // => -100 10 | 11 | console.log(_.clamp(10, -5, 5)); 12 | // => 5 -------------------------------------------------------------------------------- /02-Lodash/examples/number/02_inrange.js: -------------------------------------------------------------------------------- 1 | /** 2 | * InRange example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.inRange(3, 2, 4)); 9 | // => true 10 | 11 | console.log(_.inRange(4, 8)); 12 | // => true 13 | 14 | console.log(_.inRange(4, 2)); 15 | // => false 16 | 17 | console.log(_.inRange(2, 2)); 18 | // => false 19 | 20 | console.log(_.inRange(1.2, 2)); 21 | // => true 22 | 23 | console.log(_.inRange(5.2, 4)); 24 | // => false 25 | 26 | console.log(_.inRange(-3, -2, -6)); 27 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/number/03_random.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Random example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.random(0, 9)); 9 | // => an integer between 0 and 9 10 | 11 | console.log(_.random(9)); 12 | // => also an integer between 0 and 9 13 | 14 | console.log(_.random(9, true)); 15 | // => a floating-point number between 0 and 9 16 | 17 | console.log(_.random(1.2, 9.2)); 18 | // => a floating-point number between 1.2 and 9.2 -------------------------------------------------------------------------------- /02-Lodash/examples/object/01_assign.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Assign example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | } 11 | 12 | function Bar() { 13 | this.c = 3; 14 | } 15 | 16 | Foo.prototype.b = 2; 17 | Bar.prototype.d = 4; 18 | 19 | console.log(_.assign({ 'a': 0 }, new Foo, new Bar)); 20 | // => { 'a': 1, 'c': 3 } -------------------------------------------------------------------------------- /02-Lodash/examples/object/02_assignin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Assign example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | } 11 | 12 | function Bar() { 13 | this.c = 3; 14 | } 15 | 16 | Foo.prototype.b = 2; 17 | Bar.prototype.d = 4; 18 | 19 | console.log(_.assignIn({ 'a': 0 }, new Foo, new Bar)); 20 | // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } -------------------------------------------------------------------------------- /02-Lodash/examples/object/03_assigninwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * assignWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function customizer(objValue, srcValue) { 9 | return _.isUndefined(objValue) ? srcValue : objValue; 10 | } 11 | 12 | var defaults = _.partialRight(_.assignWith, customizer); 13 | 14 | console.log(defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 })); 15 | // => { 'a': 1, 'b': 2 } -------------------------------------------------------------------------------- /02-Lodash/examples/object/04_assignwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * difference example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.difference([2, 1, 3], [2, 3, 3])); 9 | // => [1] -------------------------------------------------------------------------------- /02-Lodash/examples/object/05_at.js: -------------------------------------------------------------------------------- 1 | /** 2 | * at example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; 9 | 10 | console.log(_.at(object, ['a[0].b.c', 'a[1]'])); 11 | // => [3, 4] -------------------------------------------------------------------------------- /02-Lodash/examples/object/06_create.js: -------------------------------------------------------------------------------- 1 | /** 2 | * create example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Shape() { 9 | this.x = 0; 10 | this.y = 0; 11 | } 12 | 13 | function Circle() { 14 | Shape.call(this); 15 | } 16 | 17 | Circle.prototype = _.create(Shape.prototype, { 18 | 'constructor': Circle 19 | }); 20 | 21 | var circle = new Circle; 22 | console.log(circle instanceof Circle); 23 | // => true 24 | 25 | console.log(circle instanceof Shape); 26 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/object/07_defaults.js: -------------------------------------------------------------------------------- 1 | /** 2 | * defaults example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(__.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 })); 9 | // => { 'a': 1, 'b': 2 } -------------------------------------------------------------------------------- /02-Lodash/examples/object/08_defaultsdeep.js: -------------------------------------------------------------------------------- 1 | /** 2 | * defaultsDeep example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } })); 9 | // => { 'a': { 'b': 2, 'c': 3 } } -------------------------------------------------------------------------------- /02-Lodash/examples/object/09_entries.js: -------------------------------------------------------------------------------- 1 | /** 2 | * entries example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | 9 | function Foo() { 10 | this.a = 1; 11 | this.b = 2; 12 | } 13 | 14 | Foo.prototype.c = 3; 15 | 16 | console.log(_.toPairs(new Foo)); 17 | // => [['a', 1], ['b', 2]] (iteration order is not guaranteed) -------------------------------------------------------------------------------- /02-Lodash/examples/object/10_entriesin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * toPairsIn example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | 9 | function Foo() { 10 | this.a = 1; 11 | this.b = 2; 12 | } 13 | 14 | Foo.prototype.c = 3; 15 | 16 | console.log(_.toPairsIn(new Foo)); 17 | // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed) -------------------------------------------------------------------------------- /02-Lodash/examples/object/11_extend.js: -------------------------------------------------------------------------------- 1 | /** 2 | * assignIn example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | } 11 | 12 | function Bar() { 13 | this.c = 3; 14 | } 15 | 16 | Foo.prototype.b = 2; 17 | Bar.prototype.d = 4; 18 | 19 | console.log(_.assignIn({ 'a': 0 }, new Foo, new Bar)); 20 | // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } -------------------------------------------------------------------------------- /02-Lodash/examples/object/12_extendwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * extendwith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | 9 | function customizer(objValue, srcValue) { 10 | return _.isUndefined(objValue) ? srcValue : objValue; 11 | } 12 | 13 | var defaults = _.partialRight(_.assignInWith, customizer); 14 | 15 | console.log(defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 })); 16 | // => { 'a': 1, 'b': 2 } 17 | 18 | -------------------------------------------------------------------------------- /02-Lodash/examples/object/13_findkey.js: -------------------------------------------------------------------------------- 1 | /** 2 | * findKey example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = { 9 | 'barney': { 'age': 36, 'active': true }, 10 | 'fred': { 'age': 40, 'active': false }, 11 | 'pebbles': { 'age': 1, 'active': true } 12 | }; 13 | 14 | console.log(_.findKey(users, function(o) { return o.age < 40; })); 15 | // => 'barney' (iteration order is not guaranteed) 16 | 17 | // The `_.matches` iteratee shorthand. 18 | console.log(_.findKey(users, { 'age': 1, 'active': true })); 19 | // => 'pebbles' 20 | 21 | // The `_.matchesProperty` iteratee shorthand. 22 | console.log(_.findKey(users, ['active', false])); 23 | // => 'fred' 24 | 25 | // The `_.property` iteratee shorthand. 26 | console.log(_.findKey(users, 'active')); 27 | // => 'barney' -------------------------------------------------------------------------------- /02-Lodash/examples/object/14_findlastkey.js: -------------------------------------------------------------------------------- 1 | /** 2 | * findLastKey example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | var users = { 8 | 'barney': { 'age': 36, 'active': true }, 9 | 'fred': { 'age': 40, 'active': false }, 10 | 'pebbles': { 'age': 1, 'active': true } 11 | }; 12 | 13 | console.log(__.findLastKey(users, function(o) { return o.age < 40; })); 14 | // => returns 'pebbles' assuming `_.findKey` returns 'barney' 15 | 16 | // The `_.matches` iteratee shorthand. 17 | console.log(__.findLastKey(users, { 'age': 36, 'active': true })); 18 | // => 'barney' 19 | 20 | // The `_.matchesProperty` iteratee shorthand. 21 | console.log(__.findLastKey(users, ['active', false])); 22 | // => 'fred' 23 | 24 | // The `_.property` iteratee shorthand. 25 | console.log(__.findLastKey(users, 'active')); 26 | // => 'pebbles' -------------------------------------------------------------------------------- /02-Lodash/examples/object/15_forin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * forIn example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | function Foo() { 8 | this.a = 1; 9 | this.b = 2; 10 | } 11 | 12 | Foo.prototype.c = 3; 13 | 14 | _.forIn(new Foo, function(value, key) { 15 | console.log(key); 16 | }); 17 | // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed). -------------------------------------------------------------------------------- /02-Lodash/examples/object/16_forinright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * forInRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | this.b = 2; 11 | } 12 | 13 | Foo.prototype.c = 3; 14 | 15 | _.forInRight(new Foo, function(value, key) { 16 | console.log(key); 17 | }); 18 | // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'. -------------------------------------------------------------------------------- /02-Lodash/examples/object/17_forown.js: -------------------------------------------------------------------------------- 1 | /** 2 | * forOwn example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | this.b = 2; 11 | } 12 | 13 | Foo.prototype.c = 3; 14 | 15 | _.forOwn(new Foo, function(value, key) { 16 | console.log(key); 17 | }); 18 | // => Logs 'a' then 'b' (iteration order is not guaranteed). -------------------------------------------------------------------------------- /02-Lodash/examples/object/18_forownright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * forOwnRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | this.b = 2; 11 | } 12 | 13 | Foo.prototype.c = 3; 14 | 15 | _.forOwnRight(new Foo, function(value, key) { 16 | console.log(key); 17 | }); 18 | // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'. -------------------------------------------------------------------------------- /02-Lodash/examples/object/19_functions.js: -------------------------------------------------------------------------------- 1 | /** 2 | * functions example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = _.constant('a'); 10 | this.b = _.constant('b'); 11 | } 12 | 13 | Foo.prototype.c = _.constant('c'); 14 | 15 | console.log(_.functions(new Foo)); 16 | // => ['a', 'b'] 17 | -------------------------------------------------------------------------------- /02-Lodash/examples/object/20_functionsin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * functionsIn example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = _.constant('a'); 10 | this.b = _.constant('b'); 11 | } 12 | 13 | Foo.prototype.c = _.constant('c'); 14 | 15 | console.log(_.functionsIn(new Foo)); 16 | // => ['a', 'b', 'c'] -------------------------------------------------------------------------------- /02-Lodash/examples/object/21_get.js: -------------------------------------------------------------------------------- 1 | /** 2 | * get example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': [{ 'b': { 'c': 3 } }] }; 9 | 10 | console.log(_.get(object, 'a[0].b.c')); 11 | // => 3 12 | 13 | console.log(_.get(object, ['a', '0', 'b', 'c'])); 14 | // => 3 15 | 16 | console.log(_.get(object, 'a.b.c', 'default')); 17 | // => 'default' -------------------------------------------------------------------------------- /02-Lodash/examples/object/22_has.js: -------------------------------------------------------------------------------- 1 | /** 2 | * has example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': { 'b': 2 } }; 9 | var other = _.create({ 'a': _.create({ 'b': 2 }) }); 10 | 11 | console.log(_.has(object, 'a')); 12 | // => true 13 | 14 | console.log(_.has(object, 'a.b')); 15 | // => true 16 | 17 | console.log(_.has(object, ['a', 'b'])); 18 | // => true 19 | 20 | console.log(_.has(other, 'a')); 21 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/object/23_hasin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hasIn example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = _.create({ 'a': _.create({ 'b': 2 }) }); 9 | 10 | console.log(_.hasIn(object, 'a')); 11 | // => true 12 | 13 | console.log(_.hasIn(object, 'a.b')); 14 | // => true 15 | 16 | console.log(_.hasIn(object, ['a', 'b'])); 17 | // => true 18 | 19 | console.log(_.hasIn(object, 'b')); 20 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/object/24_invert.js: -------------------------------------------------------------------------------- 1 | /** 2 | * invert example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1, 'b': 2, 'c': 1 }; 9 | 10 | console.log(_.invert(object)); 11 | // => { '1': 'c', '2': 'b' } -------------------------------------------------------------------------------- /02-Lodash/examples/object/25_invertby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * invertBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1, 'b': 2, 'c': 1 }; 9 | 10 | console.log(_.invertBy(object)); 11 | // => { '1': ['a', 'c'], '2': ['b'] } 12 | 13 | console.log(_.invertBy(object, function(value) { 14 | return 'group' + value; 15 | })); 16 | // => { 'group1': ['a', 'c'], 'group2': ['b'] } -------------------------------------------------------------------------------- /02-Lodash/examples/object/26_invoke.js: -------------------------------------------------------------------------------- 1 | /** 2 | * invoke example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] }; 9 | 10 | console.log(_.invoke(object, 'a[0].b.c.slice', 1, 3)); 11 | // => [2, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/object/27_keys.js: -------------------------------------------------------------------------------- 1 | /** 2 | * keys example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | this.b = 2; 11 | } 12 | 13 | Foo.prototype.c = 3; 14 | 15 | console.log(_.keys(new Foo)); 16 | // => ['a', 'b'] (iteration order is not guaranteed) 17 | 18 | console.log(_.keys('hi')); 19 | // => ['0', '1'] -------------------------------------------------------------------------------- /02-Lodash/examples/object/28_keysin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * keysIn example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | this.b = 2; 11 | } 12 | 13 | Foo.prototype.c = 3; 14 | 15 | console.log(_.keysIn(new Foo)); 16 | // => ['a', 'b', 'c'] (iteration order is not guaranteed) -------------------------------------------------------------------------------- /02-Lodash/examples/object/29_mapkeys.js: -------------------------------------------------------------------------------- 1 | /** 2 | * mapKeys example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { 9 | return key + value; 10 | })); 11 | // => { 'a1': 1, 'b2': 2 } -------------------------------------------------------------------------------- /02-Lodash/examples/object/30_mapvalues.js: -------------------------------------------------------------------------------- 1 | /** 2 | * mapValues example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = { 9 | 'fred': { 'user': 'fred', 'age': 40 }, 10 | 'pebbles': { 'user': 'pebbles', 'age': 1 } 11 | }; 12 | 13 | console.log(_.mapValues(users, function(o) { return o.age; })); 14 | // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) 15 | 16 | // The `_.property` iteratee shorthand. 17 | console.log(_.mapValues(users, 'age')); 18 | // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) -------------------------------------------------------------------------------- /02-Lodash/examples/object/31_merge.js: -------------------------------------------------------------------------------- 1 | /** 2 | * merge example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 9 | 'a': [{ 'b': 2 }, { 'd': 4 }] 10 | }; 11 | 12 | var other = { 13 | 'a': [{ 'c': 3 }, { 'e': 5 }] 14 | }; 15 | 16 | console.log(_.merge(object, other)); 17 | // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } -------------------------------------------------------------------------------- /02-Lodash/examples/object/32_mergewith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * mergeWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function customizer(objValue, srcValue) { 9 | if (_.isArray(objValue)) { 10 | return objValue.concat(srcValue); 11 | } 12 | } 13 | 14 | var object = { 'a': [1], 'b': [2] }; 15 | var other = { 'a': [3], 'b': [4] }; 16 | 17 | console.log(_.mergeWith(object, other, customizer)); 18 | // => { 'a': [1, 3], 'b': [2, 4] } -------------------------------------------------------------------------------- /02-Lodash/examples/object/33_omit.js: -------------------------------------------------------------------------------- 1 | /** 2 | * omit example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1, 'b': '2', 'c': 3 }; 9 | 10 | console.log(_.omit(object, ['a', 'c'])); 11 | // => { 'b': '2' } -------------------------------------------------------------------------------- /02-Lodash/examples/object/34_omitby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * omitBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1, 'b': '2', 'c': 3 }; 9 | 10 | console.log(_.omitBy(object, _.isNumber)); 11 | // => { 'b': '2' } -------------------------------------------------------------------------------- /02-Lodash/examples/object/35_pick.js: -------------------------------------------------------------------------------- 1 | /** 2 | * pick example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1, 'b': '2', 'c': 3 }; 9 | 10 | console.log(_.pick(object, ['a', 'c'])); 11 | // => { 'a': 1, 'c': 3 } -------------------------------------------------------------------------------- /02-Lodash/examples/object/36_pickby.js: -------------------------------------------------------------------------------- 1 | /** 2 | * pickBy example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1, 'b': '2', 'c': 3 }; 9 | 10 | console.log(_.pickBy(object, _.isNumber)); 11 | // => { 'a': 1, 'c': 3 } -------------------------------------------------------------------------------- /02-Lodash/examples/object/37_result.js: -------------------------------------------------------------------------------- 1 | /** 2 | * result example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] }; 9 | 10 | console.log(_.result(object, 'a[0].b.c1')); 11 | // => 3 12 | 13 | console.log(_.result(object, 'a[0].b.c2')); 14 | // => 4 15 | 16 | console.log(_.result(object, 'a[0].b.c3', 'default')); 17 | // => 'default' 18 | 19 | console.log(_.result(object, 'a[0].b.c3', _.constant('default'))); 20 | // => 'default' -------------------------------------------------------------------------------- /02-Lodash/examples/object/38_set.js: -------------------------------------------------------------------------------- 1 | /** 2 | * set example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': [{ 'b': { 'c': 3 } }] }; 9 | 10 | _.set(object, 'a[0].b.c', 4); 11 | console.log(object.a[0].b.c); 12 | // => 4 13 | 14 | _.set(object, ['x', '0', 'y', 'z'], 5); 15 | console.log(object.x[0].y.z); 16 | // => 5 -------------------------------------------------------------------------------- /02-Lodash/examples/object/39_setwith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * setWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = {}; 9 | 10 | console.log(_.setWith(object, '[0][1]', 'a', Object)); 11 | // => { '0': { '1': 'a' } } -------------------------------------------------------------------------------- /02-Lodash/examples/object/40_topairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * toPairs example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | this.b = 2; 11 | } 12 | 13 | Foo.prototype.c = 3; 14 | 15 | console.log(_.toPairs(new Foo)); 16 | // => [['a', 1], ['b', 2]] (iteration order is not guaranteed) -------------------------------------------------------------------------------- /02-Lodash/examples/object/41_topairsin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * toPairsIn example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | this.b = 2; 11 | } 12 | 13 | Foo.prototype.c = 3; 14 | 15 | console.log(_.toPairsIn(new Foo)); 16 | // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed) -------------------------------------------------------------------------------- /02-Lodash/examples/object/42_transform.js: -------------------------------------------------------------------------------- 1 | /** 2 | * transform example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.transform([2, 3, 4], function(result, n) { 9 | result.push(n *= n); 10 | return n % 2 == 0; 11 | }, [])); 12 | // => [4, 9] 13 | 14 | console.log(_.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { 15 | (result[value] || (result[value] = [])).push(key); 16 | }, {})); 17 | // => { '1': ['a', 'c'], '2': ['b'] } -------------------------------------------------------------------------------- /02-Lodash/examples/object/43_unset.js: -------------------------------------------------------------------------------- 1 | /** 2 | * unset example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': [{ 'b': { 'c': 7 } }] }; 9 | _.unset(object, 'a[0].b.c'); 10 | // => true 11 | 12 | console.log(object); 13 | // => { 'a': [{ 'b': {} }] }; 14 | 15 | _.unset(object, ['a', '0', 'b', 'c']); 16 | // => true 17 | 18 | console.log(object); 19 | // => { 'a': [{ 'b': {} }] }; -------------------------------------------------------------------------------- /02-Lodash/examples/object/44_update.js: -------------------------------------------------------------------------------- 1 | /** 2 | * update example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': [{ 'b': { 'c': 3 } }] }; 9 | 10 | _.update(object, 'a[0].b.c', function(n) { return n * n; }); 11 | console.log(object.a[0].b.c); 12 | // => 9 13 | 14 | _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; }); 15 | console.log(object.x[0].y.z); 16 | // => 0 -------------------------------------------------------------------------------- /02-Lodash/examples/object/45_updatewith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * updateWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = {}; 9 | 10 | console.log(_.updateWith(object, '[0][1]', _.constant('a'), Object)); 11 | // => { '0': { '1': 'a' } } -------------------------------------------------------------------------------- /02-Lodash/examples/object/46_values.js: -------------------------------------------------------------------------------- 1 | /** 2 | * values example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | this.b = 2; 11 | } 12 | 13 | Foo.prototype.c = 3; 14 | 15 | console.log(_.values(new Foo)); 16 | // => [1, 2] (iteration order is not guaranteed) 17 | 18 | console.log(_.values('hi')); 19 | // => ['h', 'i'] -------------------------------------------------------------------------------- /02-Lodash/examples/object/47_valuesin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * valuesIn example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function Foo() { 9 | this.a = 1; 10 | this.b = 2; 11 | } 12 | 13 | Foo.prototype.c = 3; 14 | 15 | console.log(_.valuesIn(new Foo)); 16 | // => [1, 2, 3] (iteration order is not guaranteed) -------------------------------------------------------------------------------- /02-Lodash/examples/properties/01_version.js: -------------------------------------------------------------------------------- 1 | /** 2 | * VERSION example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.VERSION); -------------------------------------------------------------------------------- /02-Lodash/examples/properties/02_templatesettings.js: -------------------------------------------------------------------------------- 1 | /** 2 | * templateSettings example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.templateSettings); -------------------------------------------------------------------------------- /02-Lodash/examples/properties/03_templatesettings-escape.js: -------------------------------------------------------------------------------- 1 | /** 2 | * templateSettings-escape example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.templateSettings.escape); -------------------------------------------------------------------------------- /02-Lodash/examples/properties/04_templatesettings-evaluate.js: -------------------------------------------------------------------------------- 1 | /** 2 | * templateSettings-evaluate example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.templateSettings.evaluate); -------------------------------------------------------------------------------- /02-Lodash/examples/properties/05_templatesettings-imports.js: -------------------------------------------------------------------------------- 1 | /** 2 | * templateSettings-imports example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.templateSettings.imports); -------------------------------------------------------------------------------- /02-Lodash/examples/properties/06_templatesettings-interpolate.js: -------------------------------------------------------------------------------- 1 | /** 2 | * templateSettings-interpolate example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.templateSettings.interpolate); -------------------------------------------------------------------------------- /02-Lodash/examples/properties/07_templatesettings-variable.js: -------------------------------------------------------------------------------- 1 | /** 2 | * templateSettings-variable example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.templateSettings.variable); -------------------------------------------------------------------------------- /02-Lodash/examples/seq/01_lodash.js: -------------------------------------------------------------------------------- 1 | /** 2 | * lodash example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function square(n) { 9 | return n * n; 10 | } 11 | 12 | var wrapped = _([1, 2, 3]); 13 | 14 | // Returns an unwrapped value. 15 | console.log(wrapped.reduce(_.add)); 16 | // => 6 17 | 18 | // Returns a wrapped value. 19 | var squares = wrapped.map(square); 20 | 21 | console.log(_.isArray(squares)); 22 | // => false 23 | 24 | console.log(_.isArray(squares.value())); 25 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/seq/02_chain.js: -------------------------------------------------------------------------------- 1 | /** 2 | * chain example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'age': 36 }, 10 | { 'user': 'fred', 'age': 40 }, 11 | { 'user': 'pebbles', 'age': 1 } 12 | ]; 13 | 14 | var youngest = _ 15 | .chain(users) 16 | .sortBy('age') 17 | .map(function(o) { 18 | return o.user + ' is ' + o.age; 19 | }) 20 | .head() 21 | .value(); 22 | console.log(youngest); 23 | // => 'pebbles is 1' -------------------------------------------------------------------------------- /02-Lodash/examples/seq/03_tap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * tap example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_([1, 2, 3]) 9 | .tap(function(array) { 10 | // Mutate input array. 11 | array.pop(); 12 | }) 13 | .reverse() 14 | .value()); 15 | // => [2, 1] -------------------------------------------------------------------------------- /02-Lodash/examples/seq/04_thru.js: -------------------------------------------------------------------------------- 1 | /** 2 | * thru example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_(' abc ') 9 | .chain() 10 | .trim() 11 | .thru(function(value) { 12 | return [value]; 13 | }) 14 | .value()); 15 | // => ['abc'] -------------------------------------------------------------------------------- /02-Lodash/examples/seq/05_prototype-symbol.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Symbol example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var wrapped = _([1, 2]); 9 | 10 | console.log(wrapped[Symbol.iterator]() === wrapped); 11 | // => true 12 | 13 | console.log(Array.from(wrapped)); 14 | // => [1, 2] -------------------------------------------------------------------------------- /02-Lodash/examples/seq/06_prototype-at.js: -------------------------------------------------------------------------------- 1 | /** 2 | * at example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; 9 | 10 | console.log(_(object).at(['a[0].b.c', 'a[1]']).value()); 11 | // => [3, 4] -------------------------------------------------------------------------------- /02-Lodash/examples/seq/07_prototype-chain.js: -------------------------------------------------------------------------------- 1 | /** 2 | * chain example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'age': 36 }, 10 | { 'user': 'fred', 'age': 40 } 11 | ]; 12 | 13 | // A sequence without explicit chaining. 14 | console.log(_(users).head()); 15 | // => { 'user': 'barney', 'age': 36 } 16 | 17 | // A sequence with explicit chaining. 18 | console.log(_(users) 19 | .chain() 20 | .head() 21 | .pick('user') 22 | .value()); 23 | // => { 'user': 'barney' } -------------------------------------------------------------------------------- /02-Lodash/examples/seq/08_prototype-commit.js: -------------------------------------------------------------------------------- 1 | /** 2 | * commit example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [1, 2]; 9 | var wrapped = _(array).push(3); 10 | 11 | console.log(array); 12 | // => [1, 2] 13 | 14 | wrapped = wrapped.commit(); 15 | console.log(array); 16 | // => [1, 2, 3] 17 | 18 | wrapped.last(); 19 | // => 3 20 | 21 | console.log(array); 22 | // => [1, 2, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/seq/09_prototype-next.js: -------------------------------------------------------------------------------- 1 | /** 2 | * next example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var wrapped = _([1, 2]); 9 | 10 | console.log(wrapped.next()); 11 | // => { 'done': false, 'value': 1 } 12 | 13 | console.log(wrapped.next()); 14 | // => { 'done': false, 'value': 2 } 15 | 16 | console.log(wrapped.next()); 17 | // => { 'done': true, 'value': undefined } -------------------------------------------------------------------------------- /02-Lodash/examples/seq/10_prototype-plant.js: -------------------------------------------------------------------------------- 1 | /** 2 | * plant example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function square(n) { 9 | return n * n; 10 | } 11 | 12 | var wrapped = _([1, 2]).map(square); 13 | var other = wrapped.plant([3, 4]); 14 | 15 | console.log(other.value()); 16 | // => [9, 16] 17 | 18 | console.log(wrapped.value()); 19 | // => [1, 4] -------------------------------------------------------------------------------- /02-Lodash/examples/seq/11_prototype-reverse.js: -------------------------------------------------------------------------------- 1 | /** 2 | * reverse example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [1, 2, 3]; 9 | 10 | console.log(_(array).reverse().value()); 11 | // => [3, 2, 1] 12 | 13 | console.log(array); 14 | // => [3, 2, 1] -------------------------------------------------------------------------------- /02-Lodash/examples/seq/12_prototype-json.js: -------------------------------------------------------------------------------- 1 | /** 2 | * value example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_([1, 2, 3]).value()); 9 | // => [1, 2, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/seq/13_prototype-value.js: -------------------------------------------------------------------------------- 1 | /** 2 | * value example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_([1, 2, 3]).value()); 9 | // => [1, 2, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/seq/14_prototype-valueof.js: -------------------------------------------------------------------------------- 1 | /** 2 | * value example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_([1, 2, 3]).value()); 9 | // => [1, 2, 3] -------------------------------------------------------------------------------- /02-Lodash/examples/string/01_camelcase.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CamelCase example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.camelCase('Foot Ball')); 9 | // => 'footBall' 10 | 11 | console.log(_.camelCase('--foot-ball--')); 12 | // => 'footBall' 13 | 14 | console.log(_.camelCase('__FOOT_BALL__')); 15 | // => 'footBall' -------------------------------------------------------------------------------- /02-Lodash/examples/string/02_capitalize.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Capitalize example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.capitalize('SUDHEER')); 9 | // => 'Fred' -------------------------------------------------------------------------------- /02-Lodash/examples/string/03_deburr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Deburr example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.deburr('Südheer Jŏnna')); 9 | // => 'Fred' -------------------------------------------------------------------------------- /02-Lodash/examples/string/04_endswith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * EndsWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.endsWith('sudheer', 'r')); 9 | // => true 10 | 11 | console.log(_.endsWith('sudheer', 'h')); 12 | // => false 13 | 14 | console.log(_.endsWith('sudheer', 'h', 4)); 15 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/string/05_escape.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Escape example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.escape('Apples,Oranges, & Mangoes')); 9 | // => 'Apples,Oranges, & Mangoes' -------------------------------------------------------------------------------- /02-Lodash/examples/string/06_escaperegexp.js: -------------------------------------------------------------------------------- 1 | /** 2 | * EscapeRegExp example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.escapeRegExp('[sudheerjonna](https://sudheerjonna.com/)')); 9 | // => '\[sudheerjonna\]\(https://sudheerjonna\.com/\)' -------------------------------------------------------------------------------- /02-Lodash/examples/string/07_kebabcase.js: -------------------------------------------------------------------------------- 1 | /** 2 | * KebabCase example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.kebabCase('Foot Ball')); 9 | // => 'foot-ball' 10 | 11 | console.log(_.kebabCase('footBall')); 12 | // => 'foot-ball' 13 | 14 | console.log(_.kebabCase('__FOOT_BALL__')); 15 | // => 'foot-ball' -------------------------------------------------------------------------------- /02-Lodash/examples/string/08_lowercase.js: -------------------------------------------------------------------------------- 1 | /** 2 | * LowerCase example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.lowerCase('Foot Ball')); 9 | // => 'foot ball' 10 | 11 | console.log(_.lowerCase('footBall')); 12 | // => 'foot ball' 13 | 14 | console.log(_.lowerCase('__FOOT_BALL__')); 15 | // => 'foot ball' -------------------------------------------------------------------------------- /02-Lodash/examples/string/09_lowerfirst.js: -------------------------------------------------------------------------------- 1 | /** 2 | * LowerFirst example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.lowerFirst('Sudheer')); 9 | // => 'sudheer' 10 | 11 | console.log(_.lowerFirst('SUDHEER')); 12 | // => 'sUDHEER' -------------------------------------------------------------------------------- /02-Lodash/examples/string/10_pad.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Pad example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.pad('jonna', 9)); 9 | // => ' jonna ' 10 | 11 | console.log(_.pad('jonna', 10, '=@')); 12 | // => '=@jonna=@=' 13 | 14 | console.log(_.pad('sudh', 10)); 15 | // => ' sudh ' -------------------------------------------------------------------------------- /02-Lodash/examples/string/11_padend.js: -------------------------------------------------------------------------------- 1 | /** 2 | * PadEnd example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.padEnd('jonna', 9)); 9 | // => 'jonna ' 10 | 11 | console.log(_.padEnd('jonna', 10, '=@')); 12 | // => 'jonna=@=@=' 13 | 14 | console.log(_.padEnd('sudh', 10)); 15 | // => 'sudh ' -------------------------------------------------------------------------------- /02-Lodash/examples/string/12_padstart.js: -------------------------------------------------------------------------------- 1 | /** 2 | * PadStart example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.padStart('jonna', 9)); 9 | // => ' jonna ' 10 | 11 | console.log(_.padStart('jonna', 10, '=@')); 12 | // => '=@jonna=@=' 13 | 14 | console.log(_.padStart('sudh', 10)); 15 | // => ' sudh ' -------------------------------------------------------------------------------- /02-Lodash/examples/string/13_parseint.js: -------------------------------------------------------------------------------- 1 | /** 2 | * ParseInt example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.parseInt('05')); 9 | // => 5 10 | 11 | console.log(_.map(['04', '05','03', '02', '04'], _.parseInt)); 12 | // => [04, 05, 03, 02, 04] -------------------------------------------------------------------------------- /02-Lodash/examples/string/14_repeat.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Repeat example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.repeat('@', 5)); 9 | // => '@@@@@' 10 | 11 | console.log(_.repeat('sudheer', 2)); 12 | // => 'sudheersudheer' 13 | 14 | console.log(_.repeat('sudheer', 0)); 15 | // => '' -------------------------------------------------------------------------------- /02-Lodash/examples/string/15_replace.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Replace example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.replace('Hello JavaScript', 'JavaScript', 'Lodash')); 9 | // => 'Hello Lodash' -------------------------------------------------------------------------------- /02-Lodash/examples/string/16_snakecase.js: -------------------------------------------------------------------------------- 1 | /** 2 | * SnakeCase example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.snakeCase('Foot Ball')); 9 | // => 'foot_ball' 10 | 11 | console.log(_.snakeCase('footBall')); 12 | // => 'foot_ball' 13 | 14 | console.log(_.snakeCase('--FOOT-BALL--')); 15 | // => 'foot_ball' -------------------------------------------------------------------------------- /02-Lodash/examples/string/17_split.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Split example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.split('s-u-d-h-e-e-r', '-', 4)); 9 | // => ['s', 'u', 'd', 'h'] -------------------------------------------------------------------------------- /02-Lodash/examples/string/18_startcase.js: -------------------------------------------------------------------------------- 1 | /** 2 | * StartCase example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | 9 | console.log(_.startCase('--foot-ball--')); 10 | // => 'Foot Ball' 11 | 12 | console.log(_.startCase('footBall')); 13 | // => 'Foot Ball' 14 | 15 | console.log(_.startCase('__FOOT_BALL__')); 16 | // => 'FOOT BALL' -------------------------------------------------------------------------------- /02-Lodash/examples/string/19_startswith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * StartsWith example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.startsWith('lodash', 'l')); 9 | // => true 10 | 11 | console.log(_.startsWith('lodash', 'd')); 12 | // => false 13 | 14 | console.log(_.startsWith('lodash', 's', 4)); 15 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/string/20_template.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Template example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | 9 | // Use the "interpolate" delimiter to create a compiled template. 10 | var compiled = _.template('hello <%= js %>!'); 11 | console.log(compiled({ 'js': 'lodash' })); 12 | // => 'hello lodash!' 13 | 14 | // Use the internal `print` function in "evaluate" delimiters. 15 | 16 | var compiled = _.template('<% print("hello " + js); %>!'); 17 | console.log(compiled({ 'js': 'lodash' })); 18 | // => 'hello lodash!' -------------------------------------------------------------------------------- /02-Lodash/examples/string/21_tolower.js: -------------------------------------------------------------------------------- 1 | /** 2 | * To Lower example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.toLower('--Foot-Ball--')); 9 | // => '--foot-ball--' 10 | 11 | console.log(_.toLower('footBall')); 12 | // => 'football' 13 | 14 | console.log(_.toLower('__FOOT_BALL__')); 15 | // => '__foot_ball__' -------------------------------------------------------------------------------- /02-Lodash/examples/string/22_toupper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * To Upper example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.toUpper('--Foot-Ball--')); 9 | // => '--FOOT-BALL--' 10 | 11 | console.log(_.toUpper('footBall')); 12 | // => 'FOOTBALL' 13 | 14 | console.log(_.toUpper('__FOOT_BALL__')); 15 | // => '__FOOT_BALL__' -------------------------------------------------------------------------------- /02-Lodash/examples/string/23_trim.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Trim example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.trim(' lodash ')); 9 | // => 'lodash' 10 | 11 | console.log(_.trim('-_-lodash-_-', '_-')); 12 | // => 'lodash' 13 | 14 | console.log(_.map([' lodash ', ' utility '], _.trim)); 15 | // => ['lodash', 'utility'] -------------------------------------------------------------------------------- /02-Lodash/examples/string/24_trimend.js: -------------------------------------------------------------------------------- 1 | /** 2 | * TrimEnd example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.trimEnd(' lodash ')); 9 | // => ' lodash' 10 | 11 | console.log(_.trimEnd('-_-lodash-_-', '_-')); 12 | // => '-_-lodash' 13 | 14 | console.log(_.map([' lodash ', ' utility '], _.trimEnd)); 15 | // => [' lodash', ' utility'] -------------------------------------------------------------------------------- /02-Lodash/examples/string/25_trimstart.js: -------------------------------------------------------------------------------- 1 | /** 2 | * TrimStart example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.trimStart(' lodash ')); 9 | // => ' lodash' 10 | 11 | console.log(_.trimStart('-_-lodash-_-', '_-')); 12 | // => '-_-lodash' 13 | 14 | console.log(_.map([' lodash ', ' utility '], _.trimStart)); 15 | // => [' lodash', ' utility'] -------------------------------------------------------------------------------- /02-Lodash/examples/string/26_truncate.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Truncate example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.truncate('Hello lodash fans there, lets enjoy JS')); 9 | // => 'Hello lodash fans there, le...' 10 | 11 | console.log(_.truncate('Hello lodash fans there, lets enjoy JS', { 12 | 'length': 24, 13 | 'separator': ' ' 14 | })); 15 | // => 'Hello lodash fans...' 16 | 17 | console.log(_.truncate('Hello lodash fans there, lets enjoy JS', { 18 | 'length': 24, 19 | 'separator': /,? +/ 20 | })); 21 | // => 'Hello lodash fans...' 22 | 23 | console.log(_.truncate('Hello lodash fans there, lets enjoy JS', { 24 | 'omission': ' [...]' 25 | })); 26 | // => 'Hello lodash fans there, [...]' -------------------------------------------------------------------------------- /02-Lodash/examples/string/27_unescape.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Unescape example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.unescape('Hello, lodash, & devs')); 9 | // => 'Hello, lodash, & devs' -------------------------------------------------------------------------------- /02-Lodash/examples/string/28_uppercase.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Upper Case example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.upperCase('--foot-ball')); 9 | // => 'FOOT BALL' 10 | 11 | console.log(_.upperCase('footBall')); 12 | // => 'FOOT BALL' 13 | 14 | console.log(_.upperCase('__foot_ball__')); 15 | // => 'FOOT BALL' -------------------------------------------------------------------------------- /02-Lodash/examples/string/29_upperfirst.js: -------------------------------------------------------------------------------- 1 | /** 2 | * UpperFirst example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.upperFirst('lodash')); 9 | // => 'Lodash' 10 | 11 | console.log(_.upperFirst('LODASH')); 12 | // => 'LODASH' -------------------------------------------------------------------------------- /02-Lodash/examples/string/30_words.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Words example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.words('hi, lodash, & devs')); 9 | // => ['hi', 'lodash', 'devs'] 10 | 11 | console.log(_.words('hi, lodash, & devs', /[^, ]+/g)); 12 | // => ['hi', 'lodash', '&', 'devs'] -------------------------------------------------------------------------------- /02-Lodash/examples/util/01_attempt.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Attempt example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | // Avoid throwing errors for invalid selectors. 9 | var elements = _.attempt(function(selector) { 10 | return document.querySelectorAll(selector); 11 | }, '>_>'); 12 | 13 | //console.log(elements); 14 | 15 | if (_.isError(elements)) { 16 | elements = []; 17 | } -------------------------------------------------------------------------------- /02-Lodash/examples/util/02_bindall.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Attempt example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | var jQuery = require('../../node_modules/jQuery'); 8 | const jsdom = require("jsdom"); 9 | const { JSDOM } = jsdom; 10 | 11 | var view = { 12 | 'label': 'docs', 13 | 'click': function() { 14 | console.log('clicked ' + this.label); 15 | } 16 | }; 17 | 18 | const dom = new JSDOM(` 19 | 20 | `); 21 | 22 | var element = dom.window.document.body.children[0]; 23 | 24 | _.bindAll(view, ['click']); 25 | jQuery(element).on('click', view.click); 26 | // => Logs 'clicked docs' when clicked. -------------------------------------------------------------------------------- /02-Lodash/examples/util/03_cond.js: -------------------------------------------------------------------------------- 1 | /** 2 | * cond example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var func = _.cond([ 9 | [_.matches({ 'a': 1 }), _.constant('matches A')], 10 | [_.conforms({ 'b': _.isNumber }), _.constant('matches B')], 11 | [_.stubTrue, _.constant('no match')] 12 | ]); 13 | 14 | console.log(func({ 'a': 1, 'b': 2 })); 15 | // => 'matches A' 16 | 17 | console.log(func({ 'a': 0, 'b': 1 })); 18 | // => 'matches B' 19 | 20 | console.log(func({ 'a': '1', 'b': '2' })); 21 | // => 'no match' 22 | 23 | -------------------------------------------------------------------------------- /02-Lodash/examples/util/04_conforms.js: -------------------------------------------------------------------------------- 1 | /** 2 | * conforms example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [ 9 | { 'a': 2, 'b': 1 }, 10 | { 'a': 1, 'b': 2 } 11 | ]; 12 | 13 | console.log(_.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }))); 14 | // => [{ 'a': 1, 'b': 2 }] -------------------------------------------------------------------------------- /02-Lodash/examples/util/05_constant.js: -------------------------------------------------------------------------------- 1 | /** 2 | * constant example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = _.times(2, _.constant({ 'a': 1 })); 9 | 10 | console.log(objects); 11 | // => [{ 'a': 1 }, { 'a': 1 }] 12 | 13 | console.log(objects[0] === objects[1]); 14 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/util/06_defaultto.js: -------------------------------------------------------------------------------- 1 | /** 2 | * defaultTo example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.defaultTo(1, 10)); 9 | // => 1 10 | 11 | console.log(_.defaultTo(undefined, 10)); 12 | // => 10 -------------------------------------------------------------------------------- /02-Lodash/examples/util/07_flow.js: -------------------------------------------------------------------------------- 1 | /** 2 | * flow example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function square(n) { 9 | return n * n; 10 | } 11 | 12 | var addSquare = _.flow([_.add, square]); 13 | console.log(addSquare(1, 2)); 14 | // => 9 -------------------------------------------------------------------------------- /02-Lodash/examples/util/08_flowright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * flowRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | function square(n) { 9 | return n * n; 10 | } 11 | 12 | var addSquare = _.flowRight([square, _.add]); 13 | console.log(addSquare(1, 2)); 14 | // => 9 -------------------------------------------------------------------------------- /02-Lodash/examples/util/09_identity.js: -------------------------------------------------------------------------------- 1 | /** 2 | * identity example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var object = { 'a': 1 }; 9 | 10 | console.log(_.identity(object) === object); 11 | // => true -------------------------------------------------------------------------------- /02-Lodash/examples/util/10_iteratee.js: -------------------------------------------------------------------------------- 1 | /** 2 | * iteratee example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var users = [ 9 | { 'user': 'barney', 'age': 36, 'active': true }, 10 | { 'user': 'fred', 'age': 40, 'active': false } 11 | ]; 12 | 13 | // The `_.matches` iteratee shorthand. 14 | console.log(_.filter(users, _.iteratee({ 'user': 'barney', 'active': true })); 15 | // => [{ 'user': 'barney', 'age': 36, 'active': true }] 16 | 17 | // The `_.matchesProperty` iteratee shorthand. 18 | console.log(_.filter(users, _.iteratee(['user', 'fred'])); 19 | // => [{ 'user': 'fred', 'age': 40 }] 20 | 21 | // The `_.property` iteratee shorthand. 22 | console.log(_.map(users, _.iteratee('user')); 23 | // => ['barney', 'fred'] 24 | 25 | // Create custom iteratee shorthands. 26 | console.log(_.iteratee = _.wrap(_.iteratee, function(iteratee, func) { 27 | return !_.isRegExp(func) ? iteratee(func) : function(string) { 28 | return func.test(string); 29 | }; 30 | })); 31 | 32 | console.log(_.filter(['abc', 'def'], /ef/)); 33 | // => ['def'] -------------------------------------------------------------------------------- /02-Lodash/examples/util/11_matches.js: -------------------------------------------------------------------------------- 1 | /** 2 | * matches example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [ 9 | { 'a': 1, 'b': 2, 'c': 3 }, 10 | { 'a': 4, 'b': 5, 'c': 6 } 11 | ]; 12 | 13 | console.log(_.filter(objects, _.matches({ 'a': 4, 'c': 6 }))); 14 | // => [{ 'a': 4, 'b': 5, 'c': 6 }] -------------------------------------------------------------------------------- /02-Lodash/examples/util/12_matchesproperty.js: -------------------------------------------------------------------------------- 1 | /** 2 | * matchesProperty example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [ 9 | { 'a': 1, 'b': 2, 'c': 3 }, 10 | { 'a': 4, 'b': 5, 'c': 6 } 11 | ]; 12 | 13 | console.log(_.find(objects, _.matchesProperty('a', 4))); 14 | // => { 'a': 4, 'b': 5, 'c': 6 } -------------------------------------------------------------------------------- /02-Lodash/examples/util/13_method.js: -------------------------------------------------------------------------------- 1 | /** 2 | * method example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = [ 9 | { 'a': { 'b': _.constant(2) } }, 10 | { 'a': { 'b': _.constant(1) } } 11 | ]; 12 | 13 | console.log(_.map(objects, _.method('a.b'))); 14 | // => [2, 1] 15 | 16 | console.log(_.map(objects, _.method(['a', 'b']))); 17 | // => [2, 1] -------------------------------------------------------------------------------- /02-Lodash/examples/util/14_methodof.js: -------------------------------------------------------------------------------- 1 | /** 2 | * methodOf example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = _.times(3, _.constant), 9 | object = { 'a': array, 'b': array, 'c': array }; 10 | 11 | console.log(_.map(['a[2]', 'c[0]'], _.methodOf(object))); 12 | // => [2, 0] 13 | 14 | console.log(_.map([['a', '2'], ['c', '0']], _.methodOf(object))); 15 | // => [2, 0] -------------------------------------------------------------------------------- /02-Lodash/examples/util/15_mixin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * mixin example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | 9 | function vowels(string) { 10 | return _.filter(string, function(v) { 11 | return /[aeiou]/i.test(v); 12 | }); 13 | } 14 | 15 | _.mixin({ 'vowels': vowels }); 16 | console.log(_.vowels('fred')); 17 | // => ['e'] 18 | 19 | _('fred').vowels().value(); 20 | // => ['e'] 21 | 22 | _.mixin({ 'vowels': vowels }, { 'chain': false }); 23 | console.log(_('fred').vowels()); 24 | // => ['e'] -------------------------------------------------------------------------------- /02-Lodash/examples/util/16_noconflict.js: -------------------------------------------------------------------------------- 1 | /** 2 | * noConflict example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var lodash = _.noConflict(); 9 | console.log(lodash); -------------------------------------------------------------------------------- /02-Lodash/examples/util/17_noop.js: -------------------------------------------------------------------------------- 1 | /** 2 | * noop example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.times(2, _.noop)); 9 | // => [undefined, undefined] -------------------------------------------------------------------------------- /02-Lodash/examples/util/18_ntharg.js: -------------------------------------------------------------------------------- 1 | /** 2 | * nthArg example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var func = _.nthArg(1); 9 | console.log(func('a', 'b', 'c', 'd')); 10 | // => 'b' 11 | 12 | var func = _.nthArg(-2); 13 | console.log(func('a', 'b', 'c', 'd')); 14 | // => 'c' -------------------------------------------------------------------------------- /02-Lodash/examples/util/19_over.js: -------------------------------------------------------------------------------- 1 | /** 2 | * over example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var func = _.over([Math.max, Math.min]); 9 | 10 | console.log(func(1, 2, 3, 4)); 11 | // => [4, 1] 12 | -------------------------------------------------------------------------------- /02-Lodash/examples/util/20_overevery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * func example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var func = _.overEvery([Boolean, isFinite]); 9 | 10 | console.log(func('1')); 11 | // => true 12 | 13 | console.log(func(null)); 14 | // => false 15 | 16 | console.log(func(NaN)); 17 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/util/21_oversome.js: -------------------------------------------------------------------------------- 1 | /** 2 | * overSome example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var func = _.overSome([Boolean, isFinite]); 9 | 10 | console.log(func('1')); 11 | // => true 12 | 13 | console.log(func(null)); 14 | // => true 15 | 16 | console.log(func(NaN)); 17 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/util/22_property.js: -------------------------------------------------------------------------------- 1 | /** 2 | * property example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | 9 | var objects = [ 10 | { 'a': { 'b': 2 } }, 11 | { 'a': { 'b': 1 } } 12 | ]; 13 | 14 | console.log(_.map(objects, _.property('a.b'))); 15 | // => [2, 1] 16 | 17 | console.log(_.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b')); 18 | // => [1, 2] -------------------------------------------------------------------------------- /02-Lodash/examples/util/23_propertyof.js: -------------------------------------------------------------------------------- 1 | /** 2 | * propertyOf example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var array = [0, 1, 2], 9 | object = { 'a': array, 'b': array, 'c': array }; 10 | 11 | console.log(_.map(['a[2]', 'c[0]'], _.propertyOf(object))); 12 | // => [2, 0] 13 | 14 | console.log(_.map([['a', '2'], ['c', '0']], _.propertyOf(object))); 15 | // => [2, 0] -------------------------------------------------------------------------------- /02-Lodash/examples/util/24_range.js: -------------------------------------------------------------------------------- 1 | /** 2 | * range example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | 9 | console.log(_.range(4)); 10 | // => [0, 1, 2, 3] 11 | 12 | console.log(_.range(-4)); 13 | // => [0, -1, -2, -3] 14 | 15 | console.log(_.range(1, 5)); 16 | // => [1, 2, 3, 4] 17 | 18 | console.log(_.range(0, 20, 5)); 19 | // => [0, 5, 10, 15] 20 | 21 | console.log(_.range(0, -4, -1)); 22 | // => [0, -1, -2, -3] 23 | 24 | console.log(_.range(1, 4, 0)); 25 | // => [1, 1, 1] 26 | 27 | console.log(_.range(0)); 28 | // => [] -------------------------------------------------------------------------------- /02-Lodash/examples/util/25_rangeright.js: -------------------------------------------------------------------------------- 1 | /** 2 | * rangeRight example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | 9 | console.log(_.rangeRight(4)); 10 | // => [3, 2, 1, 0] 11 | 12 | console.log(_.rangeRight(-4)); 13 | // => [-3, -2, -1, 0] 14 | 15 | console.log(_.rangeRight(1, 5)); 16 | // => [4, 3, 2, 1] 17 | 18 | console.log(_.rangeRight(0, 20, 5)); 19 | // => [15, 10, 5, 0] 20 | 21 | console.log(_.rangeRight(0, -4, -1)); 22 | // => [-3, -2, -1, 0] 23 | 24 | console.log(_.rangeRight(1, 4, 0)); 25 | // => [1, 1, 1] 26 | 27 | console.log(_.rangeRight(0)); 28 | // => [] -------------------------------------------------------------------------------- /02-Lodash/examples/util/26_runincontext.js: -------------------------------------------------------------------------------- 1 | /** 2 | * runInContext example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | _.mixin({ 'foo': _.constant('foo') }); 9 | 10 | var lodash = _.runInContext(); 11 | lodash.mixin({ 'bar': lodash.constant('bar') }); 12 | 13 | console.log(_.isFunction(_.foo)); 14 | // => true 15 | console.log(_.isFunction(_.bar)); 16 | // => false 17 | 18 | console.log(lodash.isFunction(lodash.foo)); 19 | // => false 20 | console.log(lodash.isFunction(lodash.bar)); 21 | // => true 22 | 23 | // Create a suped-up `defer` in Node.js. 24 | var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; -------------------------------------------------------------------------------- /02-Lodash/examples/util/27_stubarray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * stubArray example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var arrays = _.times(2, _.stubArray); 9 | 10 | console.log(arrays); 11 | // => [[], []] 12 | 13 | console.log(arrays[0] === arrays[1]); 14 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/util/28_stubfalse.js: -------------------------------------------------------------------------------- 1 | /** 2 | * stubFalse example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.times(2, _.stubFalse)); 9 | // => [false, false] -------------------------------------------------------------------------------- /02-Lodash/examples/util/29_stubobject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * stubObject example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | var objects = _.times(2, _.stubObject); 9 | 10 | console.log(objects); 11 | // => [{}, {}] 12 | 13 | console.log(objects[0] === objects[1]); 14 | // => false -------------------------------------------------------------------------------- /02-Lodash/examples/util/30_stubstring.js: -------------------------------------------------------------------------------- 1 | /** 2 | * stubString example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.times(2, _.stubString)); 9 | // => ['', ''] -------------------------------------------------------------------------------- /02-Lodash/examples/util/31_stubtrue.js: -------------------------------------------------------------------------------- 1 | /** 2 | * stubTrue example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.times(2, _.stubTrue)); 9 | // => [true, true] -------------------------------------------------------------------------------- /02-Lodash/examples/util/32_times.js: -------------------------------------------------------------------------------- 1 | /** 2 | * times example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.times(3, String)); 9 | // => ['0', '1', '2'] 10 | 11 | console.log(_.times(4, _.constant(0))); 12 | // => [0, 0, 0, 0] -------------------------------------------------------------------------------- /02-Lodash/examples/util/33_topath.js: -------------------------------------------------------------------------------- 1 | /** 2 | * toPath example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.toPath('a.b.c')); 9 | // => ['a', 'b', 'c'] 10 | 11 | console.log(_.toPath('a[0].b.c')); 12 | // => ['a', '0', 'b', 'c'] -------------------------------------------------------------------------------- /02-Lodash/examples/util/34_uniqueid.js: -------------------------------------------------------------------------------- 1 | /** 2 | * uniqueId example 3 | */ 4 | 5 | 'use strict'; 6 | var _ = require('../../node_modules/lodash'); 7 | 8 | console.log(_.uniqueId('contact_')); 9 | // => 'contact_104' 10 | 11 | console.log(_.uniqueId()); 12 | // => '105' -------------------------------------------------------------------------------- /02-Lodash/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "01-Inquirerjs", 3 | "version": "0.0.1", 4 | "devDependencies": { 5 | "jquery": "^3.2.1", 6 | "lodash": "^4.17.4" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /03-Webpack/01-basic/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /dist 3 | -------------------------------------------------------------------------------- /03-Webpack/01-basic/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Sudheer Jonna 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /03-Webpack/01-basic/README.md: -------------------------------------------------------------------------------- 1 | #Basic -------------------------------------------------------------------------------- /03-Webpack/01-basic/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Webpack 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /03-Webpack/01-basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "basic", 3 | "version": "1.0.0", 4 | "description": "Basic webpack app", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node_modules/.bin/webpack-dev-server", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/sudheerj/awesome-javascript-technologies.git" 13 | }, 14 | "keywords": [ 15 | "webpack" 16 | ], 17 | "author": "Sudheer Jonna", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/sudheerj/awesome-javascript-technologies/issues" 21 | }, 22 | "homepage": "https://github.com/sudheerj/awesome-javascript-technologies/tree/master/03_Webpack#readme", 23 | "devDependencies": { 24 | "webpack": "^3.8.1", 25 | "webpack-dev-server": "^2.9.3" 26 | }, 27 | "dependencies": { 28 | "jquery": "^3.1.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /03-Webpack/01-basic/src/one.js: -------------------------------------------------------------------------------- 1 | var message = require('./two'); 2 | alert(message); 3 | -------------------------------------------------------------------------------- /03-Webpack/01-basic/src/two.js: -------------------------------------------------------------------------------- 1 | module.exports = "Hello Webpack app"; 2 | -------------------------------------------------------------------------------- /03-Webpack/01-basic/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | //define entry point 4 | entry: './src/one.js', 5 | 6 | //defin output point 7 | output: { 8 | path: __dirname + '/dist', 9 | filename: 'bundle.js' 10 | } 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /03-Webpack/02-babel-loader/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /dist 3 | -------------------------------------------------------------------------------- /03-Webpack/02-babel-loader/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Sudheer Jonna 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /03-Webpack/02-babel-loader/README.md: -------------------------------------------------------------------------------- 1 | # Babel loader -------------------------------------------------------------------------------- /03-Webpack/02-babel-loader/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Webpack 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /03-Webpack/02-babel-loader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack-playlist", 3 | "version": "1.0.0", 4 | "description": "Babel loader webpack app", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node_modules/.bin/webpack-dev-server", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/sudheerj/awesome-javascript-technologies.git" 13 | }, 14 | "keywords": [ 15 | "webpack" 16 | ], 17 | "author": "Sudheer Jonna", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/sudheerj/awesome-javascript-technologies/issues" 21 | }, 22 | "homepage": "https://github.com/sudheerj/awesome-javascript-technologies/tree/master/03_Webpack#readme", 23 | "devDependencies": { 24 | "babel-core": "^6.26.0", 25 | "babel-loader": "^6.2.5", 26 | "babel-preset-es2015": "^6.14.0", 27 | "webpack": "^3.8.1", 28 | "webpack-dev-server": "^2.9.3" 29 | }, 30 | "dependencies": { 31 | "jquery": "^3.1.1" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /03-Webpack/02-babel-loader/src/one.js: -------------------------------------------------------------------------------- 1 | var message = require('./two'); 2 | alert(message); 3 | -------------------------------------------------------------------------------- /03-Webpack/02-babel-loader/src/two.js: -------------------------------------------------------------------------------- 1 | const mssg = "Hello Webpack"; 2 | module.exports = mssg; 3 | -------------------------------------------------------------------------------- /03-Webpack/02-babel-loader/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | //define entry point 4 | entry: './src/one.js', 5 | 6 | //define output point 7 | output: { 8 | path: __dirname + '/dist', 9 | filename: 'bundle.js' 10 | }, 11 | 12 | module: { 13 | loaders: [ 14 | { 15 | test: /\.js$/, 16 | exclude: /(node_modules)/, 17 | loader: 'babel-loader', 18 | query: { 19 | presets: ['es2015'] 20 | } 21 | } 22 | ] //loaders 23 | } //module 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /03-Webpack/03-css-loader/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /dist 3 | -------------------------------------------------------------------------------- /03-Webpack/03-css-loader/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Sudheer Jonna 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /03-Webpack/03-css-loader/README.md: -------------------------------------------------------------------------------- 1 | # CSS Loader -------------------------------------------------------------------------------- /03-Webpack/03-css-loader/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Webpack 6 | 7 | 8 |
9 |
10 |

Hello Webpack

11 |
12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /03-Webpack/03-css-loader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack-playlist", 3 | "version": "1.0.0", 4 | "description": "CSS Loader webpack app", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node_modules/.bin/webpack-dev-server", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/sudheerj/awesome-javascript-technologies.git" 13 | }, 14 | "keywords": [ 15 | "webpack" 16 | ], 17 | "author": "Sudheer Jonna", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/sudheerj/awesome-javascript-technologies/issues" 21 | }, 22 | "homepage": "https://github.com/sudheerj/awesome-javascript-technologies/tree/master/03_Webpack#readme", 23 | "devDependencies": { 24 | "babel-core": "^6.26.0", 25 | "babel-loader": "^6.2.5", 26 | "babel-preset-es2015": "^6.14.0", 27 | "css-loader": "^0.25.0", 28 | "style-loader": "^0.13.1", 29 | "webpack": "^3.8.1", 30 | "webpack-dev-server": "^2.9.3" 31 | }, 32 | "dependencies": { 33 | "jquery": "^3.1.1" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /03-Webpack/03-css-loader/src/css/introComponent.css: -------------------------------------------------------------------------------- 1 | .intro-component{ 2 | padding: 20px; 3 | background: blue; 4 | color: #fff; 5 | font-family: arial; 6 | } 7 | -------------------------------------------------------------------------------- /03-Webpack/03-css-loader/src/one.js: -------------------------------------------------------------------------------- 1 | // Welcome Component JS 2 | var message = require('./two'); 3 | require('./css/introComponent.css'); 4 | -------------------------------------------------------------------------------- /03-Webpack/03-css-loader/src/two.js: -------------------------------------------------------------------------------- 1 | const mssg = "tempus fugit"; 2 | module.exports = mssg; 3 | -------------------------------------------------------------------------------- /03-Webpack/03-css-loader/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | //define entry point 4 | entry: './src/one.js', 5 | 6 | //define output point 7 | output: { 8 | path: __dirname + '/dist', 9 | filename: 'bundle.js' 10 | }, 11 | 12 | module: { 13 | loaders: [ 14 | { 15 | test: /\.js$/, 16 | exclude: /(node_modules)/, 17 | loader: 'babel-loader', 18 | query: { 19 | presets: ['es2015'] 20 | } 21 | }, 22 | { 23 | test: /\.css$/, 24 | loader: 'style-loader!css-loader' 25 | } 26 | ] //loaders 27 | } //module 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /03-Webpack/04-sass-loader/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /dist 3 | -------------------------------------------------------------------------------- /03-Webpack/04-sass-loader/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Sudheer Jonna 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /03-Webpack/04-sass-loader/README.md: -------------------------------------------------------------------------------- 1 | # SASS Loaders -------------------------------------------------------------------------------- /03-Webpack/04-sass-loader/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Webpack 6 | 7 | 8 |
9 |
10 |

Hello Webpack

11 |
12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /03-Webpack/04-sass-loader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "04-sass-loader", 3 | "version": "1.0.0", 4 | "description": "Simple webpack app", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node_modules/.bin/webpack-dev-server", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/sudheerj/awesome-javascript-technologies.git" 13 | }, 14 | "keywords": [ 15 | "webpack" 16 | ], 17 | "author": "Sudheer Jonna", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/sudheerj/awesome-javascript-technologies/issues" 21 | }, 22 | "homepage": "https://github.com/sudheerj/awesome-javascript-technologies/tree/master/03_Webpack#readme", 23 | "devDependencies": { 24 | "babel-core": "^6.26.0", 25 | "babel-loader": "^6.2.5", 26 | "babel-preset-es2015": "^6.14.0", 27 | "css-loader": "^0.25.0", 28 | "node-sass": "^3.10.0", 29 | "sass-loader": "^4.0.2", 30 | "style-loader": "^0.13.1", 31 | "webpack": "^3.8.1", 32 | "webpack-dev-server": "^2.9.3" 33 | }, 34 | "dependencies": { 35 | "jquery": "^3.1.1" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /03-Webpack/04-sass-loader/src/css/introComponent.scss: -------------------------------------------------------------------------------- 1 | $mainColour: #333333; 2 | 3 | .intro-component{ 4 | padding: 20px; 5 | background: $mainColour; 6 | color: #fff; 7 | font-family: arial; 8 | 9 | h1{ 10 | text-transform: uppercase; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /03-Webpack/04-sass-loader/src/one.js: -------------------------------------------------------------------------------- 1 | // Welcome Component JS 2 | var message = require('./two'); 3 | require('./css/introComponent.scss'); 4 | -------------------------------------------------------------------------------- /03-Webpack/04-sass-loader/src/two.js: -------------------------------------------------------------------------------- 1 | const mssg = "Hello Webpack app"; 2 | module.exports = mssg; 3 | -------------------------------------------------------------------------------- /03-Webpack/04-sass-loader/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | //define entry point 4 | entry: './src/one.js', 5 | 6 | //define output point 7 | output: { 8 | path: __dirname + '/dist', 9 | filename: 'bundle.js' 10 | }, 11 | 12 | module: { 13 | loaders: [ 14 | { 15 | test: /\.js$/, 16 | exclude: /(node_modules)/, 17 | loader: 'babel-loader', 18 | query: { 19 | presets: ['es2015'] 20 | } 21 | }, 22 | { 23 | test: /\.scss$/, 24 | loader: 'style-loader!css-loader!sass-loader' 25 | } 26 | ] //loaders 27 | } //module 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /03-Webpack/images/one.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/03-Webpack/images/one.png -------------------------------------------------------------------------------- /03-Webpack/images/two.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/03-Webpack/images/two.png -------------------------------------------------------------------------------- /04-RxJS/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sudheerj/awesome-javascript-technologies/7cff79d29879feb2a6710dfeef69dc59e5472a11/04-RxJS/README.md -------------------------------------------------------------------------------- /05-TypeScript/01-basicTypes/01_boolean.ts: -------------------------------------------------------------------------------- 1 | let isVerified: boolean = false; -------------------------------------------------------------------------------- /05-TypeScript/01-basicTypes/02_number.ts: -------------------------------------------------------------------------------- 1 | let decimal: number = 6; 2 | let hex: number = 0xfabcd; 3 | let binary: number = 0b0101; 4 | let octal: number = 0o4744; -------------------------------------------------------------------------------- /05-TypeScript/01-basicTypes/03_string.ts: -------------------------------------------------------------------------------- 1 | let firstname: string = 'Sudheer'; 2 | let lastname: number = 'Jonna'; 3 | let sentence: string = `Hello, my name is ${ firstname } ${lastname}.` 4 | -------------------------------------------------------------------------------- /05-TypeScript/01-basicTypes/04_array.ts: -------------------------------------------------------------------------------- 1 | let list1: number[] = [1, 2, 3, 4, 5]; 2 | let list2: Array = [1, 2, 3, 4, 5]; -------------------------------------------------------------------------------- /05-TypeScript/01-basicTypes/05_tuple.ts: -------------------------------------------------------------------------------- 1 | let x: [string, number]; 2 | x = ["typescript", 2]; // OK 3 | x = [2, "typescript"]; // Error 4 | 5 | console.log(typeof x[0]) //String 6 | console.log(typeof x[1]) //Number 7 | 8 | x[2]= "Welcome";//Ok 9 | x[3] = true// Error 10 | 11 | 12 | -------------------------------------------------------------------------------- /05-TypeScript/01-basicTypes/06_enum.ts: -------------------------------------------------------------------------------- 1 | enum Months{JAN, FEB, MAR}// Defaults to zero 2 | console.log(Months.MAR); //Displays 2 3 | console.log(Months[1]); //Displays FEB 4 | 5 | enum Color {Red = 2, Green = 5, Blue = 9} //Assign specific values 6 | let c: Color = Color.Green; 7 | console.log(c);// 5 -------------------------------------------------------------------------------- /05-TypeScript/01-basicTypes/07_any.ts: -------------------------------------------------------------------------------- 1 | let random: any = 4; 2 | random = "hello ts user"; 3 | random = true; 4 | random.test()// no issue 5 | 6 | let randomObj: Object = 4; 7 | randomObj.test()// fails as it don't has test method 8 | let randomArray: any[] = [1, "ts"", true]; -------------------------------------------------------------------------------- /05-TypeScript/01-basicTypes/08_void.ts: -------------------------------------------------------------------------------- 1 | function greeting(): void { 2 | alert("Hello TS user"); 3 | } 4 | 5 | let notdefined: void = undefined -------------------------------------------------------------------------------- /05-TypeScript/01-basicTypes/09_unused.ts: -------------------------------------------------------------------------------- 1 | let unused1: undefined = undefined; 2 | let unused2: null = null; -------------------------------------------------------------------------------- /05-TypeScript/01-basicTypes/10_never.ts: -------------------------------------------------------------------------------- 1 | // Function returning never must have unreachable end point 2 | function error(message: string): never { 3 | throw new Error(message); 4 | } 5 | 6 | // Inferred return type is never 7 | function fail() { 8 | return error("Something failed"); 9 | } 10 | 11 | // Function returning never must have unreachable end point 12 | function infiniteLoop(): never { 13 | while (true) { 14 | } 15 | } -------------------------------------------------------------------------------- /05-TypeScript/02-interfaces/01_firstinterface.ts: -------------------------------------------------------------------------------- 1 | interface booking { 2 | moviename: string; 3 | } 4 | 5 | function bookticket(booking: bookingObj) { 6 | console.log(bookingObj.moviename); 7 | } 8 | 9 | let bookingObj = {price: 20, moviename: "Thor"}; 10 | bookticket(bookingObj); -------------------------------------------------------------------------------- /05-TypeScript/02-interfaces/02_optionalparams.ts: -------------------------------------------------------------------------------- 1 | interface booking { 2 | moviename?: string; 3 | price?: number; 4 | } 5 | 6 | function bookticket(booking: bookingObj) : {moviename: string, price: string} { 7 | let newBooking = {moviename: "Thor", price: 10}; 8 | if (bookingObj.moviename) { 9 | newBooking.moviename = bookingObj.moviename; 10 | } 11 | if (bookingObj.price) { 12 | newBooking.price = newBooking.price + 2; // Service tax 13 | } 14 | return newBooking; 15 | } 16 | 17 | let newBooking = bookticket({moviename: "Avengers"}); -------------------------------------------------------------------------------- /05-TypeScript/02-interfaces/03_readonlyparams.ts: -------------------------------------------------------------------------------- 1 | interface Car { 2 | readonly brand: string; 3 | readonly year: number; 4 | } 5 | 6 | let car: Car = { brand: 'Audi', year: 2005 }; 7 | car.brand = 'Benz'; // error! 8 | 9 | let nums1: number[] = [1, 2, 3, 4]; 10 | let nums2: ReadonlyArray = nums1; 11 | nums2[0] = 12; // error! 12 | nums2.push(5); // error! 13 | nums2.length = 100; // error! 14 | nums1 = nums2; // error! 15 | nums1 = nums2 as number[]; -------------------------------------------------------------------------------- /05-TypeScript/03-classes/01_inheritance.ts: -------------------------------------------------------------------------------- 1 | class Vehicle { 2 | licensePlate(license: string) { 3 | console.log(`Vehicle license details are: ${license}.`); 4 | } 5 | } 6 | 7 | class Car extends Vehicle { 8 | numberOfSeats(seats: number = 0) { 9 | console.log(`No. of seats are ${seats}`); 10 | } 11 | } 12 | 13 | const car = new Car(); 14 | car.numberOfSeats(); 15 | car.licensePlate('One motoring'); 16 | car.numberOfSeats(); -------------------------------------------------------------------------------- /05-TypeScript/04-functions/01_functiontypes.ts: -------------------------------------------------------------------------------- 1 | function add(a: number, b: number): number { 2 | return a + b; 3 | } 4 | 5 | let calculate = function(a: number, b: number): number { return a + b; }; -------------------------------------------------------------------------------- /05-TypeScript/04-functions/02_inferringtypes.ts: -------------------------------------------------------------------------------- 1 | function add(a: number, b: number): number { 2 | return a + b; 3 | } 4 | 5 | let calculate = function(a: number, b: number): number { return a + b; }; -------------------------------------------------------------------------------- /05-TypeScript/04-functions/03_optionals&defaults.ts: -------------------------------------------------------------------------------- 1 | function fullName(firstName: string, lastName?: string) { 2 | return firstName + lastName 3 | } 4 | 5 | function fullName(firstName: string, lastName='jonna') { 6 | return firstName + lastName 7 | } -------------------------------------------------------------------------------- /05-TypeScript/04-functions/04_restparameters.ts: -------------------------------------------------------------------------------- 1 | function namesList(firstName: string, ...remainingNames: string[]) { 2 | return firstName + " " + remainingNames.join(" "); 3 | } -------------------------------------------------------------------------------- /05-TypeScript/05-generics/01_basic.ts: -------------------------------------------------------------------------------- 1 | function profile(age: number): number { 2 | return age; 3 | } 4 | 5 | function profile(age: any): any { 6 | return age; 7 | } 8 | 9 | 10 | function profile(age: T): T { 11 | return age; 12 | } 13 | 14 | let profile = profile(30); 15 | 16 | let profile = profile(30); // Infer -------------------------------------------------------------------------------- /05-TypeScript/06-enums/01_basic.ts: -------------------------------------------------------------------------------- 1 | enum Months { 2 | JAN, 3 | FEB, 4 | MAR, 5 | APR, 6 | } 7 | 8 | enum Months1 { 9 | JAN = 1, 10 | FEB, 11 | MAR, 12 | APR, 13 | } 14 | 15 | enum Months2 { 16 | JAN="JAN", 17 | FEB="FEB", 18 | MAR="MAR", 19 | APR="APR", 20 | } 21 | 22 | enum Heterogeneous { 23 | Yes="YES", 24 | No=0 25 | } 26 | -------------------------------------------------------------------------------- /05-TypeScript/README.md: -------------------------------------------------------------------------------- 1 | let calculate: (a: number, b: number) => number = 2 | function(x, y) { return x + y; }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # awesome-javascript-technologies 2 | Explore various JS technologies 3 | 4 | # 50 Awesome JavaScript Technologies 5 | This git repo discusses about 50 popular JS technologies,frameworks or libraries avaialble in the market. Each technology detailed with an blog entry with a detailed analysis and github examples. 6 | 7 |
8 | 9 | To encourage us and if you like the project then click start(💫) 10 |
11 | 12 | Below is the list of technologies covered in this series: 13 | 14 | 1. **[Week 1: October 22, 2017](https://github.com/sudheerj/awesome-javascript-technologies/blob/master/01-Inquirerjs)** How the user interactive session is made easy with Inquirer library using question and answer prompting mechanism. The blog details are available @ [Interactive CommandLine Interface using Inquirer](http://sudheerjonna.com/blog/2017/10/22/interactive-command-line-interface-using-inquirerjs/) 15 | 2. **[Week 2: October 30, 2017](https://github.com/sudheerj/awesome-javascript-technologies/tree/master/02-Lodash)** A low-level JavaScript utility library used for delivering consistency, customization, performance, and extra features. It improves the regular JS development using it's helper methods on various types. The blog details are available @ [Lodash: A modern JavaScript Utility library](http://sudheerjonna.com/blog/2017/10/30/lodash-a-modern-javascript-utility-library/) 16 | 3. **[Week 3: November 6, 2017](https://github.com/sudheerj/awesome-javascript-technologies/tree/master/03-Webpack)** Webpack is a modern JavaScript module bundler for JavaScript applications. The blog details are available @ [Webpack: A modern JavaScript modular](http://sudheerjonna.com/blog/2017/11/12/webpack-a-module-bundler-for-javascript-applications/) 17 | 4. **[Week 4: November 13, 2017](https://github.com/sudheerj/awesome-javascript-technologies/blob/master/04-RxJS)** Bring Reactive programming for composing asynchronous and callback functions code in Javascript world. The blog details are available @ [RxJS: Reactive Programming]() -------------------------------------------------------------------------------- /javascript-frameworks.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | --------------------------------------------------------------------------------