Skip to content

Commit

Permalink
Add FP examples
Browse files Browse the repository at this point in the history
  • Loading branch information
leshakoss committed Feb 17, 2017
1 parent 73ec843 commit 0f5d9a7
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/browserify/README.md
@@ -1,6 +1,6 @@
# Usage With Browserify

See [example.js](./example.js) and [misc.js](./misc.js) for source code examples.
See [example.js](./example.js), [fp.js](./fp.js) and [misc.js](./misc.js) for source code examples.

See [package.json scripts](./package.json) for CLI usage.

Expand Down
19 changes: 19 additions & 0 deletions examples/browserify/fp.js
@@ -0,0 +1,19 @@
var addYears = require('date-fns/fp/addYears')
var dateFns = require('date-fns/fp')
var formatWithOptions = dateFns.formatWithOptions
var eoLocale = require('date-fns/locale/eo')

var addFiveYears = addYears(5)
var dateToString = formatWithOptions({locale: eoLocale}, 'D MMMM YYYY')

var dates = [
new Date(2017, 0 /* Jan */, 1),
new Date(2017, 1 /* Feb */, 11),
new Date(2017, 6 /* Jul */, 2)
]

var formattedDates = dates
.map((date) => dateToString(addFiveYears(date)))
.join(', ')

console.log(formattedDates === '1 januaro 2022, 11 februaro 2022, 2 julio 2022')
9 changes: 6 additions & 3 deletions examples/browserify/package.json
Expand Up @@ -14,15 +14,18 @@
"scripts": {
"build": "yarn run build-date-fns && yarn run build-browserify && yarn run build-babili",
"build-date-fns": "env PACKAGE_OUTPUT_PATH=\"$(pwd)/node_modules/date-fns\" ../../scripts/build_package.sh",
"build-browserify": "yarn run build-browserify-example && yarn run build-browserify-misc",
"build-browserify": "yarn run build-browserify-example && yarn run build-browserify-fp && yarn run build-browserify-misc",
"build-browserify-example": "mkdir -p dist && browserify example.js -o dist/example.js",
"build-browserify-fp": "mkdir -p dist && browserify fp.js -o dist/fp.js",
"build-browserify-misc": "mkdir -p dist && browserify misc.js -o dist/misc.js",
"build-babili": "yarn run build-babili-example && yarn run build-babili-misc && yarn run stats-size",
"build-babili": "yarn run build-babili-example && yarn run build-babili-fp && yarn run build-babili-misc && yarn run stats-size",
"build-babili-example": "babili dist/example.js --out-file dist/example.min.js --minified --no-comments",
"build-babili-fp": "babili dist/fp.js --out-file dist/fp.min.js --minified --no-comments",
"build-babili-misc": "babili dist/misc.js --out-file dist/misc.min.js --minified --no-comments",
"stats-size": "gzip-size dist/example.min.js | pretty-bytes",
"test": "yarn run test-example && yarn run test-misc",
"test": "yarn run test-example && yarn run test-fp && yarn run test-misc",
"test-example": "test $(env TZ=UTC node ./dist/example.min.js) = true",
"test-fp": "test $(env TZ=UTC node ./dist/fp.min.js) = true",
"test-misc": "test $(env TZ=UTC node ./dist/misc.min.js) = true"
}
}
2 changes: 1 addition & 1 deletion examples/flow/README.md
@@ -1,6 +1,6 @@
# Usage With webpack 1.x

See [example.js.flow](./example.js.flow) and [misc.js.flow](./misc.js.flow) for source code examples.
See [example.js.flow](./example.js.flow), [fp.js.flow](./fp.js.flow) and [misc.js.flow](./misc.js.flow) for source code examples.

See [package.json scripts](./package.json) for CLI usage.

Expand Down
19 changes: 19 additions & 0 deletions examples/flow/fp.js.flow
@@ -0,0 +1,19 @@
var addYears = require('date-fns/fp/addYears')
var dateFns = require('date-fns/fp')
var formatWithOptions = dateFns.formatWithOptions
var eoLocale = require('date-fns/locale/eo')

const addFiveYears = addYears(5)
const dateToString = formatWithOptions({locale: eoLocale}, 'D MMMM YYYY')

const dates : Date[] = [
new Date(2017, 0 /* Jan */, 1),
new Date(2017, 1 /* Feb */, 11),
new Date(2017, 6 /* Jul */, 2)
]

const formattedDates : string = dates
.map((date) => dateToString(addFiveYears(date)))
.join(', ')

console.log(formattedDates === '1 januaro 2022, 11 februaro 2022, 2 julio 2022')
6 changes: 4 additions & 2 deletions examples/flow/package.json
Expand Up @@ -14,11 +14,13 @@
"build": "yarn run build-date-fns && yarn run flow-check && yarn run build-babel",
"flow-check": "flow check",
"build-date-fns": "env PACKAGE_OUTPUT_PATH=\"$(pwd)/node_modules/date-fns\" ../../scripts/build_package.sh",
"build-babel": "yarn run build-babel-example && yarn run build-babel-misc",
"build-babel": "yarn run build-babel-example && yarn run build-babel-fp && yarn run build-babel-misc",
"build-babel-example": "mkdir -p dist && babel example.js.flow --out-file dist/example.js",
"build-babel-fp": "mkdir -p dist && babel fp.js.flow --out-file dist/fp.js",
"build-babel-misc": "mkdir -p dist && babel misc.js.flow --out-file dist/misc.js",
"test": "yarn run test-example && yarn run test-misc",
"test": "yarn run test-example && yarn run test-fp && yarn run test-misc",
"test-example": "test $(env TZ=UTC node ./dist/example.js) = true",
"test-fp": "test $(env TZ=UTC node ./dist/fp.js) = true",
"test-misc": "test $(env TZ=UTC node ./dist/misc.js) = true"
}
}
2 changes: 1 addition & 1 deletion examples/rollup/README.md
@@ -1,6 +1,6 @@
# Usage With Rollup

See [example.js](./example.js) and [misc.js](./misc.js) for source code examples.
See [example.js](./example.js), [fp.js](./fp.js) and [misc.js](./misc.js) for source code examples.

See [package.json scripts](./package.json) for CLI usage.

Expand Down
18 changes: 18 additions & 0 deletions examples/rollup/fp.js
@@ -0,0 +1,18 @@
import addYears from 'date-fns/esm/fp/addYears'
import {formatWithOptions} from 'date-fns/esm/fp'
import eoLocale from 'date-fns/esm/locale/eo'

const addFiveYears = addYears(5)
const dateToString = formatWithOptions({locale: eoLocale}, 'D MMMM YYYY')

const dates = [
new Date(2017, 0 /* Jan */, 1),
new Date(2017, 1 /* Feb */, 11),
new Date(2017, 6 /* Jul */, 2)
]

const formattedDates = dates
.map((date) => dateToString(addFiveYears(date)))
.join(', ')

console.log(formattedDates === '1 januaro 2022, 11 februaro 2022, 2 julio 2022')
9 changes: 6 additions & 3 deletions examples/rollup/package.json
Expand Up @@ -16,15 +16,18 @@
"scripts": {
"build": "yarn run build-date-fns && yarn run build-rollup && yarn run build-babili",
"build-date-fns": "env PACKAGE_OUTPUT_PATH=\"$(pwd)/node_modules/date-fns\" ../../scripts/build_package.sh",
"build-rollup": "yarn run build-rollup-example && yarn run build-rollup-misc",
"build-rollup": "yarn run build-rollup-example && yarn run build-rollup-fp && yarn run build-rollup-misc",
"build-rollup-example": "rollup -c rollup.config.example.js",
"build-rollup-fp": "rollup -c rollup.config.fp.js",
"build-rollup-misc": "rollup -c rollup.config.misc.js",
"build-babili": "yarn run build-babili-example && yarn run build-babili-misc && yarn run stats-size",
"build-babili": "yarn run build-babili-example && yarn run build-babili-fp && yarn run build-babili-misc && yarn run stats-size",
"build-babili-example": "babili dist/example.js --out-file dist/example.min.js --minified --no-comments",
"build-babili-fp": "babili dist/fp.js --out-file dist/fp.min.js --minified --no-comments",
"build-babili-misc": "babili dist/misc.js --out-file dist/misc.min.js --minified --no-comments",
"stats-size": "gzip-size dist/example.min.js | pretty-bytes",
"test": "yarn run test-example && yarn run test-misc",
"test": "yarn run test-example && yarn run test-fp && yarn run test-misc",
"test-example": "test $(env TZ=UTC node ./dist/example.min.js) = true",
"test-fp": "test $(env TZ=UTC node ./dist/fp.min.js) = true",
"test-misc": "test $(env TZ=UTC node ./dist/misc.min.js) = true"
}
}
12 changes: 12 additions & 0 deletions examples/rollup/rollup.config.fp.js
@@ -0,0 +1,12 @@
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'

export default {
entry: 'fp.js',
dest: 'dist/fp.js',
format: 'cjs',
plugins: [
resolve({jsnext: true, main: true}),
commonjs()
]
}
2 changes: 1 addition & 1 deletion examples/typescript/README.md
@@ -1,6 +1,6 @@
# Usage With webpack 1.x

See [example.ts](./example.ts) and [misc.ts](./misc.ts) for source code examples.
See [example.ts](./example.ts), [fp.ts](./fp.ts) and [misc.ts](./misc.ts) for source code examples.

See [package.json scripts](./package.json) for CLI usage

Expand Down
18 changes: 18 additions & 0 deletions examples/typescript/fp.ts
@@ -0,0 +1,18 @@
import addYears from 'date-fns/esm/fp/addYears'
import {formatWithOptions} from 'date-fns/esm/fp'
import eoLocale from 'date-fns/esm/locale/eo'

const addFiveYears = addYears(5)
const dateToString = formatWithOptions({locale: eoLocale}, 'D MMMM YYYY')

const dates = [
new Date(2017, 0 /* Jan */, 1),
new Date(2017, 1 /* Feb */, 11),
new Date(2017, 6 /* Jul */, 2)
]

const formattedDates = dates
.map((date) => dateToString(addFiveYears(date)))
.join(', ')

console.log(formattedDates === '1 januaro 2022, 11 februaro 2022, 2 julio 2022')
7 changes: 4 additions & 3 deletions examples/typescript/package.json
Expand Up @@ -12,10 +12,11 @@
"scripts": {
"build": "yarn run build-date-fns && yarn run build-typescript && yarn run build-webpack",
"build-date-fns": "env PACKAGE_OUTPUT_PATH=\"$(pwd)/node_modules/date-fns\" ../../scripts/build_package.sh",
"build-typescript": "tsc --outDir dist example.ts misc.ts",
"build-webpack": "webpack example=./dist/example.js misc=./dist/misc.js --output-path dist --output-filename [name].bundle.js",
"test": "yarn run test-example && yarn run test-misc",
"build-typescript": "tsc --outDir dist example.ts fp.ts misc.ts",
"build-webpack": "webpack example=./dist/example.js fp=./dist/fp misc=./dist/misc.js --output-path dist --output-filename [name].bundle.js",
"test": "yarn run test-example && yarn run test-fp && yarn run test-misc",
"test-example": "test $(env TZ=UTC node ./dist/example.bundle.js) = true",
"test-fp": "test $(env TZ=UTC node ./dist/fp.bundle.js) = true",
"test-misc": "test $(env TZ=UTC node ./dist/misc.bundle.js) = true"
}
}
2 changes: 1 addition & 1 deletion examples/webpack-1.x/README.md
@@ -1,6 +1,6 @@
# Usage With webpack 1.x

See [example.js](./example.js) and [misc.js](./misc.js) for source code examples.
See [example.js](./example.js), [fp.js](./fp.js) and [misc.js](./misc.js) for source code examples.

See [package.json scripts](./package.json) for CLI usage.

Expand Down
19 changes: 19 additions & 0 deletions examples/webpack-1.x/fp.js
@@ -0,0 +1,19 @@
var addYears = require('date-fns/fp/addYears')
var dateFns = require('date-fns/fp')
var formatWithOptions = dateFns.formatWithOptions
var eoLocale = require('date-fns/locale/eo')

var addFiveYears = addYears(5)
var dateToString = formatWithOptions({locale: eoLocale}, 'D MMMM YYYY')

var dates = [
new Date(2017, 0 /* Jan */, 1),
new Date(2017, 1 /* Feb */, 11),
new Date(2017, 6 /* Jul */, 2)
]

var formattedDates = dates
.map((date) => dateToString(addFiveYears(date)))
.join(', ')

console.log(formattedDates === '1 januaro 2022, 11 februaro 2022, 2 julio 2022')
8 changes: 5 additions & 3 deletions examples/webpack-1.x/package.json
Expand Up @@ -14,13 +14,15 @@
"scripts": {
"build": "yarn run build-date-fns && yarn run build-webpack && yarn run build-babili",
"build-date-fns": "env PACKAGE_OUTPUT_PATH=\"$(pwd)/node_modules/date-fns\" ../../scripts/build_package.sh",
"build-webpack": "webpack example=./example.js misc=./misc.js --output-path dist --output-file [name].js",
"build-babili": "yarn run build-babili-example && yarn run build-babili-misc && yarn run stats-size",
"build-webpack": "webpack example=./example.js fp=./fp.js misc=./misc.js --output-path dist --output-file [name].js",
"build-babili": "yarn run build-babili-example && yarn run build-babili-fp && yarn run build-babili-misc && yarn run stats-size",
"build-babili-example": "babili dist/example.js --out-file dist/example.min.js --minified --no-comments",
"build-babili-fp": "babili dist/fp.js --out-file dist/fp.min.js --minified --no-comments",
"build-babili-misc": "babili dist/misc.js --out-file dist/misc.min.js --minified --no-comments",
"stats-size": "gzip-size dist/example.min.js | pretty-bytes",
"test": "yarn run test-example && yarn run test-misc",
"test": "yarn run test-example && yarn run test-fp && yarn run test-misc",
"test-example": "test $(env TZ=UTC node ./dist/example.min.js) = true",
"test-fp": "test $(env TZ=UTC node ./dist/fp.min.js) = true",
"test-misc": "test $(env TZ=UTC node ./dist/misc.min.js) = true"
}
}
2 changes: 1 addition & 1 deletion examples/webpack-2.x/README.md
Expand Up @@ -3,7 +3,7 @@
**Important**: as at webpack 2.2.0, tree-shaking is not removing all unused imports.
See [webpack issue #2867](https://github.com/webpack/webpack/issues/2867)

See [example.js](./example.js) and [misc.js](./misc.js) for source code examples.
See [example.js](./example.js), [fp.js](./fp.js) and [misc.js](./misc.js) for source code examples.

See [package.json scripts](./package.json) for CLI usage.

Expand Down
18 changes: 18 additions & 0 deletions examples/webpack-2.x/fp.js
@@ -0,0 +1,18 @@
import addYears from 'date-fns/esm/fp/addYears'
import {formatWithOptions} from 'date-fns/esm/fp'
import eoLocale from 'date-fns/esm/locale/eo'

const addFiveYears = addYears(5)
const dateToString = formatWithOptions({locale: eoLocale}, 'D MMMM YYYY')

const dates = [
new Date(2017, 0 /* Jan */, 1),
new Date(2017, 1 /* Feb */, 11),
new Date(2017, 6 /* Jul */, 2)
]

const formattedDates = dates
.map((date) => dateToString(addFiveYears(date)))
.join(', ')

console.log(formattedDates === '1 januaro 2022, 11 februaro 2022, 2 julio 2022')
8 changes: 5 additions & 3 deletions examples/webpack-2.x/package.json
Expand Up @@ -14,13 +14,15 @@
"scripts": {
"build": "yarn run build-date-fns && yarn run build-webpack && yarn run build-babili",
"build-date-fns": "env PACKAGE_OUTPUT_PATH=\"$(pwd)/node_modules/date-fns\" ../../scripts/build_package.sh",
"build-webpack": "webpack example=./example.js misc=./misc.js --output-path dist --output-filename [name].js",
"build-babili": "yarn run build-babili-example && yarn run build-babili-misc && yarn run stats-size",
"build-webpack": "webpack example=./example.js fp=./fp.js misc=./misc.js --output-path dist --output-filename [name].js",
"build-babili": "yarn run build-babili-example && yarn run build-babili-fp && yarn run build-babili-misc && yarn run stats-size",
"build-babili-example": "babili dist/example.js --out-file dist/example.min.js --minified --no-comments",
"build-babili-fp": "babili dist/fp.js --out-file dist/fp.min.js --minified --no-comments",
"build-babili-misc": "babili dist/misc.js --out-file dist/misc.min.js --minified --no-comments",
"stats-size": "gzip-size dist/example.min.js | pretty-bytes",
"test": "yarn run test-example && yarn run test-misc",
"test": "yarn run test-example && yarn run test-fp && yarn run test-misc",
"test-example": "test $(env TZ=UTC node ./dist/example.min.js) = true",
"test-fp": "test $(env TZ=UTC node ./dist/fp.min.js) = true",
"test-misc": "test $(env TZ=UTC node ./dist/misc.min.js) = true"
}
}

0 comments on commit 0f5d9a7

Please sign in to comment.