Skip to content

Commit

Permalink
Change react-native to universal, replace assert, update babel config
Browse files Browse the repository at this point in the history
  • Loading branch information
neiker committed Nov 19, 2016
1 parent 2f09ed1 commit ebca317
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 228 deletions.
8 changes: 6 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"presets": ["react-native"],
"plugins": ["inline-package-json"],
"presets": ["es2015"],
"plugins": [
"inline-package-json",
"transform-class-properties",
"transform-object-rest-spread"
],
"env": {
"test": {
"plugins": [
Expand Down
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ engines:
- javascript
eslint:
enabled: true
channel: "eslint-2"
channel: "eslint-3"

ratings:
paths:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

![dependencies](https://david-dm.org/neiker/analytics-react-native.svg)

A React Native client for [Segment](https://segment.com). The hassle-free way to integrate analytics into any application.
A universal javascript client for [Segment](https://segment.com).

This library is based on its node counterpart, [analytics-node](https://github.com/segmentio/analytics-node). Despite being designed to run on react-native, it will also work in browsers (via webpack or browserify) and even in nodejs. You only need to include [fetch](https://github.com/github/fetch) for browsers or [node-fetch](https://github.com/bitinn/node-fetch) for nodejs or io.js.
This library is based on [analytics-node](https://github.com/segmentio/analytics-node) and have the same API, but is re writed to also work in browsers (via webpack or browserify) server side, React Native and NativeScript. You only need to include [fetch](https://github.com/github/fetch) for browsers (check [here](http://caniuse.com/#feat=fetch) if you really need it) or [node-fetch](https://github.com/bitinn/node-fetch) for nodejs or io.js.

## Installation

```bash
npm install analytics-react-native
npm install analytics-universal babel config
```

## Usage
Expand Down
5 changes: 4 additions & 1 deletion mocha_setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
/*
eslint
import/no-extraneous-dependencies: ["error", {"devDependencies": true}]
*/

require('babel-polyfill');
global.fetch = require('node-fetch');
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "analytics-react-native",
"version": "1.0.1",
"description": "A React Native client for [Segment](https://segment.com) — The hassle-free way to integrate analytics into any application.",
"name": "analytics-universal",
"version": "1.1.0",
"description": "An universal client for [Segment](https://segment.com). Works in browsers, React Native, NativeScript or nodejs",
"keywords": [
"analytics",
"segment.io",
"segmentio",
"client",
"driver",
"react-native"
"react-native",
"node"
],
"main": "lib/index.js",
"scripts": {
Expand All @@ -23,16 +24,15 @@
},
"repository": {
"type": "git",
"url": "https://github.com/neiker/analytics-react-native.git"
"url": "https://github.com/neiker/analytics-universal.git"
},
"author": "Javier Alvarez <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/neiker/analytics-react-native",
"homepage": "https://github.com/neiker/analytics-universal",
"bugs": {
"url": "https://github.com/neiker/analytics-react-native/issues"
"url": "https://github.com/neiker/analytics-universal/issues"
},
"dependencies": {
"assert": "1.4.1",
"base-64": "0.1.0",
"type-of": "2.0.1"
},
Expand All @@ -41,8 +41,10 @@
"babel-eslint": "7.1.1",
"babel-plugin-inline-package-json": "2.0.0",
"babel-plugin-istanbul": "3.0.0",
"babel-plugin-transform-class-properties": "6.19.0",
"babel-plugin-transform-object-rest-spread": "6.19.0",
"babel-polyfill": "6.16.0",
"babel-preset-react-native": "1.9.0",
"babel-preset-es2015": "6.18.0",
"babel-register": "6.18.0",
"body-parser": "1.15.2",
"codecov": "1.0.1",
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/assert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function assert(condition, message) {
if (!condition) {
throw new Error(message);
}
}
2 changes: 1 addition & 1 deletion src/helpers/validate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import typeOf from 'type-of';
import assert from './assert';

/**
* Validation rules.
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from 'assert';
import base64 from 'base-64';

import validate from './helpers/validate';
import fetchRetry from './helpers/fetch-retry';
import assert from './helpers/assert';
import uid from './helpers/uid';
import parseResponse from './helpers/parse-response';

Expand Down Expand Up @@ -233,7 +233,7 @@ export default class Analytics {
message.type = messageType;
message.context = message.context ? { ...message.context } : {};
message.context.library = {
name: 'analytics-react-native',
name: 'analytics-universal',
version: VERSION,
};

Expand All @@ -242,7 +242,7 @@ export default class Analytics {
}

if (!message.messageId) {
message.messageId = `react-native-${uid(32)}`;
message.messageId = `universal-${uid(32)}`;
}

this.queue.push({
Expand Down
6 changes: 3 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const noop = function noop() {};
const id = 'id';
const context = {
library: {
name: 'analytics-react-native',
name: 'analytics-universal',
version,
},
};
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('Analytics', () => {
analytics.enqueue('type', { event: 'test', context: { name: 'travis' } }, noop);
assert.deepEqual(analytics.queue[0].message.context, {
library: {
name: 'analytics-react-native',
name: 'analytics-universal',
version,
},
name: 'travis',
Expand All @@ -154,7 +154,7 @@ describe('Analytics', () => {

const msg = analytics.queue[0].message;
assert(msg.messageId);
assert(/react-native-[a-zA-Z0-9]{32}/.test(msg.messageId));
assert(/universal-[a-zA-Z0-9]{32}/.test(msg.messageId));
});

it('shouldn\'t change the message id', () => {
Expand Down
Loading

0 comments on commit ebca317

Please sign in to comment.