Skip to content

Commit c3aa335

Browse files
committed
init
0 parents  commit c3aa335

File tree

9 files changed

+357
-0
lines changed

9 files changed

+357
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
node_modules

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.vscode
2+
node_modules
3+
.DS_Store
4+
**/*.lock

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
// Use IntelliSense to learn about possible Node.js debug attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"program": "${workspaceRoot}/src/index.js"
12+
},
13+
{
14+
"type": "node",
15+
"request": "attach",
16+
"name": "Attach to Process",
17+
"address": "localhost",
18+
"port": 5858
19+
}
20+
]
21+
}

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2017 - present M Habib Rohman
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Javascript PHP Array
2+
Use php array style in javascript
3+
4+
## How to use
5+
6+
1. Install `php-array` from npm.
7+
`npm install --save php-array`
8+
2. require or import `php-array` to your code.
9+
Example:
10+
```javascript
11+
const phparray = require('php-array')
12+
13+
phparray(`
14+
[
15+
name => 'john doe',
16+
email => 'johndoe@test.com'
17+
]
18+
`) // it's return {name: 'john doe', email: 'johndoe@test.com'}
19+
```
20+
21+
## LICENSE
22+
**MIT LICENSE**

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "php-array",
3+
"version": "0.0.1",
4+
"description": "transform and convert php array style into javascript object",
5+
"main": "./src/index.js",
6+
"license": "MIT",
7+
"author": {
8+
"name": "Habib Rohman",
9+
"email": "mhrohman@live.com",
10+
"url": "https://github.com/rohmanhm"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git@github.com:rohmanhm/js-php-array"
15+
},
16+
"keywords": [
17+
"javascript",
18+
"php",
19+
"array",
20+
"php-array",
21+
"js-php-array",
22+
"convert"
23+
],
24+
"scripts": {
25+
"test": "mocha **/*.test.js"
26+
},
27+
"dependencies": {
28+
"json5": "^0.5.1"
29+
},
30+
"devDependencies": {
31+
"chai": "^3.5.0",
32+
"mocha": "^3.2.0"
33+
}
34+
}

src/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Name: php-array
3+
* Author: M Habib Rohman <mhrohman@live.com>
4+
* @2017
5+
*/
6+
7+
const JSON5 = require('json5')
8+
9+
/**
10+
* Convert php array style into javascript object
11+
*
12+
* @type {string} {value}
13+
* @return {object}
14+
*/
15+
module.exports = function (value) {
16+
const parseredValue = value
17+
.replace(/\[/g, '{')
18+
.replace(/\]/g, '}')
19+
.replace(/\=\>/g, ':')
20+
return JSON5.parse(parseredValue)
21+
}

test/index.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const phparray = require('../src')
2+
const chai = require('chai')
3+
4+
const { expect } = chai
5+
6+
describe('PHP-Array', () => {
7+
const value = `
8+
[
9+
author => '@rohmanhm',
10+
email => 'mhrohman@live.com'
11+
]
12+
`
13+
it('should exists', () => {
14+
expect(phparray).to.exist
15+
})
16+
it('should return an object', () => {
17+
expect(phparray(value)).to.be.an('object')
18+
})
19+
it('should convert php array style into an object', () => {
20+
const expectedValue = {
21+
author: '@rohmanhm',
22+
email: 'mhrohman@live.com'
23+
}
24+
expect(phparray(value)).to.deep.equal(expectedValue)
25+
})
26+
it('should return value like expected', () => {
27+
expect(phparray(value).author).to.equal('@rohmanhm')
28+
})
29+
})

yarn.lock

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
assertion-error@^1.0.1:
6+
version "1.0.2"
7+
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.0.2.tgz#13ca515d86206da0bac66e834dd397d87581094c"
8+
9+
balanced-match@^0.4.1:
10+
version "0.4.2"
11+
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838"
12+
13+
brace-expansion@^1.0.0:
14+
version "1.1.6"
15+
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.6.tgz#7197d7eaa9b87e648390ea61fc66c84427420df9"
16+
dependencies:
17+
balanced-match "^0.4.1"
18+
concat-map "0.0.1"
19+
20+
browser-stdout@1.3.0:
21+
version "1.3.0"
22+
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f"
23+
24+
chai@^3.5.0:
25+
version "3.5.0"
26+
resolved "https://registry.yarnpkg.com/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247"
27+
dependencies:
28+
assertion-error "^1.0.1"
29+
deep-eql "^0.1.3"
30+
type-detect "^1.0.0"
31+
32+
commander@2.9.0:
33+
version "2.9.0"
34+
resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4"
35+
dependencies:
36+
graceful-readlink ">= 1.0.0"
37+
38+
concat-map@0.0.1:
39+
version "0.0.1"
40+
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
41+
42+
debug@2.2.0:
43+
version "2.2.0"
44+
resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
45+
dependencies:
46+
ms "0.7.1"
47+
48+
deep-eql@^0.1.3:
49+
version "0.1.3"
50+
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2"
51+
dependencies:
52+
type-detect "0.1.1"
53+
54+
diff@1.4.0:
55+
version "1.4.0"
56+
resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf"
57+
58+
escape-string-regexp@1.0.5:
59+
version "1.0.5"
60+
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
61+
62+
fs.realpath@^1.0.0:
63+
version "1.0.0"
64+
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
65+
66+
glob@7.0.5:
67+
version "7.0.5"
68+
resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95"
69+
dependencies:
70+
fs.realpath "^1.0.0"
71+
inflight "^1.0.4"
72+
inherits "2"
73+
minimatch "^3.0.2"
74+
once "^1.3.0"
75+
path-is-absolute "^1.0.0"
76+
77+
"graceful-readlink@>= 1.0.0":
78+
version "1.0.1"
79+
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
80+
81+
growl@1.9.2:
82+
version "1.9.2"
83+
resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f"
84+
85+
has-flag@^1.0.0:
86+
version "1.0.0"
87+
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"
88+
89+
inflight@^1.0.4:
90+
version "1.0.6"
91+
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
92+
dependencies:
93+
once "^1.3.0"
94+
wrappy "1"
95+
96+
inherits@2:
97+
version "2.0.3"
98+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
99+
100+
json3@3.3.2:
101+
version "3.3.2"
102+
resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1"
103+
104+
json5@^0.5.1:
105+
version "0.5.1"
106+
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
107+
108+
lodash._baseassign@^3.0.0:
109+
version "3.2.0"
110+
resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e"
111+
dependencies:
112+
lodash._basecopy "^3.0.0"
113+
lodash.keys "^3.0.0"
114+
115+
lodash._basecopy@^3.0.0:
116+
version "3.0.1"
117+
resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36"
118+
119+
lodash._basecreate@^3.0.0:
120+
version "3.0.3"
121+
resolved "https://registry.yarnpkg.com/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz#1bc661614daa7fc311b7d03bf16806a0213cf821"
122+
123+
lodash._getnative@^3.0.0:
124+
version "3.9.1"
125+
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
126+
127+
lodash._isiterateecall@^3.0.0:
128+
version "3.0.9"
129+
resolved "https://registry.yarnpkg.com/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz#5203ad7ba425fae842460e696db9cf3e6aac057c"
130+
131+
lodash.create@3.1.1:
132+
version "3.1.1"
133+
resolved "https://registry.yarnpkg.com/lodash.create/-/lodash.create-3.1.1.tgz#d7f2849f0dbda7e04682bb8cd72ab022461debe7"
134+
dependencies:
135+
lodash._baseassign "^3.0.0"
136+
lodash._basecreate "^3.0.0"
137+
lodash._isiterateecall "^3.0.0"
138+
139+
lodash.isarguments@^3.0.0:
140+
version "3.1.0"
141+
resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a"
142+
143+
lodash.isarray@^3.0.0:
144+
version "3.0.4"
145+
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55"
146+
147+
lodash.keys@^3.0.0:
148+
version "3.1.2"
149+
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a"
150+
dependencies:
151+
lodash._getnative "^3.0.0"
152+
lodash.isarguments "^3.0.0"
153+
lodash.isarray "^3.0.0"
154+
155+
minimatch@^3.0.2:
156+
version "3.0.3"
157+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774"
158+
dependencies:
159+
brace-expansion "^1.0.0"
160+
161+
minimist@0.0.8:
162+
version "0.0.8"
163+
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
164+
165+
mkdirp@0.5.1:
166+
version "0.5.1"
167+
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
168+
dependencies:
169+
minimist "0.0.8"
170+
171+
mocha@^3.2.0:
172+
version "3.2.0"
173+
resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.2.0.tgz#7dc4f45e5088075171a68896814e6ae9eb7a85e3"
174+
dependencies:
175+
browser-stdout "1.3.0"
176+
commander "2.9.0"
177+
debug "2.2.0"
178+
diff "1.4.0"
179+
escape-string-regexp "1.0.5"
180+
glob "7.0.5"
181+
growl "1.9.2"
182+
json3 "3.3.2"
183+
lodash.create "3.1.1"
184+
mkdirp "0.5.1"
185+
supports-color "3.1.2"
186+
187+
ms@0.7.1:
188+
version "0.7.1"
189+
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"
190+
191+
once@^1.3.0:
192+
version "1.4.0"
193+
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
194+
dependencies:
195+
wrappy "1"
196+
197+
path-is-absolute@^1.0.0:
198+
version "1.0.1"
199+
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
200+
201+
supports-color@3.1.2:
202+
version "3.1.2"
203+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.1.2.tgz#72a262894d9d408b956ca05ff37b2ed8a6e2a2d5"
204+
dependencies:
205+
has-flag "^1.0.0"
206+
207+
type-detect@0.1.1:
208+
version "0.1.1"
209+
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822"
210+
211+
type-detect@^1.0.0:
212+
version "1.0.0"
213+
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2"
214+
215+
wrappy@1:
216+
version "1.0.2"
217+
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"

0 commit comments

Comments
 (0)