fluentnode
Fluent apis for node (based on the concepts used in C#'s FluentSharp
Last updated 3 years ago by diniscruz .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fluentnode 
SYNC missed versions from official npm registry.

FluentNode    

NPM version NPM downloads MIT License Build Status Coverage Status

NPM

NPM

FluentNode is a set of Node.js Javascript APIs that support functional programming:

  • designed to extent core Javascript/Node objects,
  • represents a continuous effort of simplifying complex actions, in order to allow the easy development and testing of readable code
  • written in Literate Coffee-Script (using TDD)
  • 100% code coverage (on both code and tests)
  • based on fluent APIs
  • an Javascript implementation of FluentSharp (part of OWASP O2 Platform)

@Fogus Functional Javascript book contains a description which completely matches the philosophy behind FluentNode.

In page 25, Functional programming is defined as consisting of the following techniques:

  • Identifying an abstraction and building a function for it
  • Using existing functions to build more complex abstractions
  • Passing existing functions to other functions to build even more complex abstractions

Install on Node.js

npm install fluentnode --save

Documentation and FluentNode APIs

The code is written in literate coffee-script where the documentation is part of the sourcecode.

See http://o2platform.com/fluentnode for the list of available functions, annotated source code, and all tests (site created using docco)

if you are viewing this in GitHub, the individual source code files (linked below) look quite nice (due to GH's support for literate Coffee-Script):

Examples

To show FluentNode in action, here are some examples taken from FluentNode's UnitTests

String::folder_Create and String::folder_Delete (in fs.test.coffee)

  it 'folder_Create and folder_Delete' , ->               # tests the String's folder_Create and folder_Delete methods
    "".folder_Create.assert_Is_Function()                 # checks if String::folder_Create exists
    "".folder_Delete.assert_Is_Function()                 # checks if String::folder_Delete exists
    tmpDir = "./".temp_Name_In_Folder()                   # get a temp folder name in the folder provided as string
    tmpDir.folder_Exists().assert_Is_False()              # checks if the folder exists (expects it to be false)
    tmpDir.folder_Create().assert_Is tmpDir.realPath()    # creates folder and confirms that the return value is the full path to the folder
    tmpDir.folder_Exists().assert_Is_True()               # confirms that folders exists
    tmpDir.folder_Delete().assert_Is_True()               # deletes folder (confirming OK result from delete action)
    tmpDir.folder_Exists().assert_Is_False()              # confirms that doesn't exists

There are actually two asserts that can be used to simply this code:

    tmpDir.assert_Folder_Not_Exists()                     # asserts that folder doesn't exist
          .folder_Create().assert_Is tmpDir.realPath()    # creates folder and confirms that the return value is the full path to the folder
    tmpDir.assert_Folder_Exists()                         # assert that folders exists
          .folder_Delete().assert_Is_True()               # deletes folder (confirming OK result from delete action)

String::file_Contents (in fs.test.coffee)

  it 'file_Contents' , ->
    ''.file_Contents.assert_Is_Function()
    file_Name     = '_temp_name_'.add_Random_String(5)
    file_Contents = 'value_'.add_Random_String(5)
    (file_Name.file_Exists().assert_Is_False())
    file_Contents.saveAs(file_Name)
    file_Name.file_Exists().assert_Is_True()
    file_Name.file_Contents().assert_Is(file_Contents)
    file_Name.file_Delete().assert_Is_True()

String::files (in fs.test.coffee)

  it 'files' , ->
    ''.files.assert_Is_Function()
    files = './'.files().filter (file) -> file isnt '.DS_Store'.realPath()
    expectedFiles = (file.realPath() for file in '.gitignore,.travis.yml,LICENSE,README.md,package.json'.split(','))
    files.assert_Contains(expectedFiles)
    './'.files('.yml' ).assert_Is(['.travis.yml'.realPath()])
    './'.files('.json').assert_Is(['package.json'.realPath()])

String::http_Status (in http.test.coffee)

  it 'http_Status', (done)->
    ''.http_Status.assert_Is_Function()
    url.http_Status (status)->
      status.assert_Is(200)
      done()

String::http_Get (in http.test.coffee)

  it 'http_GET' , (done)->
    ''.http_Status.assert_Is_Function()
    req = url.http_GET (err, data, res)->
      assert_Is_Null(err)
      data.assert_Is_String()
      req.assert_Instance_Of(http.ClientRequest)
      res.assert_Instance_Of(http.IncomingMessage)
      data.assert_Is(test_Data)
      done()

String::start_Process_Redirect_Console (in process.test.coffee)

  it 'start_Process_Redirect_Console', (done)->
    original_log = console.log
    log_Messages = []
    console.log  = (logMsg)-> log_Messages.push(logMsg)

    childProcess = 'ls'.start_Process_Redirect_Console('.')
    childProcess.on 'exit', ->
      console.log 'process ended'
      log_Messages.first() .assert_Contains('README.md')
      log_Messages.second().assert_Is('process ended')
      console.log = original_log
      done()

##Contribute See the current Issues list for a good place to start

If you need a function that is currently missing, please fork this repo and send a PR with the implementation and tests :)

##Projects using FluentNode

Current Tags

  • 0.7.1                                ...           latest (3 years ago)

45 Versions

  • 0.7.1                                ...           3 years ago
  • 0.7.0                                ...           3 years ago
  • 0.6.5                                ...           3 years ago
  • 0.6.4                                ...           4 years ago
  • 0.6.3                                ...           4 years ago
  • 0.6.2                                ...           4 years ago
  • 0.6.1                                ...           4 years ago
  • 0.6.0                                ...           4 years ago
  • 0.5.5                                ...           4 years ago
  • 0.5.4                                ...           4 years ago
  • 0.5.3                                ...           5 years ago
  • 0.5.2                                ...           5 years ago
  • 0.5.1                                ...           5 years ago
  • 0.5.0                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
  • 0.3.9                                ...           5 years ago
  • 0.3.8                                ...           5 years ago
  • 0.3.7                                ...           5 years ago
  • 0.3.6                                ...           5 years ago
  • 0.3.5                                ...           5 years ago
  • 0.3.4                                ...           5 years ago
  • 0.3.3                                ...           5 years ago
  • 0.3.2                                ...           5 years ago
  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.9                                ...           5 years ago
  • 0.2.8                                ...           5 years ago
  • 0.2.7                                ...           5 years ago
  • 0.2.6                                ...           5 years ago
  • 0.2.5                                ...           5 years ago
  • 0.2.4                                ...           5 years ago
  • 0.2.3                                ...           5 years ago
  • 0.2.2                                ...           6 years ago
  • 0.2.1                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.9                                ...           6 years ago
  • 0.1.8                                ...           6 years ago
  • 0.1.7                                ...           6 years ago
  • 0.1.6                                ...           6 years ago
  • 0.1.5                                ...           6 years ago
  • 0.1.4                                ...           6 years ago
  • 0.1.3                                ...           6 years ago
  • 0.1.2                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 91
Dependencies (1)
Dev Dependencies (3)

Copyright 2014 - 2016 © taobao.org |